Skip to content

Commit

Permalink
fix: PR feedback - boolean return typing, use existing boolean-API na…
Browse files Browse the repository at this point in the history
…ming prefix
  • Loading branch information
mikehardy committed Sep 7, 2019
1 parent e062f0d commit f636e30
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 43 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ Returns `true` if the user prefers 24h clock format, `false` if he prefers 12h c
#### Method type

```ts
type uses24HourClock = () => boolean;
type uses24HourClock = () => Option<boolean>;
```

#### Usage example
Expand All @@ -267,38 +267,38 @@ console.log(RNLocalize.uses24HourClock());

---

### isAutoDateAndTime()
### usesAutoDateAndTime()

Tells if the automatic date & time setting is enabled on the phone. **Android only**

#### Method type

```ts
type isAutoDateAndTime = () => boolean;
type usesAutoDateAndTime = () => Option<boolean>;
```

#### Usage example

```js
console.log(RNLocalize.isAutoDateAndTime()); // true or false
console.log(RNLocalize.usesAutoDateAndTime()); // true or false
```

---

### isAutoTimeZone()
### usesAutoTimeZone()

Tells if the automatic time zone setting is enabled on the phone. **Android only**

#### Method type

```ts
type isAutoTimeZone = () => boolean;
type usesAutoTimeZone = () => Option<boolean>;
```

#### Usage example

```js
console.log(RNLocalize.isAutoTimeZone());
console.log(RNLocalize.usesAutoTimeZone());
```

---
Expand All @@ -310,7 +310,7 @@ Returns `true` if the user prefers metric measure system, `false` if he prefers
#### Method type

```ts
type usesMetricSystem = () => boolean;
type usesMetricSystem = () => Option<boolean>;
```

#### Usage example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,24 +198,24 @@ private WritableMap getNumberFormatSettings(Locale locale) {
return settings;
}

private boolean isAutoDateAndTime() {
boolean isAutoDateAndTime;
private boolean usesAutoDateAndTime() {
boolean usesAutoDateAndTime;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
isAutoDateAndTime = Settings.System.getInt(getReactApplicationContext().getContentResolver(),Settings.System.AUTO_TIME, 0) != 0;
usesAutoDateAndTime = Settings.System.getInt(getReactApplicationContext().getContentResolver(), Settings.System.AUTO_TIME, 0) != 0;
} else {
isAutoDateAndTime = Settings.Global.getInt(getReactApplicationContext().getContentResolver(),Settings.Global.AUTO_TIME, 0) != 0;
usesAutoDateAndTime = Settings.Global.getInt(getReactApplicationContext().getContentResolver(), Settings.Global.AUTO_TIME, 0) != 0;
}
return isAutoDateAndTime;
return usesAutoDateAndTime;
}

private boolean isAutoTimeZone() {
boolean isAutoTimeZone;
private boolean usesAutoTimeZone() {
boolean usesAutoTimeZone;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
isAutoTimeZone = Settings.System.getInt(getReactApplicationContext().getContentResolver(),Settings.System.AUTO_TIME_ZONE, 0) != 0;
usesAutoTimeZone = Settings.System.getInt(getReactApplicationContext().getContentResolver(), Settings.System.AUTO_TIME_ZONE, 0) != 0;
} else {
isAutoTimeZone = Settings.Global.getInt(getReactApplicationContext().getContentResolver(),Settings.Global.AUTO_TIME_ZONE, 0) != 0;
usesAutoTimeZone = Settings.Global.getInt(getReactApplicationContext().getContentResolver(), Settings.Global.AUTO_TIME_ZONE, 0) != 0;
}
return isAutoTimeZone;
return usesAutoTimeZone;
}

private WritableMap getExported() {
Expand Down Expand Up @@ -265,8 +265,8 @@ private WritableMap getExported() {
exported.putMap("numberFormatSettings", getNumberFormatSettings(currentLocale));
exported.putString("temperatureUnit", getTemperatureUnit(currentLocale));
exported.putString("timeZone", TimeZone.getDefault().getID());
exported.putBoolean("isAutoDateAndTime", isAutoDateAndTime());
exported.putBoolean("isAutoTimeZone", isAutoTimeZone());
exported.putBoolean("usesAutoDateAndTime", usesAutoDateAndTime());
exported.putBoolean("usesAutoTimeZone", usesAutoTimeZone());
exported.putBoolean("uses24HourClock", DateFormat.is24HourFormat(getReactApplicationContext()));
exported.putBoolean("usesMetricSystem", getUsesMetricSystem(currentLocale));

Expand Down
8 changes: 4 additions & 4 deletions example/src/AsyncExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ export default class AsyncExample extends React.Component {
value={RNLocalize.uses24HourClock()}
/>
<Line
name="RNLocalize.isAutoDateAndTime()"
value={RNLocalize.isAutoDateAndTime()}
name="RNLocalize.usesAutoDateAndTime()"
value={RNLocalize.usesAutoDateAndTime()}
/>
<Line
name="RNLocalize.isAutoTimeZone()"
value={RNLocalize.isAutoTimeZone()}
name="RNLocalize.usesAutoTimeZone()"
value={RNLocalize.usesAutoTimeZone()}
/>
<Line
name="RNLocalize.usesMetricSystem()"
Expand Down
8 changes: 4 additions & 4 deletions example/src/SyncExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ export default class SyncExample extends React.Component {
value={RNLocalize.uses24HourClock()}
/>
<Line
name="RNLocalize.isAutoDateAndTime()"
value={RNLocalize.isAutoDateAndTime()}
name="RNLocalize.usesAutoDateAndTime()"
value={RNLocalize.usesAutoDateAndTime()}
/>
<Line
name="RNLocalize.isAutoTimeZone()"
value={RNLocalize.isAutoTimeZone()}
name="RNLocalize.usesAutoTimeZone()"
value={RNLocalize.usesAutoTimeZone()}
/>
<Line
name="RNLocalize.usesMetricSystem()"
Expand Down
5 changes: 4 additions & 1 deletion example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3561,7 +3561,10 @@ [email protected]:
utf8 "^2.1.1"

"react-native-localize@file:..":
version "1.2.0"
version "1.1.4"

"react-native-localize@file:../":
version "1.1.4"

[email protected]:
version "0.60.0"
Expand Down
18 changes: 10 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,25 @@ declare module "react-native-localize" {
numberFormatSettings: NumberFormatSettings;
temperatureUnit: TemperatureUnit;
timeZone: string;
uses24HourClock: boolean;
isAutoDateAndTime: boolean;
isAutoTimeZone: boolean;
usesMetricSystem: boolean;
uses24HourClock: Option<boolean>;
usesAutoDateAndTime: Option<boolean>;
usesAutoTimeZone: Option<boolean>;
usesMetricSystem: Option<boolean>;
};

export type Option<T> = T | undefined;

export function getCalendar(): Calendar;
export function getCountry(): string;
export function getCurrencies(): string[];
export function getLocales(): Locale[];
export function getNumberFormatSettings(): NumberFormatSettings;
export function getTemperatureUnit(): TemperatureUnit;
export function getTimeZone(): string;
export function uses24HourClock(): boolean;
export function isAutoDateAndTime(): boolean;
export function isAutoTimeZone(): boolean;
export function usesMetricSystem(): boolean;
export function uses24HourClock(): Option<boolean>;
export function usesAutoDateAndTime(): Option<boolean>;
export function usesAutoTimeZone(): Option<boolean>;
export function usesMetricSystem(): Option<boolean>;

export function addEventListener(
type: LocalizationEvent,
Expand Down
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export type LocalizationConstants = {|
usesMetricSystem: boolean,
|};

export type Option<T> = T | boolean;

let constants: LocalizationConstants = RNLocalize.initialConstants;
const emitter = new NativeEventEmitter(RNLocalize);
const handlers: Set<Function> = new Set();
Expand Down Expand Up @@ -73,16 +75,16 @@ export function getTemperatureUnit(): TemperatureUnit {
export function getTimeZone(): string {
return constants.timeZone;
}
export function uses24HourClock(): boolean {
export function uses24HourClock(): Option<boolean> {
return constants.uses24HourClock;
}
export function isAutoDateAndTime(): boolean {
return constants.isAutoDateAndTime;
export function usesAutoDateAndTime(): Option<boolean> {
return constants.usesAutoDateAndTime;
}
export function isAutoTimeZone(): boolean {
return constants.isAutoTimeZone;
export function usesAutoTimeZone(): Option<boolean> {
return constants.usesAutoTimeZone;
}
export function usesMetricSystem(): boolean {
export function usesMetricSystem(): Option<boolean> {
return constants.usesMetricSystem;
}

Expand Down

0 comments on commit f636e30

Please sign in to comment.