urbanairship / react-native-airship

Airship React Native module
Other
86 stars 62 forks source link

Expo SDK 50 - Foreground notifications cause app to reload #550

Open robwalkerco opened 7 months ago

robwalkerco commented 7 months ago

❗For how-to inquiries involving Airship functionality or use cases, please contact (support)[https://support.airship.com/].

Preliminary Info

What Airship dependencies are you using?

"@ua/react-native-airship": "^17.1.1", "airship-expo-plugin": "^1.1.0",

What are the versions of any relevant development tools you are using?

"expo": "^50.0.2",

Report

What unexpected behaviour are you seeing?

When I receive a notification and the app is active and in the foreground, then tapping the app is causing the app to be reloaded.

I suspect this is because of something working differently either in React Native 0.73 or in Expo SDK 50

What is the expected behaviour?

When I receive a notification and the app is active and in the foreground, then I expect that tapping the notification allows the app to handle the notification in the foreground.

What are the steps to reproduce the unexpected behaviour?

I'm replicating this by upgrading from a Expo SDK 49 to Expo SDK 50 project

Do you have logging for the issue?

No

rlepinski commented 7 months ago

What OS are you testing on?

robwalkerco commented 7 months ago

What OS are you testing on?

Oh, sorry. That is replicated on Android 14.

I have not tested on iOS

rlepinski commented 7 months ago

This could be old Android knowledge that I need to forget, but I remember a similar issue when launching a notification if the app was started through AS/adb. If you start the app that way, kill it, then launch it normally it would have the proper restore launch intent behavior. Could you double check that? If its still happening I will need the manifest to see if I can make sense of whats going on

robwalkerco commented 7 months ago

if the app was started through AS/adb

That could be it. I'll test tomorrow morning and confirm either way

robwalkerco commented 7 months ago

I've tested again and found the following:

When using the expo-dev-client and building and running the development app, the app reloads each time I tap on a notification in the foreground.

If I build and sign the app, then tapping a foreground notification does not cause the app to reload.

There are some changes between Expo 49 and Expo 50 regarding how the app is launched, summarised in the change log - https://expo.dev/changelog/2024/01-18-sdk-50#other-highlights (See the 4th point regarding expo-dev-client)

I have also been able to restore the original behaviour by setting the launchModeExperimental property of the expo-dev-client plugin to launcher.

module.exports = {
  expo: {
    ...,
    plugins: [
      ...,
      [
        'expo-dev-client',
        {
          ios: {
            launchModeExperimental: 'launcher',
          },
          android: {
            launchModeExperimental: 'launcher',
          },
        },
      ]
    ]
  }
}

With this change, the original launcher behaviour is used - Opening the app from a push notification requires selecting the bundler to use from the expo dev client menu, but tapping a notification from the foreground is handled in the foreground 🎉

I can consider my problem fixed now, but it would be great if there is a way to resolve this issue without having to specify the launchModeExperimental option. If this cannot be changed, then perhaps a note in the documentation would be helpful for others having the same issue.

MaxInMoon commented 3 months ago

@robwalkerco thank you so much man

robwalkerco commented 3 months ago

@robwalkerco thank you so much man

You're welcome @MaxInMoon.

For anyone running into this issue, the config property was renamed in the latest Expo SDK to launchMode (docs)