react-nativereact-native-ios

How to use react-native-share-menu without rendering mainInterface.storyboard


I've just added react-native-share-menu to my project and everything is going as expected. But I want to open my app from share menu without showing dialog modal(attached image). It shows on iOS only. enter image description here

I added didSelectPost() to the viewDidLoad() and after that it works on simulator but not working on real device.

   override func viewDidLoad() {
super.viewDidLoad()

if let hostAppId = Bundle.main.object(forInfoDictionaryKey: HOST_APP_IDENTIFIER_INFO_PLIST_KEY) as? String {
  self.hostAppId = hostAppId
} else {
  print("Error: \(NO_INFO_PLIST_INDENTIFIER_ERROR)")
}

if let hostAppUrlScheme = Bundle.main.object(forInfoDictionaryKey: HOST_URL_SCHEME_INFO_PLIST_KEY) as? String {
  self.hostAppUrlScheme = hostAppUrlScheme
} else {
  print("Error: \(NO_INFO_PLIST_URL_SCHEME_ERROR)")
}
didSelectPost() //call post function 

}


Solution

  • You need to make your own share extension, even if it's just a placeholder before you're taken to the app. Make sure you've followed these instructions to the letter:

    https://github.com/meedan/react-native-share-menu/blob/master/SHARE_EXTENSION_VIEW.md

    Once you've done that, the "MyShareComponent" you register in index.share.js will be shown instead of the dialog modal you mentioned in your post.

    AppRegistry.registerComponent(
      "ShareMenuModuleComponent",
      () => MyShareComponent
    );
    

    Inside that component, you can either show your own custom share dialog, or simply redirect to the main app after it has mounted, like this:

    useEffect(() => {
      ShareMenuReactView.data().then(({mimeType, data}) => {
        ShareMenuReactView.continueInApp({shareInfo: data});
      });
    }, []);
    

    I've had success with this method for both my own share dialog, and redirecting straight to the app.