Remove android initialAppState fallback check (#23487)

Summary:
1. We expose the `initialAppState` for Android in #19935, so we can remove the fallback check for Android.
2. Rename `RCTCurrentAppBackgroundState` to `RCTCurrentAppState`, it's a private file function, so it's safe to rename, `RCTCurrentAppState` is more suitable because we actually get app state, not app background state.

[Android] [Enhancement] - Remove android `initialAppState` fallback check.
Pull Request resolved: https://github.com/facebook/react-native/pull/23487

Differential Revision: D14121293

Pulled By: cpojer

fbshipit-source-id: fec196cef2969fe6f6f1571f4ebcafcec26266a1
This commit is contained in:
zhongwuzw
2019-02-17 15:23:19 -08:00
committed by Facebook Github Bot
parent 5560a47c1d
commit f95876ba8c
2 changed files with 5 additions and 7 deletions

View File

@@ -38,9 +38,7 @@ class AppState extends NativeEventEmitter {
memoryWarning: new Map(),
};
// TODO: Remove the 'active' fallback after `initialAppState` is exported by
// the Android implementation.
this.currentState = RCTAppState.initialAppState || 'active';
this.currentState = RCTAppState.initialAppState;
let eventUpdated = false;

View File

@@ -12,7 +12,7 @@
#import "RCTEventDispatcher.h"
#import "RCTUtils.h"
static NSString *RCTCurrentAppBackgroundState()
static NSString *RCTCurrentAppState()
{
static NSDictionary *states;
static dispatch_once_t onceToken;
@@ -54,7 +54,7 @@ RCT_EXPORT_MODULE()
- (NSDictionary *)getConstants
{
return @{@"initialAppState": RCTCurrentAppBackgroundState()};
return @{@"initialAppState": RCTCurrentAppState()};
}
#pragma mark - Lifecycle
@@ -105,7 +105,7 @@ RCT_EXPORT_MODULE()
} else if ([notification.name isEqualToString:UIApplicationWillEnterForegroundNotification]) {
newState = @"background";
} else {
newState = RCTCurrentAppBackgroundState();
newState = RCTCurrentAppState();
}
if (![newState isEqualToString:_lastKnownState]) {
@@ -123,7 +123,7 @@ RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(getCurrentAppState:(RCTResponseSenderBlock)callback
error:(__unused RCTResponseSenderBlock)error)
{
callback(@[@{@"app_state": RCTCurrentAppBackgroundState()}]);
callback(@[@{@"app_state": RCTCurrentAppState()}]);
}
@end