Skip to content

Commit

Permalink
Expose initialAppState constant from Android native AppState module (f…
Browse files Browse the repository at this point in the history
…acebook#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: facebook#19935

Reviewed By: hramos

Differential Revision: D13774044

Pulled By: ejanzer

fbshipit-source-id: 05d27e702cb9aeedf14293158bfd50004df4726b
  • Loading branch information
Oleg Bogdanov authored and facebook-github-bot committed Jan 24, 2019
1 parent 6eeb874 commit 0677ce5
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,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 {
Expand All @@ -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
Expand All @@ -38,8 +47,10 @@ public String getName() {
}

@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
Expand Down

0 comments on commit 0677ce5

Please sign in to comment.