Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoto-Ida committed Nov 24, 2017
2 parents 0a374b5 + 098c379 commit 444f5a7
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -178,7 +178,7 @@ var DeviceInfo = require('react-native-device-info');
| App Version | `getVersion()` | `string` e.g. "1.1.0" | |
| App Version (Readable) | `getReadableVersion()` | `string` e.g. "1.1.0.89" | |
| Device Name | `getDeviceName()` | `string` e.g. "Becca's iPhone 6" | |
| User Agent | `getUserAgent()` | `string` e.g. "Dalvik/2.1.0 (Linux; U; Android 5.1; Google Nexus 4 - 5.1.0 - API 22 - 768x1280 Build/LMY47D)" | |
| User Agent | `getUserAgent()` | `string` e.g. "Mozilla/5.0 (Linux; Android 8.0.0; Nexus 5X Build/OPR4.170623.009; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/61.0.3163.98 Mobile Safari/537.36" | |
| Device Locale | `getDeviceLocale()` | `string` e.g. "en-US" | |
| Device Country | `getDeviceCountry()` | `string` e.g. "US" | |
| Timezone | `getTimezone()` | `string` e.g. "America/Mexico_City" | |
Expand Down
13 changes: 13 additions & 0 deletions RNDeviceInfo/RNDeviceInfo.m
Expand Up @@ -8,7 +8,9 @@

#import "RNDeviceInfo.h"
#import "DeviceUID.h"
#if !(TARGET_OS_TV)
#import <LocalAuthentication/LocalAuthentication.h>
#endif

@interface RNDeviceInfo()
@property (nonatomic) bool isEmulator;
Expand Down Expand Up @@ -192,6 +194,12 @@ - (bool) isTablet
return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
}

- (bool) is24Hour
{
NSString *format = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale currentLocale]];
return ([format rangeOfString:@"a"].location == NSNotFound);
}

- (NSDictionary *)constantsToExport
{
UIDevice *currentDevice = [UIDevice currentDevice];
Expand All @@ -218,13 +226,18 @@ - (NSDictionary *)constantsToExport
@"timezone": self.timezone,
@"isEmulator": @(self.isEmulator),
@"isTablet": @(self.isTablet),
@"is24Hour": @(self.is24Hour),
};
}

RCT_EXPORT_METHOD(isPinOrFingerprintSet:(RCTResponseSenderBlock)callback)
{
#if TARGET_OS_TV
BOOL isPinOrFingerprintSet = false;
#else
LAContext *context = [[LAContext alloc] init];
BOOL isPinOrFingerprintSet = ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:nil]);
#endif
callback(@[[NSNumber numberWithBool:isPinOrFingerprintSet]]);
}

Expand Down
Expand Up @@ -89,6 +89,10 @@ private Boolean isTablet() {
return layout == Configuration.SCREENLAYOUT_SIZE_LARGE || layout == Configuration.SCREENLAYOUT_SIZE_XLARGE;
}

private Boolean is24Hour() {
return android.text.format.DateFormat.is24HourFormat(this.reactContext.getApplicationContext());
}

@ReactMethod
public void isPinOrFingerprintSet(Callback callback) {
KeyguardManager keyguardManager = (KeyguardManager) this.reactContext.getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE); //api 16+
Expand Down Expand Up @@ -171,6 +175,7 @@ public String getCarrier() {
constants.put("timezone", TimeZone.getDefault().getID());
constants.put("isEmulator", this.isEmulator());
constants.put("isTablet", this.isTablet());
constants.put("is24Hour", this.is24Hour());
if (getCurrentActivity() != null &&
(getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED ||
getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED ||
Expand Down
1 change: 1 addition & 0 deletions deviceinfo.d.ts
Expand Up @@ -20,6 +20,7 @@ export function getTimezone(): string;
export function getInstanceID(): string;
export function isEmulator(): boolean;
export function isTablet(): boolean;
export function is24Hour(): boolean;
export function isPinOrFingerprintSet(): (cb: (isPinOrFingerprintSet: boolean) => void) => void;
export function getFirstInstallTime(): number;
export function getLastUpdateTime(): number;
Expand Down
5 changes: 4 additions & 1 deletion deviceinfo.js
Expand Up @@ -74,7 +74,10 @@ module.exports = {
isTablet: function() {
return RNDeviceInfo.isTablet;
},
isPinOrFingerprintSet: function() {
is24Hour: function() {
return RNDeviceInfo.is24Hour;
},
isPinOrFingerprintSet: function () {
return RNDeviceInfo.isPinOrFingerprintSet;
},
getFirstInstallTime: function() {
Expand Down
1 change: 1 addition & 0 deletions deviceinfo.js.flow
Expand Up @@ -19,6 +19,7 @@ declare module.exports: {
getTimezone: () => string,
isEmulator: () => boolean,
isTablet: () => boolean,
is24Hour: () => boolean,
isPinOrFingerprintSet: () => (cb: (isPinOrFingerprintSet: boolean) => void) => void,
getAPILevel: () => number,
getInstanceID: () => string,
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "react-native-device-info",
"version": "0.12.1",
"version": "0.12.2",
"description": "Get device information using react-native",
"main": "deviceinfo.js",
"typings": "./deviceinfo.d.ts",
Expand Down
7 changes: 6 additions & 1 deletion windows/RNDeviceInfo/RNDeviceInfoModule.cs
Expand Up @@ -7,7 +7,6 @@
using Windows.ApplicationModel;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using WinRTXamlToolkit.Controls;

namespace RNDeviceInfo
{
Expand Down Expand Up @@ -38,6 +37,11 @@ private bool IsTablet(string os)
return !rgx.IsMatch(os);
}

private bool is24Hour()
{
return DateTimeFormatInfo.CurrentInfo.ShortTimePattern.Contains("H");
}

public override IReadOnlyDictionary<string, object> Constants
{

Expand Down Expand Up @@ -113,6 +117,7 @@ private bool IsTablet(string os)
constants["isEmulator"] = IsEmulator(model);
constants["isTablet"] = IsTablet(os);
constants["carrier"] = "not available";
constants["is24Hour"] = is24Hour();

return constants;
}
Expand Down

0 comments on commit 444f5a7

Please sign in to comment.