Skip to content
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

Receive share also when app is already running? #18

Closed
georgjaehnig opened this issue Apr 4, 2017 · 4 comments
Closed

Receive share also when app is already running? #18

georgjaehnig opened this issue Apr 4, 2017 · 4 comments

Comments

@georgjaehnig
Copy link

georgjaehnig commented Apr 4, 2017

Hi, thanks for your module! It does work on my app – but only when the app was not started yet. If the app is already running in the background, nothing happens.

It's also kind of clear to me: componentWillMount() was already called, so there is no trigger at this point. But is there still a way to get this working, i.e. that I can share a (new) text even when my target app is already running?

Here's my current code:

componentWillMount() {
  ShareMenu.getSharedText((text) => {
    console.log(text);
  });
}
@georgjaehnig georgjaehnig changed the title Receive share when app is already running? Receive share also when app is already running? Apr 4, 2017
@caiosba
Copy link
Collaborator

caiosba commented Apr 5, 2017

Humm try this please:

componentWillUpdate() { ShareMenu.getSharedText((text) => { console.log(text); }); }

@georgjaehnig
Copy link
Author

georgjaehnig commented Apr 5, 2017

Unfortunately, using componentWillUpdate() doesn't help:

  • On the one hand, it now gets triggered way too often, namely on any screen update, even if I just change a Picker value.
  • On the other hand, still nothing happens when I call the share action from another app while my app is running.

Interestingly, even the following is the case:

  • Let's say my app is not running and I share the text foo to my app. Then my app starts, and with the code in componentWillUpdate(), I see foo – as it should be.
  • But now, if I share from the other app bar, at first nothing happens. Then, If I cause a component update (for instance by changing a Picker value), the text from ShareMenu.getSharedText is still foo.

I guess we must somehow tie this code to a event, no? Maybe according to Linking, add an event listener, so that it's possible to write

addEventListener('text', this._handleTextShare);

no?

BTW: I'm testing on Android 6.0.1.

@georgjaehnig
Copy link
Author

So I could solve the problem for me with setting

    android:launchMode="singleTop"

within AndroidManifest.xml. Context:

  <activity
    android:name=".MainActivity"
    android:launchMode="singleTop"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="adjustResize">
    <intent-filter>
    ...

@caiosba
Copy link
Collaborator

caiosba commented Dec 30, 2017

I just fixed this on version 2.0.0. I basically had to implement onNewIntent on the module code. In my code I also had to implement some logic to get the latest intent when the app comes to foreground: https://github.com/meedan/check-mark/blob/150f88fb83f08d41a0530827d5a02a544859f3ed/index.js#L70-L110.

@caiosba caiosba closed this as completed Dec 30, 2017
arkahood pushed a commit to arkahood/react-native-share-menu that referenced this issue Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants