react-native-timer-picker 1.6.0 → 1.8.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 (121) hide show
  1. package/README.md +74 -25
  2. package/dist/commonjs/assets/select_click.mp3 +0 -0
  3. package/dist/commonjs/components/{TimerPicker/DurationScroll.js → DurationScroll/index.js} +113 -63
  4. package/dist/commonjs/components/DurationScroll/index.js.map +1 -0
  5. package/dist/commonjs/components/DurationScroll/types.js +6 -0
  6. package/dist/commonjs/components/DurationScroll/types.js.map +1 -0
  7. package/dist/commonjs/components/Modal/index.js +21 -20
  8. package/dist/commonjs/components/Modal/index.js.map +1 -1
  9. package/dist/commonjs/components/Modal/{Modal.styles.js → styles.js} +1 -1
  10. package/dist/commonjs/components/Modal/styles.js.map +1 -0
  11. package/dist/commonjs/components/Modal/types.js +6 -0
  12. package/dist/commonjs/components/Modal/types.js.map +1 -0
  13. package/dist/commonjs/components/TimerPicker/index.js +68 -79
  14. package/dist/commonjs/components/TimerPicker/index.js.map +1 -1
  15. package/dist/commonjs/components/TimerPicker/{TimerPicker.styles.js → styles.js} +1 -3
  16. package/dist/commonjs/components/TimerPicker/styles.js.map +1 -0
  17. package/dist/commonjs/components/TimerPicker/types.js +6 -0
  18. package/dist/commonjs/components/TimerPicker/types.js.map +1 -0
  19. package/dist/commonjs/components/{index.js → TimerPickerModal/index.js} +42 -99
  20. package/dist/commonjs/components/TimerPickerModal/index.js.map +1 -0
  21. package/dist/commonjs/components/{TimerPickerModal.styles.js → TimerPickerModal/styles.js} +1 -3
  22. package/dist/commonjs/components/TimerPickerModal/styles.js.map +1 -0
  23. package/dist/commonjs/components/TimerPickerModal/types.js +6 -0
  24. package/dist/commonjs/components/TimerPickerModal/types.js.map +1 -0
  25. package/dist/commonjs/index.js +14 -13
  26. package/dist/commonjs/index.js.map +1 -1
  27. package/dist/commonjs/tests/DurationScroll.test.js +1 -1
  28. package/dist/commonjs/tests/DurationScroll.test.js.map +1 -1
  29. package/dist/commonjs/tests/Modal.test.js +7 -7
  30. package/dist/commonjs/tests/Modal.test.js.map +1 -1
  31. package/dist/commonjs/tests/TimerPicker.test.js.map +1 -1
  32. package/dist/commonjs/tests/TimerPickerModal.test.js +2 -2
  33. package/dist/commonjs/tests/TimerPickerModal.test.js.map +1 -1
  34. package/dist/commonjs/utils/generateNumbers.js.map +1 -1
  35. package/dist/commonjs/utils/getAdjustedLimit.js.map +1 -1
  36. package/dist/commonjs/utils/getScrollIndex.js +2 -2
  37. package/dist/commonjs/utils/getScrollIndex.js.map +1 -1
  38. package/dist/module/assets/select_click.mp3 +0 -0
  39. package/dist/module/components/{TimerPicker/DurationScroll.js → DurationScroll/index.js} +114 -64
  40. package/dist/module/components/DurationScroll/index.js.map +1 -0
  41. package/dist/module/components/DurationScroll/types.js +2 -0
  42. package/dist/module/components/DurationScroll/types.js.map +1 -0
  43. package/dist/module/components/Modal/index.js +19 -19
  44. package/dist/module/components/Modal/index.js.map +1 -1
  45. package/dist/module/components/Modal/{Modal.styles.js → styles.js} +1 -1
  46. package/dist/module/components/Modal/styles.js.map +1 -0
  47. package/dist/module/components/Modal/types.js +2 -0
  48. package/dist/module/components/Modal/types.js.map +1 -0
  49. package/dist/module/components/TimerPicker/index.js +67 -78
  50. package/dist/module/components/TimerPicker/index.js.map +1 -1
  51. package/dist/module/components/TimerPicker/{TimerPicker.styles.js → styles.js} +1 -2
  52. package/dist/module/components/TimerPicker/styles.js.map +1 -0
  53. package/dist/module/components/TimerPicker/types.js +2 -0
  54. package/dist/module/components/TimerPicker/types.js.map +1 -0
  55. package/dist/module/components/{index.js → TimerPickerModal/index.js} +41 -98
  56. package/dist/module/components/TimerPickerModal/index.js.map +1 -0
  57. package/dist/module/components/{TimerPickerModal.styles.js → TimerPickerModal/styles.js} +1 -2
  58. package/dist/module/components/TimerPickerModal/styles.js.map +1 -0
  59. package/dist/module/components/TimerPickerModal/types.js +2 -0
  60. package/dist/module/components/TimerPickerModal/types.js.map +1 -0
  61. package/dist/module/index.js +6 -4
  62. package/dist/module/index.js.map +1 -1
  63. package/dist/module/tests/DurationScroll.test.js +1 -1
  64. package/dist/module/tests/DurationScroll.test.js.map +1 -1
  65. package/dist/module/tests/Modal.test.js +1 -1
  66. package/dist/module/tests/Modal.test.js.map +1 -1
  67. package/dist/module/tests/TimerPicker.test.js.map +1 -1
  68. package/dist/module/tests/TimerPickerModal.test.js +2 -2
  69. package/dist/module/tests/TimerPickerModal.test.js.map +1 -1
  70. package/dist/module/utils/generateNumbers.js.map +1 -1
  71. package/dist/module/utils/getAdjustedLimit.js.map +1 -1
  72. package/dist/module/utils/getScrollIndex.js +2 -2
  73. package/dist/module/utils/getScrollIndex.js.map +1 -1
  74. package/dist/typescript/components/DurationScroll/index.d.ts +4 -0
  75. package/dist/typescript/components/{TimerPicker/DurationScroll.d.ts → DurationScroll/types.d.ts} +36 -29
  76. package/dist/typescript/components/Modal/index.d.ts +3 -14
  77. package/dist/typescript/components/Modal/types.d.ts +15 -0
  78. package/dist/typescript/components/TimerPicker/index.d.ts +2 -57
  79. package/dist/typescript/components/TimerPicker/styles.d.ts +1022 -0
  80. package/dist/typescript/components/TimerPicker/types.d.ts +61 -0
  81. package/dist/typescript/components/TimerPickerModal/index.d.ts +4 -0
  82. package/dist/typescript/components/TimerPickerModal/styles.d.ts +738 -0
  83. package/dist/typescript/components/{index.d.ts → TimerPickerModal/types.d.ts} +24 -26
  84. package/dist/typescript/index.d.ts +6 -4
  85. package/dist/typescript/utils/generateNumbers.d.ts +4 -4
  86. package/dist/typescript/utils/getAdjustedLimit.d.ts +1 -1
  87. package/dist/typescript/utils/getScrollIndex.d.ts +2 -2
  88. package/package.json +14 -11
  89. package/src/assets/select_click.mp3 +0 -0
  90. package/src/components/{TimerPicker/DurationScroll.tsx → DurationScroll/index.tsx} +126 -110
  91. package/src/components/DurationScroll/types.ts +63 -0
  92. package/src/components/Modal/index.tsx +20 -30
  93. package/src/components/Modal/types.ts +17 -0
  94. package/src/components/TimerPicker/index.tsx +70 -138
  95. package/src/components/TimerPicker/{TimerPicker.styles.ts → styles.ts} +13 -13
  96. package/src/components/TimerPicker/types.ts +72 -0
  97. package/src/components/{index.tsx → TimerPickerModal/index.tsx} +44 -147
  98. package/src/components/{TimerPickerModal.styles.ts → TimerPickerModal/styles.ts} +9 -9
  99. package/src/components/TimerPickerModal/types.ts +52 -0
  100. package/src/index.ts +6 -7
  101. package/src/tests/DurationScroll.test.tsx +3 -1
  102. package/src/tests/Modal.test.tsx +3 -1
  103. package/src/tests/TimerPicker.test.tsx +2 -0
  104. package/src/tests/TimerPickerModal.test.tsx +3 -1
  105. package/src/utils/generateNumbers.ts +4 -4
  106. package/src/utils/getAdjustedLimit.ts +1 -1
  107. package/src/utils/getScrollIndex.ts +3 -3
  108. package/dist/commonjs/components/Modal/Modal.styles.js.map +0 -1
  109. package/dist/commonjs/components/TimerPicker/DurationScroll.js.map +0 -1
  110. package/dist/commonjs/components/TimerPicker/TimerPicker.styles.js.map +0 -1
  111. package/dist/commonjs/components/TimerPickerModal.styles.js.map +0 -1
  112. package/dist/commonjs/components/index.js.map +0 -1
  113. package/dist/module/components/Modal/Modal.styles.js.map +0 -1
  114. package/dist/module/components/TimerPicker/DurationScroll.js.map +0 -1
  115. package/dist/module/components/TimerPicker/TimerPicker.styles.js.map +0 -1
  116. package/dist/module/components/TimerPickerModal.styles.js.map +0 -1
  117. package/dist/module/components/index.js.map +0 -1
  118. package/dist/typescript/components/TimerPicker/TimerPicker.styles.d.ts +0 -29
  119. package/dist/typescript/components/TimerPickerModal.styles.d.ts +0 -19
  120. /package/dist/typescript/components/Modal/{Modal.styles.d.ts → styles.d.ts} +0 -0
  121. /package/src/components/Modal/{Modal.styles.ts → styles.ts} +0 -0
