Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
react-native-device-info
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
放牛的园子
react-native-device-info
Commits
23122d53
Commit
23122d53
authored
Oct 29, 2016
by
Tanner Semerad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added isTablet method for iOS and Android
parent
668996c6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
2 deletions
+18
-2
README.md
README.md
+2
-2
RNDeviceInfo.m
RNDeviceInfo/RNDeviceInfo.m
+6
-0
RNDeviceModule.java
...c/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
+7
-0
deviceinfo.js
deviceinfo.js
+3
-0
No files found.
README.md
View file @
23122d53
...
@@ -172,6 +172,6 @@ console.log("Timezone", DeviceInfo.getTimezone()); // e.g America/Mexico_City
...
@@ -172,6 +172,6 @@ console.log("Timezone", DeviceInfo.getTimezone()); // e.g America/Mexico_City
console.log("App Instance ID", DeviceInfo.getInstanceID()); // ANDROID ONLY - see https://developers.google.com/instance-id/
console.log("App Instance ID", DeviceInfo.getInstanceID()); // ANDROID ONLY - see https://developers.google.com/instance-id/
console.log("App is running in emulator", DeviceInfo.isEmulator()); // if app is running in emulator return true
console.log("App is running in emulator", DeviceInfo.isEmulator()); // if app is running in emulator return true
``
`
console.log("App is running on a tablet", DeviceInfo.isTablet()); // if app is running on a tablet return true
``
`
RNDeviceInfo/RNDeviceInfo.m
View file @
23122d53
...
@@ -157,6 +157,11 @@ RCT_EXPORT_MODULE()
...
@@ -157,6 +157,11 @@ RCT_EXPORT_MODULE()
return
[
self
.
deviceName
isEqual
:
@"Simulator"
];
return
[
self
.
deviceName
isEqual
:
@"Simulator"
];
}
}
-
(
bool
)
isTablet
{
return
[[
UIDevice
currentDevice
]
userInterfaceIdiom
]
==
UIUserInterfaceIdiomPad
;
}
-
(
NSDictionary
*
)
constantsToExport
-
(
NSDictionary
*
)
constantsToExport
{
{
UIDevice
*
currentDevice
=
[
UIDevice
currentDevice
];
UIDevice
*
currentDevice
=
[
UIDevice
currentDevice
];
...
@@ -180,6 +185,7 @@ RCT_EXPORT_MODULE()
...
@@ -180,6 +185,7 @@ RCT_EXPORT_MODULE()
@"userAgent"
:
self
.
userAgent
,
@"userAgent"
:
self
.
userAgent
,
@"timezone"
:
self
.
timezone
,
@"timezone"
:
self
.
timezone
,
@"isEmulator"
:
@
(
self
.
isEmulator
),
@"isEmulator"
:
@
(
self
.
isEmulator
),
@"isTablet"
:
@
(
self
.
isTablet
),
};
};
}
}
...
...
android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
View file @
23122d53
...
@@ -3,6 +3,7 @@ package com.learnium.RNDeviceInfo;
...
@@ -3,6 +3,7 @@ package com.learnium.RNDeviceInfo;
import
android.bluetooth.BluetoothAdapter
;
import
android.bluetooth.BluetoothAdapter
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
import
android.content.pm.PackageManager
;
import
android.content.res.Configuration
;
import
android.os.Build
;
import
android.os.Build
;
import
android.provider.Settings.Secure
;
import
android.provider.Settings.Secure
;
...
@@ -63,6 +64,11 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
...
@@ -63,6 +64,11 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
||
"google_sdk"
.
equals
(
Build
.
PRODUCT
);
||
"google_sdk"
.
equals
(
Build
.
PRODUCT
);
}
}
private
Boolean
isTablet
()
{
int
layout
=
getReactApplicationContext
().
getResources
().
getConfiguration
().
screenLayout
&
Configuration
.
SCREENLAYOUT_SIZE_MASK
;
return
layout
==
Configuration
.
SCREENLAYOUT_SIZE_LARGE
||
layout
==
Configuration
.
SCREENLAYOUT_SIZE_XLARGE
;
}
@Override
@Override
public
@Nullable
Map
<
String
,
Object
>
getConstants
()
{
public
@Nullable
Map
<
String
,
Object
>
getConstants
()
{
HashMap
<
String
,
Object
>
constants
=
new
HashMap
<
String
,
Object
>();
HashMap
<
String
,
Object
>
constants
=
new
HashMap
<
String
,
Object
>();
...
@@ -106,6 +112,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
...
@@ -106,6 +112,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
constants
.
put
(
"userAgent"
,
System
.
getProperty
(
"http.agent"
));
constants
.
put
(
"userAgent"
,
System
.
getProperty
(
"http.agent"
));
constants
.
put
(
"timezone"
,
TimeZone
.
getDefault
().
getID
());
constants
.
put
(
"timezone"
,
TimeZone
.
getDefault
().
getID
());
constants
.
put
(
"isEmulator"
,
this
.
isEmulator
());
constants
.
put
(
"isEmulator"
,
this
.
isEmulator
());
constants
.
put
(
"isTablet"
,
this
.
isTablet
());
return
constants
;
return
constants
;
}
}
}
}
deviceinfo.js
View file @
23122d53
...
@@ -59,4 +59,7 @@ module.exports = {
...
@@ -59,4 +59,7 @@ module.exports = {
isEmulator
:
function
()
{
isEmulator
:
function
()
{
return
RNDeviceInfo
.
isEmulator
;
return
RNDeviceInfo
.
isEmulator
;
},
},
isTablet
:
function
()
{
return
RNDeviceInfo
.
isTablet
;
},
};
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment