From e9d82318a1f65e93b6b62cc16da1e8549c5795b9 Mon Sep 17 00:00:00 2001 From: Oleg Bogdanov Date: Wed, 27 Jun 2018 13:57:03 -0700 Subject: [PATCH 1/2] Expose initialAppState constant from Android native AppState module --- .../modules/appstate/AppStateModule.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/appstate/AppStateModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/appstate/AppStateModule.java index f4bc26fbafedbf..899631b819d66b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/appstate/AppStateModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/appstate/AppStateModule.java @@ -1,8 +1,10 @@ /** * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. */ package com.facebook.react.modules.appstate; @@ -14,9 +16,13 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.WritableMap; +import com.facebook.react.common.LifecycleState; import com.facebook.react.module.annotations.ReactModule; import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter; +import java.util.HashMap; +import java.util.Map; + @ReactModule(name = AppStateModule.NAME) public class AppStateModule extends ReactContextBaseJavaModule implements LifecycleEventListener { @@ -26,10 +32,15 @@ public class AppStateModule extends ReactContextBaseJavaModule public static final String APP_STATE_ACTIVE = "active"; public static final String APP_STATE_BACKGROUND = "background"; - private String mAppState = "uninitialized"; + private static final String INITIAL_STATE = "initialAppState"; + + private String mAppState; public AppStateModule(ReactApplicationContext reactContext) { super(reactContext); + reactContext.addLifecycleEventListener(this); + mAppState = (reactContext.getLifecycleState() == LifecycleState.RESUMED ? + APP_STATE_ACTIVE : APP_STATE_BACKGROUND); } @Override @@ -38,8 +49,10 @@ public String getName() { } @Override - public void initialize() { - getReactApplicationContext().addLifecycleEventListener(this); + public Map getConstants() { + HashMap constants = new HashMap<>(); + constants.put(INITIAL_STATE, mAppState); + return constants; } @ReactMethod From 05f569a24f729325995e0076b783bf81b832521f Mon Sep 17 00:00:00 2001 From: Oleg Bogdanov Date: Wed, 27 Jun 2018 13:58:28 -0700 Subject: [PATCH 2/2] fixing license text --- .../com/facebook/react/modules/appstate/AppStateModule.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/appstate/AppStateModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/appstate/AppStateModule.java index 899631b819d66b..d979ae5755492a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/appstate/AppStateModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/appstate/AppStateModule.java @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ package com.facebook.react.modules.appstate;