react-native-timer-picker 1.5.4 → 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.
Files changed (29) hide show
  1. package/README.md +31 -20
  2. package/dist/commonjs/components/TimerPicker/DurationScroll.js +6 -3
  3. package/dist/commonjs/components/TimerPicker/DurationScroll.js.map +1 -1
  4. package/dist/commonjs/components/TimerPicker/TimerPicker.styles.js +4 -0
  5. package/dist/commonjs/components/TimerPicker/TimerPicker.styles.js.map +1 -1
  6. package/dist/commonjs/components/TimerPicker/index.js +21 -12
  7. package/dist/commonjs/components/TimerPicker/index.js.map +1 -1
  8. package/dist/commonjs/components/TimerPickerModal.styles.js.map +1 -1
  9. package/dist/commonjs/components/index.js +19 -25
  10. package/dist/commonjs/components/index.js.map +1 -1
  11. package/dist/module/components/TimerPicker/DurationScroll.js +6 -3
  12. package/dist/module/components/TimerPicker/DurationScroll.js.map +1 -1
  13. package/dist/module/components/TimerPicker/TimerPicker.styles.js +4 -0
  14. package/dist/module/components/TimerPicker/TimerPicker.styles.js.map +1 -1
  15. package/dist/module/components/TimerPicker/index.js +21 -12
  16. package/dist/module/components/TimerPicker/index.js.map +1 -1
  17. package/dist/module/components/TimerPickerModal.styles.js.map +1 -1
  18. package/dist/module/components/index.js +19 -25
  19. package/dist/module/components/index.js.map +1 -1
  20. package/dist/typescript/components/TimerPicker/DurationScroll.d.ts +1 -0
  21. package/dist/typescript/components/TimerPicker/TimerPicker.styles.d.ts +3092 -19
  22. package/dist/typescript/components/TimerPicker/index.d.ts +8 -3
  23. package/dist/typescript/components/TimerPickerModal.styles.d.ts +2190 -14
  24. package/package.json +1 -1
  25. package/src/components/TimerPicker/DurationScroll.tsx +13 -5
  26. package/src/components/TimerPicker/TimerPicker.styles.ts +16 -11
  27. package/src/components/TimerPicker/index.tsx +36 -15
  28. package/src/components/TimerPickerModal.styles.ts +8 -8
  29. package/src/components/index.tsx +26 -25
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "url": "https://github.com/troberts-28"
7
7
  },
8
8
  "license": "MIT",
9
- "version": "1.5.4",
9
+ "version": "1.7.0",
10
10
  "main": "dist/commonjs/index.js",
11
11
  "types": "dist/typescript/src/index.d.ts",