@@ -0,0 +1,17 @@
1
+ import type { ComponentProps } from "react";
2
+
3
+ import type { ViewStyle } from "react-native";
4
+ import type { Modal as ReactNativeModal } from "react-native";
5
+
6
+ export interface ModalProps {
7
+ animationDuration?: number;
8
+ children?: React.ReactElement;
9
+ contentStyle?: ViewStyle;
10
+ isVisible?: boolean;
11
+ modalProps?: ComponentProps<typeof ReactNativeModal>;
12
+ onHide?: () => void;
13
+ onOverlayPress?: () => void;
14
+ overlayOpacity?: number;
15
+ overlayStyle?: ViewStyle;
16
+ testID?: string;
17
+ }
@@ -1,5 +1,4 @@
1
1
  import React, {
2
- MutableRefObject,
3
2
  forwardRef,
4
3
  useEffect,
5
4
  useImperativeHandle,
@@ -7,102 +6,44 @@ import React, {
7
6
  useRef,
8
7
  useState,
9
8
  } from "react";
10
- import { View } from "react-native";
11
-
12
- import DurationScroll, { DurationScrollRef, LimitType } from "./DurationScroll";
13
9
 
14
- import { generateStyles, CustomTimerPickerStyles } from "./TimerPicker.styles";
15
- import { LinearGradientProps } from "./DurationScroll";
10
+ import { View } from "react-native";
16
11
 
17
- export interface TimerPickerRef {
18
- reset: (options?: { animated?: boolean }) => void;
19
- setValue: (
20
- value: {
21
- hours: number;
22
- minutes: number;
23
- seconds: number;
24
- },
25
- options?: { animated?: boolean }
26
- ) => void;
27
- latestDuration: {
28
- hours: MutableRefObject<number> | undefined;
29
- minutes: MutableRefObject<number> | undefined;
30
- seconds: MutableRefObject<number> | undefined;
31
- };
32
- }
12
+ import DurationScroll from "../DurationScroll";
13
+ import type { DurationScrollRef } from "../DurationScroll/types";
33
14
 
34
- export interface TimerPickerProps {
35
- allowFontScaling?: boolean;
36
- onDurationChange?: (duration: {
37
- hours: number;
38
- minutes: number;
39
- seconds: number;
40
- }) => void;
41
- initialHours?: number;
42
- initialMinutes?: number;
43
- initialSeconds?: number;
44
- aggressivelyGetLatestDuration?: boolean;
45
- use12HourPicker?: boolean;
46
- amLabel?: string;
47
- pmLabel?: string;
48
- hideHours?: boolean;
49
- hideMinutes?: boolean;
50
- hideSeconds?: boolean;
51
- hoursPickerIsDisabled?: boolean;
52
- minutesPickerIsDisabled?: boolean;
53
- secondsPickerIsDisabled?: boolean;
54
- hourLimit?: LimitType;
55
- minuteLimit?: LimitType;
56
- secondLimit?: LimitType;
57
- hourLabel?: string | React.ReactElement;
58
- minuteLabel?: string | React.ReactElement;
59
- secondLabel?: string | React.ReactElement;
60
- padWithNItems?: number;
61
- disableInfiniteScroll?: boolean;
62
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
- LinearGradient?: any;
64
- pickerContainerProps?: React.ComponentProps<typeof View>;
65
- pickerGradientOverlayProps?: Partial<LinearGradientProps>;
66
- topPickerGradientOverlayProps?: Partial<LinearGradientProps>;
67
- bottomPickerGradientOverlayProps?: Partial<LinearGradientProps>;
68
- styles?: CustomTimerPickerStyles;
69
- }
15
+ import { generateStyles } from "./styles";
16
+ import type { TimerPickerProps, TimerPickerRef } from "./types";
70
17
 
71
18
  const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
72
- (
73
- {
19
+ (props, ref) => {
20
+ const {
21
+ aggressivelyGetLatestDuration = false,
74
22
  allowFontScaling = false,
75
- onDurationChange,
76
- initialHours = 0,
77
- initialMinutes = 0,
78
- initialSeconds = 0,
23
+ amLabel = "am",
24
+ disableInfiniteScroll = false,
79
25
  hideHours = false,
80
26
  hideMinutes = false,
81
27
  hideSeconds = false,
82
- hoursPickerIsDisabled = false,
83
- minutesPickerIsDisabled = false,
84
- secondsPickerIsDisabled = false,
85
- hourLimit,
86
- minuteLimit,
87
- secondLimit,
88
28
  hourLabel,
29
+ hourLimit,
30
+ hoursPickerIsDisabled = false,
31
+ initialValue,
89
32
  minuteLabel,
90
- secondLabel,
33
+ minuteLimit,
34
+ minutesPickerIsDisabled = false,
35
+ onDurationChange,
91
36
  padWithNItems = 1,
92
- disableInfiniteScroll = false,
93
- aggressivelyGetLatestDuration = false,
94
- use12HourPicker = false,
95
- amLabel = "am",
96
- pmLabel = "pm",
97
- LinearGradient,
98
37
  pickerContainerProps,
99
- pickerGradientOverlayProps,
100
- topPickerGradientOverlayProps,
101
- bottomPickerGradientOverlayProps,
38
+ pmLabel = "pm",
39
+ secondLabel,
40
+ secondLimit,
41
+ secondsPickerIsDisabled = false,
102
42
  styles: customStyles,
103
- },
104
- ref
105
- ): React.ReactElement => {
43
+ use12HourPicker = false,
44
+ ...otherProps
45
+ } = props;
46
+
106
47
  const checkedPadWithNItems =
107
48
  padWithNItems >= 0 ? Math.round(padWithNItems) : 0;
108
49
 
@@ -115,9 +56,21 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
115
56
  [checkedPadWithNItems, customStyles]
116
57
  );
117
58
 
118
- const [selectedHours, setSelectedHours] = useState(initialHours);
119
- const [selectedMinutes, setSelectedMinutes] = useState(initialMinutes);
120
- const [selectedSeconds, setSelectedSeconds] = useState(initialSeconds);
59
+ const safeInitialValue = {
60
+ hours: initialValue?.hours ?? 0,
61
+ minutes: initialValue?.minutes ?? 0,
62
+ seconds: initialValue?.seconds ?? 0,
63
+ };
64
+
65
+ const [selectedHours, setSelectedHours] = useState(
66
+ safeInitialValue.hours
67
+ );
68
+ const [selectedMinutes, setSelectedMinutes] = useState(
69
+ safeInitialValue.minutes
70
+ );
71
+ const [selectedSeconds, setSelectedSeconds] = useState(
72
+ safeInitialValue.seconds
73
+ );
121
74
 
122
75
  useEffect(() => {
123
76
  onDurationChange?.({
@@ -134,9 +87,9 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
134
87
 
135
88
  useImperativeHandle(ref, () => ({
136
89
  reset: (options) => {
137
- setSelectedHours(initialHours);
138
- setSelectedMinutes(initialMinutes);
139
- setSelectedSeconds(initialSeconds);
90
+ setSelectedHours(safeInitialValue.hours);
91
+ setSelectedMinutes(safeInitialValue.minutes);
92
+ setSelectedSeconds(safeInitialValue.seconds);
140
93
  hoursDurationScrollRef.current?.reset(options);
141
94
  minutesDurationScrollRef.current?.reset(options);
142
95
  secondsDurationScrollRef.current?.reset(options);
@@ -170,89 +123,68 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
170
123
  {!hideHours ? (
171
124
  <DurationScroll
172
125
  ref={hoursDurationScrollRef}
173
- numberOfItems={23}
174
- label={
175
- hourLabel ?? (!use12HourPicker ? "h" : undefined)
176
- }
177
- isDisabled={hoursPickerIsDisabled}
178
- initialValue={initialHours}
179
- allowFontScaling={allowFontScaling}
180
126
  aggressivelyGetLatestDuration={
181
127
  aggressivelyGetLatestDuration
182
128
  }
183
- onDurationChange={setSelectedHours}
184
- pickerGradientOverlayProps={pickerGradientOverlayProps}
185
- topPickerGradientOverlayProps={
186
- topPickerGradientOverlayProps
187
- }
188
- bottomPickerGradientOverlayProps={
189
- bottomPickerGradientOverlayProps
190
- }
129
+ allowFontScaling={allowFontScaling}
130
+ amLabel={amLabel}
191
131
  disableInfiniteScroll={disableInfiniteScroll}
192
- padWithNItems={checkedPadWithNItems}
193
- limit={hourLimit}
194
- LinearGradient={LinearGradient}
132
+ initialValue={safeInitialValue.hours}
195
133
  is12HourPicker={use12HourPicker}
196
- amLabel={amLabel}
134
+ isDisabled={hoursPickerIsDisabled}
135
+ label={
136
+ hourLabel ?? (!use12HourPicker ? "h" : undefined)
137
+ }
138
+ limit={hourLimit}
139
+ numberOfItems={23}
140
+ onDurationChange={setSelectedHours}
141
+ padWithNItems={checkedPadWithNItems}
197
142
  pmLabel={pmLabel}
198
143
  styles={styles}
199
144
  testID="duration-scroll-hour"
145
+ {...otherProps}
200
146
  />
201
147
  ) : null}
202
148
  {!hideMinutes ? (
203
149
  <DurationScroll
204
150
  ref={minutesDurationScrollRef}
205
- numberOfItems={59}
206
- label={minuteLabel ?? "m"}
207
- isDisabled={minutesPickerIsDisabled}
208
- initialValue={initialMinutes}
209
- allowFontScaling={allowFontScaling}
210
151
  aggressivelyGetLatestDuration={
211
152
  aggressivelyGetLatestDuration
212
153
  }
154
+ allowFontScaling={allowFontScaling}
155
+ disableInfiniteScroll={disableInfiniteScroll}
156
+ initialValue={safeInitialValue.minutes}
157
+ isDisabled={minutesPickerIsDisabled}
158
+ label={minuteLabel ?? "m"}
159
+ limit={minuteLimit}
160
+ numberOfItems={59}
213
161
  onDurationChange={setSelectedMinutes}
214
162
  padNumbersWithZero
215
- pickerGradientOverlayProps={pickerGradientOverlayProps}
216
- topPickerGradientOverlayProps={
217
- topPickerGradientOverlayProps
218
- }
219
- bottomPickerGradientOverlayProps={
220
- bottomPickerGradientOverlayProps
221
- }
222
- disableInfiniteScroll={disableInfiniteScroll}
223
163
  padWithNItems={checkedPadWithNItems}
224
- limit={minuteLimit}
225
- LinearGradient={LinearGradient}
226
164
  styles={styles}
227
165
  testID="duration-scroll-minute"
166
+ {...otherProps}
228
167
  />
229
168
  ) : null}
230
169
  {!hideSeconds ? (
231
170
  <DurationScroll
232
171
  ref={secondsDurationScrollRef}
233
- numberOfItems={59}
234
- label={secondLabel ?? "s"}
235
- isDisabled={secondsPickerIsDisabled}
236
- initialValue={initialSeconds}
237
- allowFontScaling={allowFontScaling}
238
172
  aggressivelyGetLatestDuration={
239
173
  aggressivelyGetLatestDuration
240
174
  }
175
+ allowFontScaling={allowFontScaling}
176
+ disableInfiniteScroll={disableInfiniteScroll}
177
+ initialValue={safeInitialValue.seconds}
178
+ isDisabled={secondsPickerIsDisabled}
179
+ label={secondLabel ?? "s"}
180
+ limit={secondLimit}
181
+ numberOfItems={59}
241
182
  onDurationChange={setSelectedSeconds}
242
183
  padNumbersWithZero
243
- pickerGradientOverlayProps={pickerGradientOverlayProps}
244
- topPickerGradientOverlayProps={
245
- topPickerGradientOverlayProps
246
- }
247
- bottomPickerGradientOverlayProps={
248
- bottomPickerGradientOverlayProps
249
- }
250
- disableInfiniteScroll={disableInfiniteScroll}
251
184
  padWithNItems={checkedPadWithNItems}
252
- limit={secondLimit}
253
- LinearGradient={LinearGradient}
254
185
  styles={styles}
255
186
  testID="duration-scroll-second"
187
+ {...otherProps}
256
188
  />
257
189
  ) : null}
258
190
  </View>
@@ -1,20 +1,20 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
1
  import { StyleSheet } from "react-native";
2
+ import type { TextStyle, ViewStyle } from "react-native";
3
3
 
4
4
  export interface CustomTimerPickerStyles {
5
- theme?: "light" | "dark";
6
5
  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
- disabledPickerContainer?: any;
16
- disabledPickerItem?: any;
17
- pickerGradientOverlay?: any;
6
+ disabledPickerContainer?: ViewStyle;
7
+ disabledPickerItem?: TextStyle;
8
+ pickerAmPmContainer?: ViewStyle;
9
+ pickerAmPmLabel?: TextStyle;
10
+ pickerContainer?: ViewStyle & { backgroundColor?: string };
11
+ pickerGradientOverlay?: ViewStyle;
12
+ pickerItem?: TextStyle;
13
+ pickerItemContainer?: ViewStyle & { height?: number };
14
+ pickerLabel?: TextStyle;
15
+ pickerLabelContainer?: ViewStyle;
16
+ text?: TextStyle;
17
+ theme?: "light" | "dark";
18
18
  }
19
19
 
20
20
  const DARK_MODE_BACKGROUND_COLOR = "#232323";
@@ -0,0 +1,72 @@
1
+ import type { MutableRefObject } from "react";
2
+
3
+ import type { View } from "react-native";
4
+
5
+ import type {
6
+ LinearGradientProps,
7
+ SoundAssetType,
8
+ LimitType,
9
+ } from "../DurationScroll/types";
10
+
11
+ import type { CustomTimerPickerStyles } from "./styles";
12
+
13
+ export interface TimerPickerRef {
14
+ latestDuration: {
15
+ hours: MutableRefObject<number> | undefined;
16
+ minutes: MutableRefObject<number> | undefined;
17
+ seconds: MutableRefObject<number> | undefined;
18
+ };
19
+ reset: (options?: { animated?: boolean }) => void;
20
+ setValue: (
21
+ value: {
22
+ hours: number;
23
+ minutes: number;
24
+ seconds: number;
25
+ },
26
+ options?: { animated?: boolean }
27
+ ) => void;
28
+ }
29
+
30
+ export interface TimerPickerProps {
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
+ Audio?: any;
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ Haptics?: any;
35
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
+ LinearGradient?: any;
37
+ aggressivelyGetLatestDuration?: boolean;
38
+ allowFontScaling?: boolean;
39
+ amLabel?: string;
40
+ bottomPickerGradientOverlayProps?: Partial<LinearGradientProps>;
41
+ clickSoundAsset?: SoundAssetType;
42
+ disableInfiniteScroll?: boolean;
43
+ hideHours?: boolean;
44
+ hideMinutes?: boolean;
45
+ hideSeconds?: boolean;
46
+ hourLabel?: string | React.ReactElement;
47
+ hourLimit?: LimitType;
48
+ hoursPickerIsDisabled?: boolean;
49
+ initialValue?: {
50
+ hours?: number;
51
+ minutes?: number;
52
+ seconds?: number;
53
+ };
54
+ minuteLabel?: string | React.ReactElement;
55
+ minuteLimit?: LimitType;
56
+ minutesPickerIsDisabled?: boolean;
57
+ onDurationChange?: (duration: {
58
+ hours: number;
59
+ minutes: number;
60
+ seconds: number;
61
+ }) => void;
62
+ padWithNItems?: number;
63
+ pickerContainerProps?: React.ComponentProps<typeof View>;
64
+ pickerGradientOverlayProps?: Partial<LinearGradientProps>;
65
+ pmLabel?: string;
66
+ secondLabel?: string | React.ReactElement;
67
+ secondLimit?: LimitType;
68
+ secondsPickerIsDisabled?: boolean;
69
+ styles?: CustomTimerPickerStyles;
70
+ topPickerGradientOverlayProps?: Partial<LinearGradientProps>;
71
+ use12HourPicker?: boolean;
72
+ }
@@ -1,5 +1,4 @@
1
1
  import React, {
2
- MutableRefObject,
3
2
  forwardRef,
4
3
  useCallback,
5
4
  useEffect,
@@ -7,140 +6,70 @@ import React, {
7
6
  useRef,
8
7
  useState,
9
8
  } from "react";
10
- import { View, Text, TouchableOpacity } from "react-native";
11
-
12
- import TimerPicker, { TimerPickerProps, TimerPickerRef } from "./TimerPicker";
13
- import Modal from "./Modal";
14
9
 
15
- import {
16
- generateStyles,
17
- CustomTimerPickerModalStyles,
18
- } from "./TimerPickerModal.styles";
10
+ import { View, Text, TouchableOpacity } from "react-native";
19
11
 
20
- export interface TimerPickerModalRef {
21
- reset: (options?: { animated?: boolean }) => void;
22
- setValue: (
23
- value: {
24
- hours: number;
25
- minutes: number;
26
- seconds: number;
27
- },
28
- options?: { animated?: boolean }
29
- ) => void;
30
- latestDuration: {
31
- hours: MutableRefObject<number> | undefined;
32
- minutes: MutableRefObject<number> | undefined;
33
- seconds: MutableRefObject<number> | undefined;
34
- };
35
- }
12
+ import Modal from "../Modal";
13
+ import TimerPicker from "../TimerPicker";
14
+ import type { TimerPickerRef } from "../TimerPicker/types";
36
15
 
37
- export interface TimerPickerModalProps extends TimerPickerProps {
38
- visible: boolean;
39
- setIsVisible: (isVisible: boolean) => void;
40
- onConfirm: ({
41
- hours,
42
- minutes,
43
- seconds,
44
- }: {
45
- hours: number;
46
- minutes: number;
47
- seconds: number;
48
- }) => void;
49
- onCancel?: () => void;
50
- closeOnOverlayPress?: boolean;
51
- hideCancelButton?: boolean;
52
- confirmButtonText?: string;
53
- cancelButtonText?: string;
54
- modalTitle?: string;
55
- modalProps?: React.ComponentProps<typeof Modal>;
56
- containerProps?: React.ComponentProps<typeof View>;
57
- contentContainerProps?: React.ComponentProps<typeof View>;
58
- buttonContainerProps?: React.ComponentProps<typeof View>;
59
- buttonTouchableOpacityProps?: React.ComponentProps<typeof TouchableOpacity>;
60
- modalTitleProps?: React.ComponentProps<typeof Text>;
61
- styles?: CustomTimerPickerModalStyles;
62
- }
16
+ import { generateStyles } from "./styles";
17
+ import type { TimerPickerModalRef, TimerPickerModalProps } from "./types";
63
18
 
64
19
  const TimerPickerModal = forwardRef<TimerPickerModalRef, TimerPickerModalProps>(
65
- (
66
- {
67
- visible,
68
- setIsVisible,
69
- onConfirm,
70
- onCancel,
71
- onDurationChange,
20
+ (props, ref) => {
21
+ const {
22
+ buttonContainerProps,
23
+ buttonTouchableOpacityProps,
24
+ cancelButtonText,
72
25
  closeOnOverlayPress,
73
- initialHours = 0,
74
- initialMinutes = 0,
75
- initialSeconds = 0,
76
- hideHours = false,
77
- hideMinutes = false,
78
- hideSeconds = false,
79
- hoursPickerIsDisabled = false,
80
- minutesPickerIsDisabled = false,
81
- secondsPickerIsDisabled = false,
82
- hourLimit,
83
- minuteLimit,
84
- secondLimit,
85
- hourLabel,
86
- minuteLabel,
87
- secondLabel,
88
- padWithNItems = 1,
89
- disableInfiniteScroll = false,
90
- allowFontScaling = false,
91
- use12HourPicker,
92
- amLabel,
93
- pmLabel,
94
- hideCancelButton = false,
95
- confirmButtonText = "Confirm",
96
- cancelButtonText = "Cancel",
97
- modalTitle,
98
- LinearGradient,
99
- modalProps,
26
+ confirmButtonText,
100
27
  containerProps,
101
28
  contentContainerProps,
102
- pickerContainerProps,
103
- buttonContainerProps,
104
- buttonTouchableOpacityProps,
29
+ hideCancelButton,
30
+ initialValue,
31
+ modalProps,
32
+ modalTitle,
105
33
  modalTitleProps,
106
- pickerGradientOverlayProps,
107
- topPickerGradientOverlayProps,
108
- bottomPickerGradientOverlayProps,
34
+ onCancel,
35
+ onConfirm,
36
+ onDurationChange,
37
+ setIsVisible,
109
38
  styles: customStyles,
110
- },
111
- ref
112
- ): React.ReactElement => {
39
+ visible,
40
+ ...otherProps
41
+ } = props;
42
+
113
43
  const styles = generateStyles(customStyles);
114
44
 
115
45
  const timerPickerRef = useRef<TimerPickerRef>(null);
116
46
 
117
- const [selectedDuration, setSelectedDuration] = useState({
118
- hours: initialHours,
119
- minutes: initialMinutes,
120
- seconds: initialSeconds,
121
- });
122
- const [confirmedDuration, setConfirmedDuration] = useState({
123
- hours: initialHours,
124
- minutes: initialMinutes,
125
- seconds: initialSeconds,
126
- });
47
+ const safeInitialValue = {
48
+ hours: initialValue?.hours ?? 0,
49
+ minutes: initialValue?.minutes ?? 0,
50
+ seconds: initialValue?.seconds ?? 0,
51
+ };
52
+
53
+ const [selectedDuration, setSelectedDuration] =
54
+ useState(safeInitialValue);
55
+ const [confirmedDuration, setConfirmedDuration] =
56
+ useState(safeInitialValue);
127
57
 
128
58
  const reset = (options?: { animated?: boolean }) => {
129
- const initialDuration = {
130
- hours: initialHours,
131
- minutes: initialMinutes,
132
- seconds: initialSeconds,
133
- };
134
- setSelectedDuration(initialDuration);
135
- setConfirmedDuration(initialDuration);
59
+ setSelectedDuration(safeInitialValue);
60
+ setConfirmedDuration(safeInitialValue);
136
61
  timerPickerRef.current?.reset(options);
137
62
  };
138
63
 
139
- // reset state if the initial times change
64
+ // reset state if the initial value changes
140
65
  useEffect(() => {
141
66
  reset();
142
67
  // eslint-disable-next-line react-hooks/exhaustive-deps
143
- }, [initialHours, initialMinutes, initialSeconds]);
68
+ }, [
69
+ safeInitialValue.hours,
70
+ safeInitialValue.minutes,
71
+ safeInitialValue.seconds,
72
+ ]);
144
73
 
145
74
  const hideModalHandler = () => {
146
75
  setSelectedDuration({
@@ -216,41 +145,9 @@ const TimerPickerModal = forwardRef<TimerPickerModalRef, TimerPickerModalProps>(
216
145
  ) : null}
217
146
  <TimerPicker
218
147
  ref={timerPickerRef}
148
+ initialValue={confirmedDuration}
149
+ {...otherProps}
219
150
  onDurationChange={durationChangeHandler}
220
- initialHours={confirmedDuration.hours}
221
- initialMinutes={confirmedDuration.minutes}
222
- initialSeconds={confirmedDuration.seconds}
223
- aggressivelyGetLatestDuration={true}
224
- hideHours={hideHours}
225
- hideMinutes={hideMinutes}
226
- hideSeconds={hideSeconds}
227
- hoursPickerIsDisabled={hoursPickerIsDisabled}
228
- minutesPickerIsDisabled={minutesPickerIsDisabled}
229
- secondsPickerIsDisabled={secondsPickerIsDisabled}
230
- hourLimit={hourLimit}
231
- minuteLimit={minuteLimit}
232
- secondLimit={secondLimit}
233
- hourLabel={hourLabel}
234
- minuteLabel={minuteLabel}
235
- secondLabel={secondLabel}
236
- padWithNItems={padWithNItems}
237
- disableInfiniteScroll={disableInfiniteScroll}
238
- allowFontScaling={allowFontScaling}
239
- use12HourPicker={use12HourPicker}
240
- amLabel={amLabel}
241
- pmLabel={pmLabel}
242
- LinearGradient={LinearGradient}
243
- pickerContainerProps={pickerContainerProps}
244
- pickerGradientOverlayProps={
245
- pickerGradientOverlayProps
246
- }
247
- topPickerGradientOverlayProps={
248
- topPickerGradientOverlayProps
249
- }
250
- bottomPickerGradientOverlayProps={
251
- bottomPickerGradientOverlayProps
252
- }
253
- styles={customStyles}
254
151
  />
255
152
  <View
256
153
  {...buttonContainerProps}
@@ -1,16 +1,16 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
1
  import { StyleSheet } from "react-native";
2
+ import type { TextStyle, ViewStyle } from "react-native";
3
3
 
4
- import type { CustomTimerPickerStyles } from "./TimerPicker/TimerPicker.styles";
4
+ import type { CustomTimerPickerStyles } from "../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
+ button?: TextStyle;
8
+ buttonContainer?: ViewStyle;
9
+ cancelButton?: TextStyle;
10
+ confirmButton?: TextStyle;
11
+ container?: ViewStyle;
12
+ contentContainer?: ViewStyle;
13
+ modalTitle?: TextStyle;
14
14
  }
15
15
 
16
16
  const DARK_MODE_BACKGROUND_COLOR = "#232323";