software-mansion / react-native-screens

Native navigation primitives for your React Native app.
https://docs.swmansion.com/react-native-screens/
MIT License
3.02k stars 513 forks source link

Workaround for restore from background (#17) prevent result of ActivityResultRegistry from working correctly #2342

Open jpcoliveira opened 2 weeks ago

jpcoliveira commented 2 weeks ago

Description

I'm working on a Brownfield project and I need to interact with native contexts. The problem I'm experiencing is the failure to get activity navigation result using ActivityResultRegistry. Setting savedInstanceState to null in onCreate of the Activity Host prevents the result callback from working correctly.

private val launcher = registerForActivityResult(StartActivityForResult()) { result ->
    ...
}

Below, the workaround for avoid crash when restoring from background (#17), this prevent that other behaviors working in moment of restoring.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(null);
}

In my testing, i notice that onActivityResult is invoked, but this method is deprecated and changed for ActivityResultRegistry.

Base on this fact, does react-native-screens have any perspective of fixing this behavior for mitigate impact in projects that needs use ActivityResultRegistry?

Steps to reproduce

  1. Turn on Don't Keep Activities on your device
  2. Open the app
  3. Click on Navigate to MainActivity 2

Result don't works when returning to the MainActivity

Snack or a link to a repository

https://github.com/jpcoliveira/ActivityRegistrySample

Screens version

3.31.1

React Native version

0.71.6

Platforms

Android

JavaScript runtime

V8

Workflow

None

Architecture

None

Build type

None

Device

Real device

Device model

No response

Acknowledgements

Yes

jpcoliveira commented 2 weeks ago

@kkafar