You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found that global variables are not reset in one of the following situations on Android:
changing system font size in Settings app (Settings > Display > Font Size and Styles), then app is restarted.
changing navigation style between 3-button navigation and gesture navigation in Settings app, then app is restarted.
I believe that componentDidMount is called when and only on app launched, by the fact that componentDidMount is called in <App> when the restart.
If it is right, it means that the code example in "Snack, code example, screenshot, or link to a repository" indicates global variables not reset on restarting app.
As a supplement, I found that the difference between first launch and restart.
When app is restarted, Application class is still alive, not re-created.
When app launches, both Application class and Activity class are created.
Though it might be a specification that global variables are only initialized when Application class is created but not reset when Activity class is created in Android, I cannot decide if it is a bug or not, therefore I will post this issue.
React Native Version
0.70.6
Output of npx react-native info
info Fetching system and libraries information...
System:
OS: macOS 12.6
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Memory: 1.28 GB / 32.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 16.13.1 - ~/.nodenv/versions/16.13.1/bin/node
Yarn: 1.22.19 - ~/.nodenv/versions/16.13.1/bin/yarn
npm: 8.1.2 - ~/.nodenv/versions/16.13.1/bin/npm
Watchman: 2022.07.04.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /Users/*****/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
Android SDK:
Android NDK: 21.4.7075529
IDEs:
Android Studio: 2020.3 AI-203.7717.56.2031.7935034
Xcode: 14.1/14B47b - /usr/bin/xcodebuild
Languages:
Java: 11.0.12 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: 0.70.6 => 0.70.6
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
info React Native v0.71.4 is now available (your project is running on v0.70.6).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.71.4
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.70.6
info For more info, check out "https://reactnative.dev/docs/upgrading".
Steps to reproduce
This intstruction shows that a global variable is not reset when app is restarted by changing system font size.
You are on a supported minor version, but it looks like there's a newer patch available. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.
I'm having to fill in a bunch of gaps here, but I'd expect that behaviour. There are two things happening here:
your code is loaded into the VM, and
the React runtime is mounting a component.
When you cold start your application (Activity) you get 1 & 2. Moving the app between some states (running → pause → running) may cause a component to remount but importantly it isn't doing 1 (which sets globalVariable to false).
Description
I found that global variables are not reset in one of the following situations on Android:
I believe that
componentDidMount
is called when and only on app launched, by the fact thatcomponentDidMount
is called in<App>
when the restart.If it is right, it means that the code example in "Snack, code example, screenshot, or link to a repository" indicates global variables not reset on restarting app.
As a supplement, I found that the difference between first launch and restart.
Though it might be a specification that global variables are only initialized when Application class is created but not reset when Activity class is created in Android, I cannot decide if it is a bug or not, therefore I will post this issue.
React Native Version
0.70.6
Output of
npx react-native info
Steps to reproduce
This intstruction shows that a global variable is not reset when app is restarted by changing system font size.
Create sample app.
Add code to App.js as the sample describes. it contains the procedures
false
(globalVariable)globalVariable
to console logtrue
toglobalVariable
after printing loginstall app to an Android device with the following command and launch
check console log (it is expected that the value should be
false
)change system font size in "Settings" app.
set the app to foreground (the app seems to be restarted) then check console log (We are able to watch that the value is still
true
, not reset.)Snack, code example, screenshot, or link to a repository
This is an excerpt (a global variable and App component) of App.js, adding step2 in 'Steps to reproduce.'
The text was updated successfully, but these errors were encountered: