From 9ce3bcbbef18d93c44b769ac0fc16b84c04ba856 Mon Sep 17 00:00:00 2001 From: Reza Date: Fri, 21 Apr 2017 17:32:48 +0430 Subject: [PATCH 1/2] add Platform.isTablet --- Libraries/Utilities/Platform.android.js | 4 ++++ Libraries/Utilities/Platform.ios.js | 4 ++++ .../facebook/react/CoreModulesPackage.java | 2 +- .../modules/systeminfo/AndroidInfoModule.java | 23 +++++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Libraries/Utilities/Platform.android.js b/Libraries/Utilities/Platform.android.js index 4bab19c5287227..f35b677aee4052 100644 --- a/Libraries/Utilities/Platform.android.js +++ b/Libraries/Utilities/Platform.android.js @@ -20,6 +20,10 @@ const Platform = { const constants = NativeModules.PlatformConstants; return constants && constants.Version; }, + get isTablet() { + const constants = NativeModules.PlatformConstants; + return constants && constants.isTablet; + }, get isTesting(): boolean { const constants = NativeModules.PlatformConstants; return constants && constants.isTesting; diff --git a/Libraries/Utilities/Platform.ios.js b/Libraries/Utilities/Platform.ios.js index 3238a44627fe9c..6872e71640f03f 100644 --- a/Libraries/Utilities/Platform.ios.js +++ b/Libraries/Utilities/Platform.ios.js @@ -20,6 +20,10 @@ const Platform = { const constants = NativeModules.PlatformConstants; return constants && constants.osVersion; }, + get isTablet() { + const constants = NativeModules.PlatformConstants; + return constants ? constants.interfaceIdiom === 'pad' : false; + }, get isPad() { const constants = NativeModules.PlatformConstants; return constants ? constants.interfaceIdiom === 'pad' : false; diff --git a/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java b/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java index 88e53489065cda..f26da38b01ee6c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java @@ -99,7 +99,7 @@ public List getNativeModules(final ReactApplicationContext reactCont new ModuleSpec(AndroidInfoModule.class, new Provider() { @Override public NativeModule get() { - return new AndroidInfoModule(); + return new AndroidInfoModule(reactContext); } })); moduleSpecList.add( diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java index 07666145e48ece..414464af0b6074 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java @@ -9,9 +9,12 @@ package com.facebook.react.modules.systeminfo; +import android.content.Context; +import android.content.res.Configuration; import android.os.Build; import com.facebook.react.bridge.BaseJavaModule; +import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.module.annotations.ReactModule; import java.util.HashMap; @@ -27,6 +30,19 @@ public class AndroidInfoModule extends BaseJavaModule { private static final String IS_TESTING = "IS_TESTING"; + private @Nullable ReactApplicationContext mReactApplicationContext; + private boolean isTablet; + + public AndroidInfoModule(ReactApplicationContext reactContext) { + this((Context) reactContext); + mReactApplicationContext = reactContext; + } + + public AndroidInfoModule(Context context) { + mReactApplicationContext = null; + isTablet = context.getResources().getConfiguration().smallestScreenWidthDp >= 600; + } + @Override public String getName() { return "PlatformConstants"; @@ -36,8 +52,15 @@ public String getName() { public @Nullable Map getConstants() { HashMap constants = new HashMap<>(); constants.put("Version", Build.VERSION.SDK_INT); + constants.put("isTablet", isTablet); constants.put("ServerHost", AndroidInfoHelpers.getServerHost()); constants.put("isTesting", "true".equals(System.getProperty(IS_TESTING))); return constants; } + + // private boolean isTablet(Context context) { + // return (context.getResources().getConfiguration().screenLayout + // & Configuration.SCREENLAYOUT_SIZE_MASK) + // >= Configuration.SCREENLAYOUT_SIZE_LARGE; + // } } From 1148808503cad61889cb6ec55ef54ecd9a3d6ea6 Mon Sep 17 00:00:00 2001 From: Reza Date: Fri, 21 Apr 2017 17:37:24 +0430 Subject: [PATCH 2/2] clean code --- .../react/modules/systeminfo/AndroidInfoModule.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java index 414464af0b6074..8c87b8b9bc8563 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java @@ -10,7 +10,6 @@ package com.facebook.react.modules.systeminfo; import android.content.Context; -import android.content.res.Configuration; import android.os.Build; import com.facebook.react.bridge.BaseJavaModule; @@ -57,10 +56,4 @@ public String getName() { constants.put("isTesting", "true".equals(System.getProperty(IS_TESTING))); return constants; } - - // private boolean isTablet(Context context) { - // return (context.getResources().getConfiguration().screenLayout - // & Configuration.SCREENLAYOUT_SIZE_MASK) - // >= Configuration.SCREENLAYOUT_SIZE_LARGE; - // } }