JW Jevaveh
JW Jevaveh

Reputation: 91

React-native-fbsdk ShareDialog. How to share with prefilled message and photos content together?

I have react-native 0.44.0 and react-native-fbsdk 0.5.0. ShareDialog component work fine, but due to lack of docs explanation had been totally stuck. I have app with own API. I make API call fetch sharing template with photos array.

.then((responseData) => {
console.log("Facebook Share Api Test")
console.log(responseData)
// After receiving result checking Platform
// If this is iOS we should let our result image links be fetched to encode it in Base64.
if(Platform.OS !== 'android'){
  console.log("Not Andro!d!")
  let imgUrl
  let sharePhotoContent

  let iteratePhotos = function (data) {
    var photoInfo = [];
    var ready = Promise.resolve(null)
    data.forEach(function (value, i) {
      let iconURL = API.SERVER_URL + API.SERVICE_PORT + API.HEAD_ICON_RES_URL + value.photo_id + 'S'
      ready = ready.then(function () {
        return RNFetchBlob
        .fetch('GET', iconURL)
        .then(res => res.data)
        .then(resData => {
            imgUrl = 'data:image/jpeg;base64,' + resData
            console.log(imgUrl) 
            return imgUrl
        })
        .then(img => {
          console.log(img) 
          let res = {
            imageUrl: img,
            userGenerated: true,
            caption: value.comment
          } 
          return res
        })
        .catch(err => {
          console.log(err)
        })
      }).then(function (resData) {
        photoInfo[i] = resData;
      });
    });

    return ready.then(function () { return photoInfo; });
  }

  iteratePhotos(responseData.photos).then((res) => {
    console.log('res', res)
    if(res.length > 0){
      sharePhotoContent = {
        contentType: 'photo',
        contentDescription: 'Wow, check out this great site!',
        photos: res
      }
    } else {
      sharePhotoContent = {
        contentType: 'link',
        contentUrl: 'some url',
        message: responseData.message
      }
    }
    ShareDialog.canShow(sharePhotoContent)
    .then((canShow) => {
      if (canShow) {
        return ShareDialog.show(sharePhotoContent);
      }
    })
    .then((result) => {
      this.setState({isshowIndicator: false})
      if(!result.isCancelled){
        this.setState({isFacebookShared: true})
        setTimeout(() => alert("Success!"), 100)
      }
    })
    .catch(error => {
      this.setState({isshowIndicator: false})
      console.log(error)
      setTimeout(() => alert('Share fail with error: ' + error), 100)
      }
    )
  })
} else {
  let photoInfo = responseData.photos.map(value => {
    return {
      imageUrl: API.SERVER_URL + API.SERVICE_PORT + API.HEAD_ICON_RES_URL + value.photo_id + 'S',
      ...value 
    }
  })
  console.log(photoInfo, "It IS ANDROID")
  if(responseData.photos.length > 0){
    var sharePhotoContent = {
      contentType: 'photo',
      photos: photoInfo
    }
  } else {
    var sharePhotoContent = {
      contentType: 'link',
      contentUrl: 'some url',
      message: responseData.message
    }
  }
  ShareDialog.canShow(sharePhotoContent)
  .then((canShow) => {
    if (canShow) {
      return ShareDialog.show(sharePhotoContent);
    }
  })
  .then((result) => {
    this.setState({isshowIndicator: false})
    if(!result.isCancelled){
      this.setState({isFacebookShared: true})
      setTimeout(() => alert("Success!"), 100)
    }
  })
  .catch(error => {
    this.setState({isshowIndicator: false})
    setTimeout(() => alert('Share fail with error: ' + error), 100)
  })
}
})

When I tap share, sharedialog opens and photos that I want are pasted but message line waits to be filled But I need into ShareDialog opened:

Photos needed to be attached; Message to be prefilled according that one I received from my API. Is this possible? Please help this is prerelease feature needed to be implemented very fast and I havent any idea how((

Attaching screenshots that describes 1. what is going now here? 2. What i want to do.

Now opened ShareDialog looks like this

It should be prefilled in ShareDialog like this

Upvotes: 0

Views: 1199

Answers (1)

GianhTran
GianhTran

Reputation: 3711

some social network like facebook does not support pre-filling the message for users as seen in their Policy: https://developers.facebook.com/policy/#socialplugins

Upvotes: 1

Related Questions