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

App rerender after click on push notification #701

Closed
janaka120 opened this issue Jan 5, 2019 · 31 comments
Closed

App rerender after click on push notification #701

janaka120 opened this issue Jan 5, 2019 · 31 comments

Comments

@janaka120
Copy link

Description:
When I clicked on push notification, my Android app is getting render again. I didn't check it on IOS.

Environment
react-native-onesignal: 3.2.11,
react: 16.6.0-alpha.8af6728,
react-native: 0.57.4,

I used npm install --save react-native-onesignal command to install oneSignal.

I configured the oneSignal package according to this documentation. https://documentation.onesignal.com/v5.0/docs/react-native-sdk-setup

Steps to Reproduce Issue:

  1. Install the OneSignal SDK using npm into your project
  2. Initialize the SDK in the Android
  3. Send a push notification throught OneSignal webSite(for testing purpose).
  4. App is running in foreground.
  5. Clicked on the push notification received.
  6. App is render again.

I'm using react-navigation: 2.16.
This is my code.

componentDidMount() {
        // One signal notification settings
        OneSignal.configure();
        OneSignal.setLogLevel(5, 0); // adb logcat debug (5) logs
        OneSignal.init('xxxxxxxxxxxx');
        OneSignal.inFocusDisplaying(2);
        OneSignal.addEventListener('ids', this.onIds);
        OneSignal.getPermissionSubscriptionState((status) => {
            if(status.userId)
                // update userID using props
	});
    }
    onIds = (device) => {
        const userId = device.userId;
        if(userId)
           // update userID using props

        OneSignal.removeEventListener('ids', this.onIds);
    }

I removed all the event listeners(received, opened), I used. But when I clicked on the push notification. My Android app rerender.

        OneSignal.addEventListener('received', this.onReceived);
        OneSignal.addEventListener('opened', this.onOpened); 

I try to find out a solution, But I couldn't. If some has any idea about this Please tell me.

@janaka120
Copy link
Author

I find out, why app gets rerender. Because when I clicked on notification, app goes to background and then it comes to foreground.
why does app status change? when I clicked on notification.
How to stop this.

@martinosmartinos
Copy link

Did you add android:launchMode="singleTop" to your AndroidManifest.xml?

@janaka120
Copy link
Author

@martinosmartinos yes, I added it.

@martinosmartinos
Copy link

Try to move your logic into componentWillMount lifecycle instead and see if it helps.

@janaka120
Copy link
Author

Thanks for your support @martinosmartinos. But it didn't work.

@rgomezp
Copy link
Contributor

rgomezp commented Jan 30, 2019

Hello @janaka120
It sounds like you're trying to deep-link into your app. You can find more information on this topic here. You may also be encountering an issue due to react-navigation.

I'm wondering if the entire app is re-rendering or if you mean that the current screen gets re-rendered (react-lifecycle)?

@janaka120
Copy link
Author

Hi @rgomezp

My entire app is rendering when I tap on push-notification.

@rgomezp
Copy link
Contributor

rgomezp commented Jan 31, 2019

@janaka120 I see. Is the metro-bundler rebuilding everything or do you simply get taken back to the splash-screen and/or homepage?

@janaka120
Copy link
Author

janaka120 commented Feb 1, 2019

@rgomezp I don't get back to the splash-screen. I get back to the homepage. When I console my main app.js after tap on push notification, it rendered So my app route to home screen.

@rgomezp
Copy link
Contributor

rgomezp commented Feb 1, 2019

@janaka120 ok so just to confirm, the app is not being re-bundled correct?

@janaka120
Copy link
Author

@rgomezp yes. It's not rebundling.

@rgomezp
Copy link
Contributor

rgomezp commented Feb 5, 2019

This sounds like a deep-linking issue. Please read our documentation on setting deep-links correctly and verify that you did everything correctly. https://documentation.onesignal.com/docs/links

@janaka120
Copy link
Author

@rgomezp I didn't use any deep-link with push-notification.

