Description
Actual Behavior
AppState Change Event is called as expected when the app is moved to the background with the hardware back button but it is not called when the app is resumed from the background.
AppState Change Event is called as expected when resuming the app after using the Home button so it seems to only be an issue with the hardware back button.
note:
Home button not call componentWillUnmount while Back button call it
So opening app after Home button press not calling componentDidMount while opening app after Back button calls the componentDidMount but not _handleAppStateChange
Version
0.66.3
Output of react-native info
System:
OS: macOS 11.6
CPU: (4) x64 Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz
Memory: 197.88 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.13.0 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.12.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.1 - /Users/ivasystem/.rvm/rubies/ruby-2.7.0-preview1/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 15.0, DriverKit 20.4, macOS 11.3, tvOS 15.0, watchOS 8.0
Android SDK:
API Levels: 23, 28, 29, 30
Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.2
System Images: android-28 | Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5977832
Xcode: 13.0/13A233 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_232 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.66.3 => 0.66.3
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
Steps to reproduce
Open app
Close app using the Android hardware back button
Open app again
AppState Change Event is not triggered
Expected Behavior
AppState Change Event should be called when app resumes from the background
Snack, code example, screenshot, or link to a repository
Reproducible Demo
class AppStateTest extends Component {
constructor(props) {
super(props);
this.state = {
appState: AppState.currentState
};
}
componentDidMount() {
this.appStateSubscription = AppState.addEventListener('change', this._handleAppStateChange);
}
componentWillUnmount() {
this.appStateSubscription.remove();
}
_handleAppStateChange = (nextAppState) => {
console.log(this.state.appState, nextAppState)
this.setState({appState: nextAppState})
};
}
Description
Actual Behavior
AppState Change Event is called as expected when the app is moved to the background with the hardware back button but it is not called when the app is resumed from the background.
AppState Change Event is called as expected when resuming the app after using the Home button so it seems to only be an issue with the hardware back button.
note:
Home button not call
componentWillUnmountwhile Back button call itSo opening app after Home button press not calling
componentDidMountwhile opening app after Back button calls thecomponentDidMountbut not_handleAppStateChangeVersion
0.66.3
Output of
react-native infoSystem:
OS: macOS 11.6
CPU: (4) x64 Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz
Memory: 197.88 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.13.0 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.12.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.1 - /Users/ivasystem/.rvm/rubies/ruby-2.7.0-preview1/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 15.0, DriverKit 20.4, macOS 11.3, tvOS 15.0, watchOS 8.0
Android SDK:
API Levels: 23, 28, 29, 30
Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.2
System Images: android-28 | Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5977832
Xcode: 13.0/13A233 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_232 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.66.3 => 0.66.3
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
Steps to reproduce
Open app
Close app using the Android hardware back button
Open app again
AppState Change Event is not triggered
Expected Behavior
AppState Change Event should be called when app resumes from the background
Snack, code example, screenshot, or link to a repository
Reproducible Demo