MaxAst / expo-share-extension

Expo config plugin for creating iOS share extensions with a custom view.
MIT License
161 stars 4 forks source link

[Feature Request] Open containing app in share extension #22

Closed dongsuo closed 1 month ago

dongsuo commented 1 month ago

First of all, thanks for this great repo, it helped a lot. I'm trying to replace https://github.com/timedtext/expo-config-plugin-ios-share-extension#readme with this in my project, but I found I can't open my app in share extension. So I did some research and found some workaround to do it. Hope someone can bring this feature to this repo and here are some links may help.

https://stackoverflow.com/questions/73040801/ios-how-to-let-user-share-url-from-safari-chrome-in-swiftui-app/73124182#73124182 https://medium.com/@damisipikuda/how-to-receive-a-shared-content-in-an-ios-application-4d5964229701 https://www.reddit.com/r/iOSProgramming/comments/137ratu/share_extension_opening_containing_app_when_apple/

MaxAst commented 1 month ago

redirecting to the main app is on the roadmap, I'm still thinking about how to design the API for this. I'll probably do this via option fields in the config plugin definition, e.g. something like this:

    [
      "expo-share-extension",
      {
        redirectingActivationRules: ["NSExtensionActivationSupportsWebURLWithMaxCount"]
      },
    ]

if we wanna use the exact names of the iOS activation rules

or something more abstract and easy like:

    [
      "expo-share-extension",
      {
        redirectingActivationRules: ["url", "video"]
      },
    ]

Alternatively, we could do this via a method exported by expo-share-extension called redirect or something, so that you could do this programmatically in the react native root component of the share extension. However, that would unnecessarily create the overhead of starting react native in the share extension view.

Do you have any preferences on this? I'm also open for other ideas

dongsuo commented 1 month ago

Glad to hear you are considering this! So the first solution is when user click the ShareExtension icon, then jump to app directly and the second one is open the modal and let developer decide how to use the redirect api, am I right? If my understanding is right As my usage case, I prefer the second one, but I don't know if others want the first one, because developer can also use a modal in their app and don't have to sync some status(like auth and subscription status) between ShareExtension and the containing app, it seems much easier. BTW, is it possible we can have both? If there is a config, then choose the first one, if no config, pop up the modal like current.

MaxAst commented 1 month ago

Hey @dongsuo, I added a openHostApp function as part of #25 which you can import from expo-share-extension. Like this, you can share content via a query param in the url. You can also use react-native-mmkv by writing the data before the redirect in the share extension, and reading it in the host app. Hope this suits your use case. Will close the issue for now, let me know if you run into any issues.