diff --git a/Libraries/AppState/AppState.js b/Libraries/AppState/AppState.js index 1573a90129c..e8babe4dd61 100644 --- a/Libraries/AppState/AppState.js +++ b/Libraries/AppState/AppState.js @@ -83,12 +83,10 @@ class AppState extends NativeEventEmitter { memoryWarning: new Map(), }; - // TODO: getCurrentAppState callback seems to be called at a really late stage - // after app launch. Trying to get currentState when mounting App component - // will likely to have the initial value here. - // Initialize to 'active' instead of null. - this.currentState = 'active'; - + // TODO: Remove the 'active' fallback after `initialAppState` is exported by + // the Android implementation. + this.currentState = RCTAppState.initialAppState || 'active'; + // TODO: this is a terrible solution - in order to ensure `currentState` prop // is up to date, we have to register an observer that updates it whenever // the state changes, even if nobody cares. We should just deprecate the @@ -99,7 +97,7 @@ class AppState extends NativeEventEmitter { this.currentState = appStateData.app_state; } ); - + // TODO: see above - this request just populates the value of `currentState` // when the module is first initialized. Would be better to get rid of the prop // and expose `getCurrentAppState` method directly. @@ -111,7 +109,7 @@ class AppState extends NativeEventEmitter { ); } - /** + /** * Add a handler to AppState changes by listening to the `change` event type * and providing the handler * diff --git a/React/Modules/RCTAppState.m b/React/Modules/RCTAppState.m index db9716a7eff..1ae39027164 100644 --- a/React/Modules/RCTAppState.m +++ b/React/Modules/RCTAppState.m @@ -46,6 +46,11 @@ RCT_EXPORT_MODULE() return dispatch_get_main_queue(); } +- (NSDictionary *)constantsToExport +{ + return @{@"initialAppState": RCTCurrentAppBackgroundState()}; +} + #pragma mark - Lifecycle - (NSArray *)supportedEvents