12
12
  "scripts": {
@@ -55,6 +55,7 @@ interface DurationScrollProps {
55
55
  onDurationChange: (duration: number) => void;
56
56
  padNumbersWithZero?: boolean;
57
57
  disableInfiniteScroll?: boolean;
58
+ isDisabled?: boolean;
58
59
  limit?: LimitType;
59
60
  aggressivelyGetLatestDuration: boolean;
60
61
  is12HourPicker?: boolean;
@@ -83,6 +84,7 @@ const DurationScroll = forwardRef<DurationScrollRef, DurationScrollProps>(
83
84
  padNumbersWithZero = false,
84
85
  disableInfiniteScroll = false,
85
86
  limit,
87
+ isDisabled,
86
88
  aggressivelyGetLatestDuration,
87
89
  allowFontScaling = false,
88
90
  is12HourPicker,
@@ -336,11 +338,16 @@ const DurationScroll = forwardRef<DurationScrollRef, DurationScrollProps>(
336
338
  return (
337
339
  <View
338
340
  testID={testID}
339
- style={{
340
- height:
341
- styles.pickerItemContainer.height * numberOfItemsToShow,
342
- overflow: "visible",
343
- }}>
341
+ pointerEvents={isDisabled ? "none" : undefined}
342
+ style={[
343
+ {
344
+ height:
345
+ styles.pickerItemContainer.height *
346
+ numberOfItemsToShow,
347
+ overflow: "visible",
348
+ },
349
+ isDisabled && styles.disabledPickerContainer,
350
+ ]}>
344
351
  <FlatList
345
352
  ref={flatListRef}
346
353
  data={data}
@@ -353,6 +360,7 @@ const DurationScroll = forwardRef<DurationScrollRef, DurationScrollProps>(
353
360
  decelerationRate={0.88}
354
361
  scrollEventThrottle={16}
355
362
  snapToAlignment="start"
363
+ scrollEnabled={!isDisabled}
356
364
  // used in place of snapToOffset due to bug on Android
357
365
  snapToOffsets={[...Array(data.length)].map(
358
366
  (_, i) => i * styles.pickerItemContainer.height
@@ -1,19 +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?: any;
8
- pickerContainer?: any;
9
- pickerLabelContainer?: any;
10
- pickerLabel?: any;
11
- pickerAmPmContainer?: any;
12
- pickerAmPmLabel?: any;
13
- pickerItemContainer?: any;
14
- pickerItem?: any;
15
- disabledPickerItem?: any;
16
- pickerGradientOverlay?: any;
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;
17
18
  }
18
19
 
19
20
  const DARK_MODE_BACKGROUND_COLOR = "#232323";
@@ -101,6 +102,10 @@ export const generateStyles = (
101
102
  ...customStyles?.pickerLabel,
102
103
  ...customStyles?.pickerAmPmLabel,
103
104
  },
105
+ disabledPickerContainer: {
106
+ opacity: 0.4,
107
+ ...customStyles?.disabledPickerContainer,
108
+ },
104
109
  disabledPickerItem: {
105
110
  opacity: 0.2,
106
111
  ...customStyles?.disabledPickerItem,
@@ -38,9 +38,11 @@ export interface TimerPickerProps {
38
38
  minutes: number;
39
39
  seconds: number;
40
40
  }) => void;
41
- initialHours?: number;
42
- initialMinutes?: number;
43
- initialSeconds?: number;
41
+ initialValue?: {
42
+ hours?: number;
43
+ minutes?: number;
44
+ seconds?: number;
45
+ };
44
46
  aggressivelyGetLatestDuration?: boolean;
45
47
  use12HourPicker?: boolean;
46
48
  amLabel?: string;
@@ -48,6 +50,9 @@ export interface TimerPickerProps {
48
50
  hideHours?: boolean;
49
51
  hideMinutes?: boolean;
50
52
  hideSeconds?: boolean;
53
+ hoursPickerIsDisabled?: boolean;
54
+ minutesPickerIsDisabled?: boolean;
55
+ secondsPickerIsDisabled?: boolean;
51
56
  hourLimit?: LimitType;
52
57
  minuteLimit?: LimitType;
53
58
  secondLimit?: LimitType;
@@ -70,12 +75,13 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
70
75
  {
71
76
  allowFontScaling = false,
72
77
  onDurationChange,
73
- initialHours = 0,
74
- initialMinutes = 0,
75
- initialSeconds = 0,
78
+ initialValue,
76
79
  hideHours = false,
77
80
  hideMinutes = false,
78
81
  hideSeconds = false,
82
+ hoursPickerIsDisabled = false,
83
+ minutesPickerIsDisabled = false,
84
+ secondsPickerIsDisabled = false,
79
85
  hourLimit,
80
86
  minuteLimit,
81
87
  secondLimit,
@@ -109,9 +115,21 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
109
115
  [checkedPadWithNItems, customStyles]
110
116
  );
111
117
 
112
- const [selectedHours, setSelectedHours] = useState(initialHours);
113
- const [selectedMinutes, setSelectedMinutes] = useState(initialMinutes);
114
- const [selectedSeconds, setSelectedSeconds] = useState(initialSeconds);
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
+ );
115
133
 
116
134
  useEffect(() => {
117
135
  onDurationChange?.({
@@ -128,9 +146,9 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
128
146
 
129
147
  useImperativeHandle(ref, () => ({
130
148
  reset: (options) => {
131
- setSelectedHours(initialHours);
132
- setSelectedMinutes(initialMinutes);
133
- setSelectedSeconds(initialSeconds);
149
+ setSelectedHours(safeInitialValue.hours);
150
+ setSelectedMinutes(safeInitialValue.minutes);
151
+ setSelectedSeconds(safeInitialValue.seconds);
134
152
  hoursDurationScrollRef.current?.reset(options);
135
153
  minutesDurationScrollRef.current?.reset(options);
136
154
  secondsDurationScrollRef.current?.reset(options);
@@ -168,7 +186,8 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
168
186
  label={
169
187
  hourLabel ?? (!use12HourPicker ? "h" : undefined)
170
188
  }
171
- initialValue={initialHours}
189
+ isDisabled={hoursPickerIsDisabled}
190
+ initialValue={safeInitialValue.hours}
172
191
  allowFontScaling={allowFontScaling}
173
192
  aggressivelyGetLatestDuration={
174
193
  aggressivelyGetLatestDuration
@@ -197,7 +216,8 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
197
216
  ref={minutesDurationScrollRef}
198
217
  numberOfItems={59}
199
218
  label={minuteLabel ?? "m"}
200
- initialValue={initialMinutes}
219
+ isDisabled={minutesPickerIsDisabled}
220
+ initialValue={safeInitialValue.minutes}
201
221
  allowFontScaling={allowFontScaling}
202
222
  aggressivelyGetLatestDuration={
203
223
  aggressivelyGetLatestDuration
@@ -224,7 +244,8 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
224
244
  ref={secondsDurationScrollRef}
225
245
  numberOfItems={59}
226
246
  label={secondLabel ?? "s"}
227
- initialValue={initialSeconds}
247
+ isDisabled={secondsPickerIsDisabled}
248
+ initialValue={safeInitialValue.seconds}
228
249
  allowFontScaling={allowFontScaling}
229
250
  aggressivelyGetLatestDuration={
230
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?: any;
8
- contentContainer?: any;
9
- buttonContainer?: any;
10
- button?: any;
11
- cancelButton?: any;
12
- confirmButton?: any;
13
- modalTitle?: any;
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";
@@ -70,12 +70,13 @@ const TimerPickerModal = forwardRef<TimerPickerModalRef, TimerPickerModalProps>(
70
70
  onCancel,
71
71
  onDurationChange,
72
72
  closeOnOverlayPress,
73
- initialHours = 0,
74
- initialMinutes = 0,
75
- initialSeconds = 0,
73
+ initialValue,
76
74
  hideHours = false,
77
75
  hideMinutes = false,
78
76
  hideSeconds = false,
77
+ hoursPickerIsDisabled = false,
78
+ minutesPickerIsDisabled = false,
79
+ secondsPickerIsDisabled = false,
79
80
  hourLimit,
80
81
  minuteLimit,
81
82
  secondLimit,
@@ -111,33 +112,32 @@ const TimerPickerModal = forwardRef<TimerPickerModalRef, TimerPickerModalProps>(
111
112
 
112
113
  const timerPickerRef = useRef<TimerPickerRef>(null);
113
114
 
114
- const [selectedDuration, setSelectedDuration] = useState({
115
- hours: initialHours,
116
- minutes: initialMinutes,
117
- seconds: initialSeconds,
118
- });
119
- const [confirmedDuration, setConfirmedDuration] = useState({
120
- hours: initialHours,
121
- minutes: initialMinutes,
122
- seconds: initialSeconds,
123
- });
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);
124
125
 
125
126
  const reset = (options?: { animated?: boolean }) => {
126
- const initialDuration = {
127
- hours: initialHours,
128
- minutes: initialMinutes,
129
- seconds: initialSeconds,
130
- };
131
- setSelectedDuration(initialDuration);
132
- setConfirmedDuration(initialDuration);
127
+ setSelectedDuration(safeInitialValue);
128
+ setConfirmedDuration(safeInitialValue);
133
129
  timerPickerRef.current?.reset(options);
134
130
  };
135
131
 
136
- // reset state if the initial times change
132
+ // reset state if the initial value changes
137
133
  useEffect(() => {
138
134
  reset();
139
135
  // eslint-disable-next-line react-hooks/exhaustive-deps
140
- }, [initialHours, initialMinutes, initialSeconds]);
136
+ }, [
137
+ safeInitialValue.hours,
138
+ safeInitialValue.minutes,
139
+ safeInitialValue.seconds,
140
+ ]);
141
141
 
142
142
  const hideModalHandler = () => {
143
143
  setSelectedDuration({
@@ -214,13 +214,14 @@ const TimerPickerModal = forwardRef<TimerPickerModalRef, TimerPickerModalProps>(
214
214
  <TimerPicker
215
215
  ref={timerPickerRef}
216
216
  onDurationChange={durationChangeHandler}
217
- initialHours={confirmedDuration.hours}
218
- initialMinutes={confirmedDuration.minutes}
219
- initialSeconds={confirmedDuration.seconds}
217
+ initialValue={confirmedDuration}
220
218
  aggressivelyGetLatestDuration={true}
221
219
  hideHours={hideHours}
222
220
  hideMinutes={hideMinutes}
223
221
  hideSeconds={hideSeconds}
222
+ hoursPickerIsDisabled={hoursPickerIsDisabled}
223
+ minutesPickerIsDisabled={minutesPickerIsDisabled}
224
+ secondsPickerIsDisabled={secondsPickerIsDisabled}
224
225
  hourLimit={hourLimit}
225
226
  minuteLimit={minuteLimit}
226
227
  secondLimit={secondLimit}