@rgomezp
Copy link
Contributor

rgomezp commented Feb 20, 2019

Can you please test on iOS to see if you are getting the same result? I'm not sure why this is happening. React will re-render when state changes

@rgomezp
Copy link
Contributor

rgomezp commented Mar 4, 2019

Closing due to no response

@rgomezp rgomezp closed this as completed Mar 4, 2019
@karvulf
Copy link

karvulf commented Aug 14, 2019

That could solve your problem:
Instead of using android:launchMode="singleTop"use android:launchMode="singleTask"

@hotaryuzaki
Copy link

That could solve your problem:
Instead of using android:launchMode="singleTop"use android:launchMode="singleTask"

i have same issue.
another problem is when i open deep link from Email, apps open new app task. If i open task manager my apps have multiple tabs running.
And it solved if i change to SINGLETASK.

But my question, is there any problem that i must concern if change to SINGLETASK??

@lafiosca
Copy link

@rgomezp I believe I'm experiencing the same problem as the original poster on Android. My application is running, and I minimize it. A push notification arrives, and I tap it to open the application. At this point, the entire application reinitializes. It does not behave this way on iOS. I am currently using singleTop as recommended by the SDK docs, but I'm curious if another mode might fix this problem.

@hotaryuzaki
Copy link

Use singleTask instead.
I don't understand why they're not fix this issue, because this is very important

@lafiosca
Copy link

lafiosca commented Oct 1, 2019

Thanks @hotaryuzaki, after posting my comment yesterday I tried out singleTask which seems to be working so far without any noticeable problems. I am concerned though because the SDK authors have said multiple times that this could cause issues.

@hotaryuzaki
Copy link

Yes I got confirmed by them about that, but they weren't mentioned the detail which problem they mean.
If it was an issue, I don't know why they're didn't fix that.

@rgomezp
Copy link
Contributor

rgomezp commented Oct 1, 2019

Howdy,
We are planning to fix this in a future release. Thanks for your patience

@jariwalabhavesh
Copy link

jariwalabhavesh commented Oct 5, 2019

@rgomezp : Can you provide possible issue detail that may occure on changing launchMode from 'singleTop' to 'singleTask'.
So we can understand risk of switching to 'singleTask'
I am also facing an issue with auth0 and onesignal.

Right now I had swithed to 'singleTask'

@rgomezp
Copy link
Contributor

rgomezp commented Oct 8, 2019

Setting it to singleTask may result in multiple copies of your activity being created

@jariwalabhavesh

@jariwalabhavesh
Copy link

@rgomezp :
Thanks for the response.
I think as you mention in previous comment that you guys are planning for a fix. Till that we will wait.

@xeroxoid
Copy link

xeroxoid commented Nov 13, 2019

@rgomezp As per React Native documentation (https://facebook.github.io/react-native/docs/linking) Linking requires the MainActivity to be singleTask. Is there away around this for OneSignal?

@samitha9125
Copy link

Howdy,
We are planning to fix this in a future release. Thanks for your patience

@rgomezp Thank you for working on this and is this issue fixed yet?

@rgomezp
Copy link
Contributor

rgomezp commented Jan 28, 2020

This feature request has not been implemented yet

@bernhardt1
Copy link

@rgomezp is there an ETA for when the fix will come through? IMO: This is the biggest problem with onesignal for react native in its current state.

I have also switched to singleTask.

I am not seeing multiple copies of the activity being created when using singleTask. Plus it is the only way to stop the app from re-launching on notification press. It is also necessary to have deep links work properly...

@KestasVenslauskas
Copy link

Having same problems with push notifications on android. But I do use deep links.
The problem is that if app is killed and opened from notification it open from loading everything from start. If user pressed Home button and comes back again app always reloads and always re-launches same launchUrl from depp-linking.

@FayyazAliKhan1
Copy link

@KestasVenslauskas did you managed to solve this cause I also implement the deep link and the same problem is coming to me

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