microsoft / react-native-test-app

react-native-test-app provides an app for all supported platforms as a package
MIT License
595 stars 91 forks source link

Handle orientation change on Android #2207

Closed CptFabulouso closed 1 month ago

CptFabulouso commented 1 month ago

Proposal

I am using this library for the first time to create a native module and I've spend quite some time trying to achieve a stable application state after I rotate an Android device. All my attempts to have a View to keep it's state failed and googling did not return anything. Only to discover that RN with it's initial setup has this in AndroidManifest in the activity tag android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|uiMode". The TestApp does not have that and I didn't find any way to do it (other that add it manually to the generated project). Shouldn't this be the default configuration? Or at least have the option to enable it in app.json? I assume this is how RN is intended to behave, it seems they do not have any support for preserving the app state.

Alternatives

I didn't find any way how to preserve application state upon orientation change.

Implementation Details

Add android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|uiMode" to activity tag in AndroidManifest. Or allow to enable this via app.json config

Additional Context

No response

Code of Conduct

tido64 commented 1 month ago

Hi, thanks for opening this issue. The default values should've been whatever the template defaults to. I guess we just missed it.

CptFabulouso commented 1 month ago

Hi. In case of this library the configChanges should be on "com.microsoft.reacttestapp.component.ComponentActivity", not the "com.microsoft.reacttestapp.MainActivity". I guess the ComponentActivity is what mounts the RN code. It can be removed from MainActivity

tido64 commented 1 month ago

Hi. In case of this library the configChanges should be on "com.microsoft.reacttestapp.component.ComponentActivity", not the "com.microsoft.reacttestapp.MainActivity". I guess the ComponentActivity is what mounts the RN code. It can be removed from MainActivity

Thanks for pointing that out. I totally missed the mark on that one. Can you please check the latest PR and make sure it works for you?

CptFabulouso commented 1 month ago

After installing the package from PR I get "React Native CLI failed to determine Android project configuration" during build, so I can't test that directly, but after applying the same changes to generated AndroidManifest, it works like it should.