-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react-native-fbsdk ShareDialog.show promise not resolves in Android #12457
Comments
Please try following steps:
and in FBShareDialogModule constructor
|
Thanks @aakashrai1 I will test soon. |
@aakashrai1 Not work for me. Here is FBShareDialogModule.java package com.facebook.reactnative.androidsdk;
import android.app.Activity;
import android.content.Intent;
import com.facebook.CallbackManager;
import com.facebook.FacebookException;
import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.facebook.share.Sharer;
import com.facebook.share.widget.ShareDialog;
public class FBShareDialogModule extends FBSDKDialogBaseJavaModule implements ActivityEventListener {
private CallbackManager fbCallbackManager;
@Override
public void onActivityResult(Activity activity, final int requestCode, final int resultCode, final Intent data) {
fbCallbackManager.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onNewIntent(Intent intent) {}
private class ShareDialogCallback extends ReactNativeFacebookSDKCallback<Sharer.Result> {
public ShareDialogCallback(Promise promise) {
super(promise);
}
@Override
public void onSuccess(Sharer.Result result) {
if (mPromise != null) {
WritableMap shareResult = Arguments.createMap();
shareResult.putString("postId", result.getPostId());
mPromise.resolve(shareResult);
mPromise = null;
}
}
}
private ShareDialog.Mode mShareDialogMode;
private boolean mShouldFailOnError;
public FBShareDialogModule(ReactApplicationContext reactContext, CallbackManager callbackManager) {
super(reactContext, callbackManager);
fbCallbackManager = callbackManager;
reactContext.addActivityEventListener(this);
}
@Override
public String getName() {
return "FBShareDialog";
}
@ReactMethod
public void canShow(ReadableMap shareContent, Promise promise) {
if (getCurrentActivity() != null) {
ShareDialog shareDialog = new ShareDialog(getCurrentActivity());
promise.resolve(
mShareDialogMode == null
? shareDialog.canShow(Utility.buildShareContent(shareContent))
: shareDialog.canShow(Utility.buildShareContent(shareContent), mShareDialogMode)
);
} else {
promise.reject("No current activity.");
}
}
@ReactMethod
public void show(ReadableMap shareContent, final Promise promise) {
if (getCurrentActivity() != null) {
ShareDialog shareDialog = new ShareDialog(getCurrentActivity());
shareDialog.registerCallback(getCallbackManager(), new ShareDialogCallback(promise));
shareDialog.setShouldFailOnDataError(mShouldFailOnError);
if (mShareDialogMode != null) {
shareDialog.show(Utility.buildShareContent(shareContent), mShareDialogMode);
} else {
shareDialog.show(Utility.buildShareContent(shareContent));
}
} else {
promise.reject("No current activity.");
}
}
@ReactMethod
public void setMode(String mode) {
mShareDialogMode = ShareDialog.Mode.valueOf(mode.toUpperCase());
}
@ReactMethod
public void setShouldFailOnError(boolean shouldFailOnError) {
mShouldFailOnError = shouldFailOnError;
}
} |
I think https://github.com/facebook/react-native-fbsdk is a better place for this issue |
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally! If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution. |
try sharePhotoWithShareDialog() { |
Description
In my app, user selects an image, makes some modifications to the image, and then uses ShareDialog to send the processed image to his Facebook account.
I can successfully share the image, but I never get the result of the promise.
I'm trying in many ways but in all of them I don't know if it was shared successfully or canceled by the user to update the user interface accordingly.
Reproduction
My sharePhotoContent object
Below it is all the ways I tried to get result of the promise.
And even trying to call ShareDialog.show directly did not work for me.
Additional Information
In iOS works perfectly.
The text was updated successfully, but these errors were encountered: