Expose initialAppState constant from Android native AppState module (#19935)
Summary: This PR addresses TODO left in _AppState.js_ The goal is to align AppState module implementation between iOS and Android. iOS native module exposes _initialAppState_ constant that AppState.js relies on, while Android doesn't expose that constant and js implementation uses a fallback. This PR aims to remove a need for a fallback Pull Request resolved: https://github.com/facebook/react-native/pull/19935 Reviewed By: hramos Differential Revision: D13774044 Pulled By: ejanzer fbshipit-source-id: 05d27e702cb9aeedf14293158bfd50004df4726b
This commit is contained in:
parent
e4d7fc06cb
commit
5c0dcddc0f
|
@ -14,9 +14,13 @@ import com.facebook.react.bridge.ReactApplicationContext;
|
|||
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 +30,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 +47,10 @@ public class AppStateModule extends ReactContextBaseJavaModule
|
|||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
getReactApplicationContext().addLifecycleEventListener(this);
|
||||
public Map<String, Object> getConstants() {
|
||||
HashMap<String, Object> constants = new HashMap<>();
|
||||
constants.put(INITIAL_STATE, mAppState);
|
||||
return constants;
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
|
|
Loading…
Reference in New Issue