Commit 5d7a8f0b authored by ezengsvmx's avatar ezengsvmx

Add 24 hour detection

parent 00b78754
......@@ -183,6 +183,12 @@ RCT_EXPORT_MODULE()
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];
......@@ -208,6 +214,7 @@ RCT_EXPORT_MODULE()
@"timezone": self.timezone,
@"isEmulator": @(self.isEmulator),
@"isTablet": @(self.isTablet),
@"is24Hour": @(self.is24Hour),
};
}
......
......@@ -89,6 +89,10 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
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+
......@@ -165,6 +169,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
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 ||
......
......@@ -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;
......
......@@ -74,6 +74,9 @@ module.exports = {
isTablet: function() {
return RNDeviceInfo.isTablet;
},
is24Hour: function() {
return RNDeviceInfo.is24Hour;
},
isPinOrFingerprintSet: function () {
return RNDeviceInfo.isPinOrFingerprintSet;
},
......
......@@ -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,
......
{
"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",
......
......@@ -37,6 +37,11 @@ namespace RNDeviceInfo
return !rgx.IsMatch(os);
}
private bool is24Hour()
{
return DateTimeFormatInfo.CurrentInfo.ShortTimePattern.Contains("H");
}
public override IReadOnlyDictionary<string, object> Constants
{
......@@ -111,6 +116,7 @@ namespace RNDeviceInfo
constants["timezone"] = TimeZoneInfo.Local.Id;
constants["isEmulator"] = IsEmulator(model);
constants["isTablet"] = IsTablet(os);
constants["is24Hour"] = is24Hour();
return constants;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment