react-native-timer-picker 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -8
- package/dist/commonjs/components/TimerPicker/TimerPicker.styles.js.map +1 -1
- package/dist/commonjs/components/TimerPicker/index.js +15 -12
- package/dist/commonjs/components/TimerPicker/index.js.map +1 -1
- package/dist/commonjs/components/TimerPickerModal.styles.js.map +1 -1
- package/dist/commonjs/components/index.js +13 -25
- package/dist/commonjs/components/index.js.map +1 -1
- package/dist/module/components/TimerPicker/TimerPicker.styles.js.map +1 -1
- package/dist/module/components/TimerPicker/index.js +15 -12
- package/dist/module/components/TimerPicker/index.js.map +1 -1
- package/dist/module/components/TimerPickerModal.styles.js.map +1 -1
- package/dist/module/components/index.js +13 -25
- package/dist/module/components/index.js.map +1 -1
- package/dist/typescript/components/TimerPicker/TimerPicker.styles.d.ts +3092 -21
- package/dist/typescript/components/TimerPicker/index.d.ts +5 -3
- package/dist/typescript/components/TimerPickerModal.styles.d.ts +2190 -14
- package/package.json +1 -1
- package/src/components/TimerPicker/TimerPicker.styles.ts +12 -12
- package/src/components/TimerPicker/index.tsx +27 -15
- package/src/components/TimerPickerModal.styles.ts +8 -8
- package/src/components/index.tsx +20 -25
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { StyleSheet } from "react-native";
|
|
2
|
+
import { StyleSheet, TextStyle, ViewStyle } from "react-native";
|
|
3
3
|
|
|
4
4
|
export interface CustomTimerPickerStyles {
|
|
5
5
|
theme?: "light" | "dark";
|
|
6
6
|
backgroundColor?: string;
|
|
7
|
-
text?:
|
|
8
|
-
pickerContainer?:
|
|
9
|
-
pickerLabelContainer?:
|
|
10
|
-
pickerLabel?:
|
|
11
|
-
pickerAmPmContainer?:
|
|
12
|
-
pickerAmPmLabel?:
|
|
13
|
-
pickerItemContainer?:
|
|
14
|
-
pickerItem?:
|
|
15
|
-
disabledPickerContainer?:
|
|
16
|
-
disabledPickerItem?:
|
|
17
|
-
pickerGradientOverlay?:
|
|
7
|
+
text?: TextStyle;
|
|
8
|
+
pickerContainer?: ViewStyle & { backgroundColor?: string };
|
|
9
|
+
pickerLabelContainer?: ViewStyle;
|
|
10
|
+
pickerLabel?: TextStyle;
|
|
11
|
+
pickerAmPmContainer?: ViewStyle;
|
|
12
|
+
pickerAmPmLabel?: TextStyle;
|
|
13
|
+
pickerItemContainer?: ViewStyle & { height?: number };
|
|
14
|
+
pickerItem?: TextStyle;
|
|
15
|
+
disabledPickerContainer?: ViewStyle;
|
|
16
|
+
disabledPickerItem?: TextStyle;
|
|
17
|
+
pickerGradientOverlay?: ViewStyle;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const DARK_MODE_BACKGROUND_COLOR = "#232323";
|
|
@@ -38,9 +38,11 @@ export interface TimerPickerProps {
|
|
|
38
38
|
minutes: number;
|
|
39
39
|
seconds: number;
|
|
40
40
|
}) => void;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
initialValue?: {
|
|
42
|
+
hours?: number;
|
|
43
|
+
minutes?: number;
|
|
44
|
+
seconds?: number;
|
|
45
|
+
};
|
|
44
46
|
aggressivelyGetLatestDuration?: boolean;
|
|
45
47
|
use12HourPicker?: boolean;
|
|
46
48
|
amLabel?: string;
|
|
@@ -73,9 +75,7 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
|
|
|
73
75
|
{
|
|
74
76
|
allowFontScaling = false,
|
|
75
77
|
onDurationChange,
|
|
76
|
-
|
|
77
|
-
initialMinutes = 0,
|
|
78
|
-
initialSeconds = 0,
|
|
78
|
+
initialValue,
|
|
79
79
|
hideHours = false,
|
|
80
80
|
hideMinutes = false,
|
|
81
81
|
hideSeconds = false,
|
|
@@ -115,9 +115,21 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
|
|
|
115
115
|
[checkedPadWithNItems, customStyles]
|
|
116
116
|
);
|
|
117
117
|
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
const safeInitialValue = {
|
|
119
|
+
hours: initialValue?.hours ?? 0,
|
|
120
|
+
minutes: initialValue?.minutes ?? 0,
|
|
121
|
+
seconds: initialValue?.seconds ?? 0,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const [selectedHours, setSelectedHours] = useState(
|
|
125
|
+
safeInitialValue.hours
|
|
126
|
+
);
|
|
127
|
+
const [selectedMinutes, setSelectedMinutes] = useState(
|
|
128
|
+
safeInitialValue.minutes
|
|
129
|
+
);
|
|
130
|
+
const [selectedSeconds, setSelectedSeconds] = useState(
|
|
131
|
+
safeInitialValue.seconds
|
|
132
|
+
);
|
|
121
133
|
|
|
122
134
|
useEffect(() => {
|
|
123
135
|
onDurationChange?.({
|
|
@@ -134,9 +146,9 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
|
|
|
134
146
|
|
|
135
147
|
useImperativeHandle(ref, () => ({
|
|
136
148
|
reset: (options) => {
|
|
137
|
-
setSelectedHours(
|
|
138
|
-
setSelectedMinutes(
|
|
139
|
-
setSelectedSeconds(
|
|
149
|
+
setSelectedHours(safeInitialValue.hours);
|
|
150
|
+
setSelectedMinutes(safeInitialValue.minutes);
|
|
151
|
+
setSelectedSeconds(safeInitialValue.seconds);
|
|
140
152
|
hoursDurationScrollRef.current?.reset(options);
|
|
141
153
|
minutesDurationScrollRef.current?.reset(options);
|
|
142
154
|
secondsDurationScrollRef.current?.reset(options);
|
|
@@ -175,7 +187,7 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
|
|
|
175
187
|
hourLabel ?? (!use12HourPicker ? "h" : undefined)
|
|
176
188
|
}
|
|
177
189
|
isDisabled={hoursPickerIsDisabled}
|
|
178
|
-
initialValue={
|
|
190
|
+
initialValue={safeInitialValue.hours}
|
|
179
191
|
allowFontScaling={allowFontScaling}
|
|
180
192
|
aggressivelyGetLatestDuration={
|
|
181
193
|
aggressivelyGetLatestDuration
|
|
@@ -205,7 +217,7 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
|
|
|
205
217
|
numberOfItems={59}
|
|
206
218
|
label={minuteLabel ?? "m"}
|
|
207
219
|
isDisabled={minutesPickerIsDisabled}
|
|
208
|
-
initialValue={
|
|
220
|
+
initialValue={safeInitialValue.minutes}
|
|
209
221
|
allowFontScaling={allowFontScaling}
|
|
210
222
|
aggressivelyGetLatestDuration={
|
|
211
223
|
aggressivelyGetLatestDuration
|
|
@@ -233,7 +245,7 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
|
|
|
233
245
|
numberOfItems={59}
|
|
234
246
|
label={secondLabel ?? "s"}
|
|
235
247
|
isDisabled={secondsPickerIsDisabled}
|
|
236
|
-
initialValue={
|
|
248
|
+
initialValue={safeInitialValue.seconds}
|
|
237
249
|
allowFontScaling={allowFontScaling}
|
|
238
250
|
aggressivelyGetLatestDuration={
|
|
239
251
|
aggressivelyGetLatestDuration
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { StyleSheet } from "react-native";
|
|
2
|
+
import { StyleSheet, TextStyle, ViewStyle } from "react-native";
|
|
3
3
|
|
|
4
4
|
import type { CustomTimerPickerStyles } from "./TimerPicker/TimerPicker.styles";
|
|
5
5
|
|
|
6
6
|
export interface CustomTimerPickerModalStyles extends CustomTimerPickerStyles {
|
|
7
|
-
container?:
|
|
8
|
-
contentContainer?:
|
|
9
|
-
buttonContainer?:
|
|
10
|
-
button?:
|
|
11
|
-
cancelButton?:
|
|
12
|
-
confirmButton?:
|
|
13
|
-
modalTitle?:
|
|
7
|
+
container?: ViewStyle;
|
|
8
|
+
contentContainer?: ViewStyle;
|
|
9
|
+
buttonContainer?: ViewStyle;
|
|
10
|
+
button?: TextStyle;
|
|
11
|
+
cancelButton?: TextStyle;
|
|
12
|
+
confirmButton?: TextStyle;
|
|
13
|
+
modalTitle?: TextStyle;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const DARK_MODE_BACKGROUND_COLOR = "#232323";
|
package/src/components/index.tsx
CHANGED
|
@@ -70,9 +70,7 @@ const TimerPickerModal = forwardRef<TimerPickerModalRef, TimerPickerModalProps>(
|
|
|
70
70
|
onCancel,
|
|
71
71
|
onDurationChange,
|
|
72
72
|
closeOnOverlayPress,
|
|
73
|
-
|
|
74
|
-
initialMinutes = 0,
|
|
75
|
-
initialSeconds = 0,
|
|
73
|
+
initialValue,
|
|
76
74
|
hideHours = false,
|
|
77
75
|
hideMinutes = false,
|
|
78
76
|
hideSeconds = false,
|
|
@@ -114,33 +112,32 @@ const TimerPickerModal = forwardRef<TimerPickerModalRef, TimerPickerModalProps>(
|
|
|
114
112
|
|
|
115
113
|
const timerPickerRef = useRef<TimerPickerRef>(null);
|
|
116
114
|
|
|
117
|
-
const
|
|
118
|
-
hours:
|
|
119
|
-
minutes:
|
|
120
|
-
seconds:
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
115
|
+
const safeInitialValue = {
|
|
116
|
+
hours: initialValue?.hours ?? 0,
|
|
117
|
+
minutes: initialValue?.minutes ?? 0,
|
|
118
|
+
seconds: initialValue?.seconds ?? 0,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const [selectedDuration, setSelectedDuration] =
|
|
122
|
+
useState(safeInitialValue);
|
|
123
|
+
const [confirmedDuration, setConfirmedDuration] =
|
|
124
|
+
useState(safeInitialValue);
|
|
127
125
|
|
|
128
126
|
const reset = (options?: { animated?: boolean }) => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
minutes: initialMinutes,
|
|
132
|
-
seconds: initialSeconds,
|
|
133
|
-
};
|
|
134
|
-
setSelectedDuration(initialDuration);
|
|
135
|
-
setConfirmedDuration(initialDuration);
|
|
127
|
+
setSelectedDuration(safeInitialValue);
|
|
128
|
+
setConfirmedDuration(safeInitialValue);
|
|
136
129
|
timerPickerRef.current?.reset(options);
|
|
137
130
|
};
|
|
138
131
|
|
|
139
|
-
// reset state if the initial
|
|
132
|
+
// reset state if the initial value changes
|
|
140
133
|
useEffect(() => {
|
|
141
134
|
reset();
|
|
142
135
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
143
|
-
}, [
|
|
136
|
+
}, [
|
|
137
|
+
safeInitialValue.hours,
|
|
138
|
+
safeInitialValue.minutes,
|
|
139
|
+
safeInitialValue.seconds,
|
|
140
|
+
]);
|
|
144
141
|
|
|
145
142
|
const hideModalHandler = () => {
|
|
146
143
|
setSelectedDuration({
|
|
@@ -217,9 +214,7 @@ const TimerPickerModal = forwardRef<TimerPickerModalRef, TimerPickerModalProps>(
|
|
|
217
214
|
<TimerPicker
|
|
218
215
|
ref={timerPickerRef}
|
|
219
216
|
onDurationChange={durationChangeHandler}
|
|
220
|
-
|
|
221
|
-
initialMinutes={confirmedDuration.minutes}
|
|
222
|
-
initialSeconds={confirmedDuration.seconds}
|
|
217
|
+
initialValue={confirmedDuration}
|
|
223
218
|
aggressivelyGetLatestDuration={true}
|
|
224
219
|
hideHours={hideHours}
|
|
225
220
|
hideMinutes={hideMinutes}
|