Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Platform.isTablet #13611

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Libraries/Utilities/Platform.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions Libraries/Utilities/Platform.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public List<ModuleSpec> getNativeModules(final ReactApplicationContext reactCont
new ModuleSpec(AndroidInfoModule.class, new Provider<NativeModule>() {
@Override
public NativeModule get() {
return new AndroidInfoModule();
return new AndroidInfoModule(reactContext);
}
}));
moduleSpecList.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

package com.facebook.react.modules.systeminfo;

import android.content.Context;
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;
Expand All @@ -27,6 +29,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;
}
Copy link
Contributor

@AndrewJack AndrewJack Jun 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you need the reactContext you should change this module to extend ReactContextBaseJavaModule

you can then remove the mReactApplicationContext field.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


@Override
public String getName() {
return "PlatformConstants";
Expand All @@ -36,6 +51,7 @@ public String getName() {
public @Nullable Map<String, Object> getConstants() {
HashMap<String, Object> 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;
Expand Down