Cap-go / capacitor-inappbrowser

Capacitor plugin in app browser with urlChangeEvent
MIT License
58 stars 37 forks source link

Capacitor Share Api #102

Closed qliqdev closed 1 month ago

qliqdev commented 5 months ago

Hello can not use Capasitor Share plugin while InAppBrowser's view controller is presented

await InAppBrowser.openWebView({
        url: '<some url>',
        title: 'Title',
        visibleTitle: false,
        toolbarType: ToolBarType.BLANK,
        isAnimated: false
});

await InAppBrowser.addListener('urlChangeEvent', async (event: UrlEvent) => {
        console.log(event.url);
        if (event.url.includes('#share')) {
          await Share.share({url: event.url});
        } else if (event.url.includes('#exit')) {
          await InAppBrowser.close();
        }
});

catching error in

https://github.com/ionic-team/capacitor-plugins/blob/c4f916521b1d14bfb2ddac651b1fdc33e4c29884/share/ios/Sources/SharePlugin/SharePlugin.swift#L67-L70

Are there any best practices how to user Capacitor Share plugin with capacitor-inappbrowser

riderx commented 4 months ago

I have no idea why this catch in share plugin, but since it catch there where there is no apparent reason maybe try to open issue in SharePlugin repo?

gasci commented 1 month ago

Yes, I am getting the same error, too. @qliqdev

I had to build the share button on my website that is being opened by this plugin.

riderx commented 1 month ago

Again this is not a bug, you cannot show 2 native views on top of each others in capacitor. Close the browser first and this will work

gasci commented 1 month ago

Unfortunately, the close method doesn't close the webview, either. It just puts it to the background. Therefore, we are not able to use the Share API and this plugin together. Please test them together and you will also experience the same issue. (I mean when we open a webview)

riderx commented 1 month ago

This make more sense, do you have the issue on android or iOS ?

gasci commented 1 month ago

Oh sorry that I haven't stated it beforehand. It is on iOS 17.4.1. Capacitor 6.0.0.

qliqdev commented 1 month ago

SharePlugin prevents from opening another ViewController because of this code

if self?.bridge?.viewController?.presentedViewController != nil {
    call.reject("Can't share while sharing is in progress")
    return
}

https://github.com/ionic-team/capacitor-plugins/blob/c4f916521b1d14bfb2ddac651b1fdc33e4c29884/share/ios/Sources/SharePlugin/SharePlugin.swift#L67-L70

for now i'm using Share.open() after await InAppBrowser.close();. This is the only way i think

complete code looks like

await InAppBrowser.addListener('urlChangeEvent', async (event: UrlEvent) => {
  const url = new URL(event.url);
  if (url.hash?.startsWith('#share')) {
    await InAppBrowser.close();
    Share.open({...})
  } else if (url.hash?.startsWith('#exit')) {
    await InAppBrowser.close();
    await this.router.navigate(['/home']);
  }
});