Permalink
Browse files

Allow DeviceInfoModule to be instantiated with only an android Context

Reviewed By: javache

Differential Revision: D4772673

fbshipit-source-id: 80894faa076ccfddf0fe28bd4d7b6aaeba6c38a5
  • Loading branch information...
mhorowitz authored and facebook-github-bot committed Mar 31, 2017
1 parent 1916b38 commit ec4b85467db3a354e26f03d33ff0d703cf1b1585
@@ -14,12 +14,13 @@
import java.util.HashMap;
import java.util.Map;
import android.content.Context;
import android.util.DisplayMetrics;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.BaseJavaModule;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.core.DeviceEventManagerModule;
@@ -29,16 +30,21 @@
* Module that exposes Android Constants to JS.
*/
@ReactModule(name = "DeviceInfo")
public class DeviceInfoModule extends ReactContextBaseJavaModule implements
public class DeviceInfoModule extends BaseJavaModule implements
LifecycleEventListener {
private @Nullable ReactApplicationContext mReactApplicationContext;
private float mFontScale;
public DeviceInfoModule(
ReactApplicationContext reactContext) {
super(reactContext);
public DeviceInfoModule(ReactApplicationContext reactContext) {
this((Context) reactContext);
mReactApplicationContext = reactContext;
}
mFontScale = getReactApplicationContext().getResources().getConfiguration().fontScale;
public DeviceInfoModule(Context context) {
mReactApplicationContext = null;
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(context);
mFontScale = context.getResources().getConfiguration().fontScale;
}
@Override
@@ -57,7 +63,11 @@ public String getName() {
@Override
public void onHostResume() {
float fontScale = getReactApplicationContext().getResources().getConfiguration().fontScale;
if (mReactApplicationContext == null) {
return;
}
float fontScale = mReactApplicationContext.getResources().getConfiguration().fontScale;
if (mFontScale != fontScale) {
mFontScale = fontScale;
emitUpdateDimensionsEvent();
@@ -73,7 +83,11 @@ public void onHostDestroy() {
}
public void emitUpdateDimensionsEvent() {
getReactApplicationContext()
if (mReactApplicationContext == null) {
return;
}
mReactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("didUpdateDimensions", getDimensionsConstants());
}

0 comments on commit ec4b854

Please sign in to comment.