react-native-timer-picker 1.7.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 +65 -23
  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 +57 -71
  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} +31 -76
  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 +56 -70
  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} +30 -75
  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 -59
  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 +52 -132
  95. package/src/components/TimerPicker/{TimerPicker.styles.ts → styles.ts} +11 -11
  96. package/src/components/TimerPicker/types.ts +72 -0
  97. package/src/components/{index.tsx → TimerPickerModal/index.tsx} +26 -124
  98. package/src/components/{TimerPickerModal.styles.ts → TimerPickerModal/styles.ts} +6 -6
  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 -3100
  119. package/dist/typescript/components/TimerPickerModal.styles.d.ts +0 -2195
  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
- initialValue?: {
42
- hours?: number;
43
- minutes?: number;
44
- seconds?: number;
45
- };
46
- aggressivelyGetLatestDuration?: boolean;
47
- use12HourPicker?: boolean;
48
- amLabel?: string;
49
- pmLabel?: string;
50
- hideHours?: boolean;
51
- hideMinutes?: boolean;
52
- hideSeconds?: boolean;
53
- hoursPickerIsDisabled?: boolean;
54
- minutesPickerIsDisabled?: boolean;
55
- secondsPickerIsDisabled?: boolean;
56
- hourLimit?: LimitType;
57
- minuteLimit?: LimitType;
58
- secondLimit?: LimitType;
59
- hourLabel?: string | React.ReactElement;
60
- minuteLabel?: string | React.ReactElement;
61
- secondLabel?: string | React.ReactElement;
62
- padWithNItems?: number;
63
- disableInfiniteScroll?: boolean;
64
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
- LinearGradient?: any;
66
- pickerContainerProps?: React.ComponentProps<typeof View>;
67
- pickerGradientOverlayProps?: Partial<LinearGradientProps>;
68
- topPickerGradientOverlayProps?: Partial<LinearGradientProps>;
69
- bottomPickerGradientOverlayProps?: Partial<LinearGradientProps>;
70
- styles?: CustomTimerPickerStyles;
71
- }
15
+ import { generateStyles } from "./styles";
16
+ import type { TimerPickerProps, TimerPickerRef } from "./types";
72
17
 
73
18
  const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
74
- (
75
- {
19
+ (props, ref) => {
20
+ const {
21
+ aggressivelyGetLatestDuration = false,
76
22
  allowFontScaling = false,
77
- onDurationChange,
78
- initialValue,
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
 
@@ -182,89 +123,68 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
182
123
  {!hideHours ? (
183
124
  <DurationScroll
184
125
  ref={hoursDurationScrollRef}
185
- numberOfItems={23}
186
- label={
187
- hourLabel ?? (!use12HourPicker ? "h" : undefined)
188
- }
189
- isDisabled={hoursPickerIsDisabled}
190
- initialValue={safeInitialValue.hours}
191
- allowFontScaling={allowFontScaling}
192
126
  aggressivelyGetLatestDuration={
193
127
  aggressivelyGetLatestDuration
194
128
  }
195
- onDurationChange={setSelectedHours}
196
- pickerGradientOverlayProps={pickerGradientOverlayProps}
197
- topPickerGradientOverlayProps={
198
- topPickerGradientOverlayProps
199
- }
200
- bottomPickerGradientOverlayProps={
201
- bottomPickerGradientOverlayProps
202
- }
129
+ allowFontScaling={allowFontScaling}
130
+ amLabel={amLabel}
203
131
  disableInfiniteScroll={disableInfiniteScroll}
204
- padWithNItems={checkedPadWithNItems}
205
- limit={hourLimit}
206
- LinearGradient={LinearGradient}
132
+ initialValue={safeInitialValue.hours}
207
133
  is12HourPicker={use12HourPicker}
208
- 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}
209
142
  pmLabel={pmLabel}
210
143
  styles={styles}
211
144
  testID="duration-scroll-hour"
145
+ {...otherProps}
212
146
  />
213
147
  ) : null}
214
148
  {!hideMinutes ? (
215
149
  <DurationScroll
216
150
  ref={minutesDurationScrollRef}
217
- numberOfItems={59}
218
- label={minuteLabel ?? "m"}
219
- isDisabled={minutesPickerIsDisabled}
220
- initialValue={safeInitialValue.minutes}
221
- allowFontScaling={allowFontScaling}
222
151
  aggressivelyGetLatestDuration={
223
152
  aggressivelyGetLatestDuration
224
153
  }
154
+ allowFontScaling={allowFontScaling}
155
+ disableInfiniteScroll={disableInfiniteScroll}
156
+ initialValue={safeInitialValue.minutes}
157
+ isDisabled={minutesPickerIsDisabled}
158
+ label={minuteLabel ?? "m"}
159
+ limit={minuteLimit}
160
+ numberOfItems={59}
225
161
  onDurationChange={setSelectedMinutes}
226
162
  padNumbersWithZero
227
- pickerGradientOverlayProps={pickerGradientOverlayProps}
228
- topPickerGradientOverlayProps={
229
- topPickerGradientOverlayProps
230
- }
231
- bottomPickerGradientOverlayProps={
232
- bottomPickerGradientOverlayProps
233
- }
234
- disableInfiniteScroll={disableInfiniteScroll}
235
163
  padWithNItems={checkedPadWithNItems}
236
- limit={minuteLimit}
237
- LinearGradient={LinearGradient}
238
164
  styles={styles}
239
165
  testID="duration-scroll-minute"
166
+ {...otherProps}
240
167
  />
241
168
  ) : null}
242
169
  {!hideSeconds ? (
243
170
  <DurationScroll
244
171
  ref={secondsDurationScrollRef}
245
- numberOfItems={59}
246
- label={secondLabel ?? "s"}
247
- isDisabled={secondsPickerIsDisabled}
248
- initialValue={safeInitialValue.seconds}
249
- allowFontScaling={allowFontScaling}
250
172
  aggressivelyGetLatestDuration={
251
173
  aggressivelyGetLatestDuration
252
174
  }
175
+ allowFontScaling={allowFontScaling}
176
+ disableInfiniteScroll={disableInfiniteScroll}
177
+ initialValue={safeInitialValue.seconds}
178
+ isDisabled={secondsPickerIsDisabled}
179
+ label={secondLabel ?? "s"}
180
+ limit={secondLimit}
181
+ numberOfItems={59}
253
182
  onDurationChange={setSelectedSeconds}
254
183
  padNumbersWithZero
255
- pickerGradientOverlayProps={pickerGradientOverlayProps}
256
- topPickerGradientOverlayProps={
257
- topPickerGradientOverlayProps
258
- }
259
- bottomPickerGradientOverlayProps={
260
- bottomPickerGradientOverlayProps
261
- }
262
- disableInfiniteScroll={disableInfiniteScroll}
263
184
  padWithNItems={checkedPadWithNItems}
264
- limit={secondLimit}
265
- LinearGradient={LinearGradient}
266
185
  styles={styles}
267
186
  testID="duration-scroll-second"
187
+ {...otherProps}
268
188
  />
269
189
  ) : null}
270
190
  </View>
@@ -1,20 +1,20 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { StyleSheet, TextStyle, ViewStyle } from "react-native";
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?: 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
6
  disabledPickerContainer?: ViewStyle;
16
7
  disabledPickerItem?: TextStyle;
8
+ pickerAmPmContainer?: ViewStyle;
9
+ pickerAmPmLabel?: TextStyle;
10
+ pickerContainer?: ViewStyle & { backgroundColor?: string };
17
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,107 +6,40 @@ 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
- initialValue,
74
- hideHours = false,
75
- hideMinutes = false,
76
- hideSeconds = false,
77
- hoursPickerIsDisabled = false,
78
- minutesPickerIsDisabled = false,
79
- secondsPickerIsDisabled = false,
80
- hourLimit,
81
- minuteLimit,
82
- secondLimit,
83
- hourLabel,
84
- minuteLabel,
85
- secondLabel,
86
- padWithNItems = 1,
87
- disableInfiniteScroll = false,
88
- allowFontScaling = false,
89
- use12HourPicker,
90
- amLabel,
91
- pmLabel,
92
- hideCancelButton = false,
93
- confirmButtonText = "Confirm",
94
- cancelButtonText = "Cancel",
95
- modalTitle,
96
- LinearGradient,
97
- modalProps,
26
+ confirmButtonText,
98
27
  containerProps,
99
28
  contentContainerProps,
100
- pickerContainerProps,
101
- buttonContainerProps,
102
- buttonTouchableOpacityProps,
29
+ hideCancelButton,
30
+ initialValue,
31
+ modalProps,
32
+ modalTitle,
103
33
  modalTitleProps,
104
- pickerGradientOverlayProps,
105
- topPickerGradientOverlayProps,
106
- bottomPickerGradientOverlayProps,
34
+ onCancel,
35
+ onConfirm,
36
+ onDurationChange,
37
+ setIsVisible,
107
38
  styles: customStyles,
108
- },
109
- ref
110
- ): React.ReactElement => {
39
+ visible,
40
+ ...otherProps
41
+ } = props;
42
+
111
43
  const styles = generateStyles(customStyles);
112
44
 
113
45
  const timerPickerRef = useRef<TimerPickerRef>(null);
@@ -213,39 +145,9 @@ const TimerPickerModal = forwardRef<TimerPickerModalRef, TimerPickerModalProps>(
213
145
  ) : null}
214
146
  <TimerPicker
215
147
  ref={timerPickerRef}
216
- onDurationChange={durationChangeHandler}
217
148
  initialValue={confirmedDuration}
218
- aggressivelyGetLatestDuration={true}
219
- hideHours={hideHours}
220
- hideMinutes={hideMinutes}
221
- hideSeconds={hideSeconds}
222
- hoursPickerIsDisabled={hoursPickerIsDisabled}
223
- minutesPickerIsDisabled={minutesPickerIsDisabled}
224
- secondsPickerIsDisabled={secondsPickerIsDisabled}
225
- hourLimit={hourLimit}
226
- minuteLimit={minuteLimit}
227
- secondLimit={secondLimit}
228
- hourLabel={hourLabel}
229
- minuteLabel={minuteLabel}
230
- secondLabel={secondLabel}
231
- padWithNItems={padWithNItems}
232
- disableInfiniteScroll={disableInfiniteScroll}
233
- allowFontScaling={allowFontScaling}
234
- use12HourPicker={use12HourPicker}
235
- amLabel={amLabel}
236
- pmLabel={pmLabel}
237
- LinearGradient={LinearGradient}
238
- pickerContainerProps={pickerContainerProps}
239
- pickerGradientOverlayProps={
240
- pickerGradientOverlayProps
241
- }
242
- topPickerGradientOverlayProps={
243
- topPickerGradientOverlayProps
244
- }
245
- bottomPickerGradientOverlayProps={
246
- bottomPickerGradientOverlayProps
247
- }
248
- styles={customStyles}
149
+ {...otherProps}
150
+ onDurationChange={durationChangeHandler}
249
151
  />
250
152
  <View
251
153
  {...buttonContainerProps}
@@ -1,15 +1,15 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { StyleSheet, TextStyle, ViewStyle } from "react-native";
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?: ViewStyle;
8
- contentContainer?: ViewStyle;
9
- buttonContainer?: ViewStyle;
10
7
  button?: TextStyle;
8
+ buttonContainer?: ViewStyle;
11
9
  cancelButton?: TextStyle;
12
10
  confirmButton?: TextStyle;
11
+ container?: ViewStyle;
12
+ contentContainer?: ViewStyle;
13
13
  modalTitle?: TextStyle;
14
14
  }
15
15
 
@@ -0,0 +1,52 @@
1
+ import type { MutableRefObject } from "react";
2
+
3
+ import type { View, TouchableOpacity, Text } from "react-native";
4
+
5
+ import type Modal from "../Modal";
6
+ import type { TimerPickerProps } from "../TimerPicker/types";
7
+
8
+ import type { CustomTimerPickerModalStyles } from "./styles";
9
+
10
+ export interface TimerPickerModalRef {
11
+ latestDuration: {
12
+ hours: MutableRefObject<number> | undefined;
13
+ minutes: MutableRefObject<number> | undefined;
14
+ seconds: MutableRefObject<number> | undefined;
15
+ };
16
+ reset: (options?: { animated?: boolean }) => void;
17
+ setValue: (
18
+ value: {
19
+ hours: number;
20
+ minutes: number;
21
+ seconds: number;
22
+ },
23
+ options?: { animated?: boolean }
24
+ ) => void;
25
+ }
26
+
27
+ export interface TimerPickerModalProps extends TimerPickerProps {
28
+ buttonContainerProps?: React.ComponentProps<typeof View>;
29
+ buttonTouchableOpacityProps?: React.ComponentProps<typeof TouchableOpacity>;
30
+ cancelButtonText?: string;
31
+ closeOnOverlayPress?: boolean;
32
+ confirmButtonText?: string;
33
+ containerProps?: React.ComponentProps<typeof View>;
34
+ contentContainerProps?: React.ComponentProps<typeof View>;
35
+ hideCancelButton?: boolean;
36
+ modalProps?: React.ComponentProps<typeof Modal>;
37
+ modalTitle?: string;
38
+ modalTitleProps?: React.ComponentProps<typeof Text>;
39
+ onCancel?: () => void;
40
+ onConfirm: ({
41
+ hours,
42
+ minutes,
43
+ seconds,
44
+ }: {
45
+ hours: number;
46
+ minutes: number;
47
+ seconds: number;
48
+ }) => void;
49
+ setIsVisible: (isVisible: boolean) => void;
50
+ styles?: CustomTimerPickerModalStyles;
51
+ visible: boolean;
52
+ }
package/src/index.ts CHANGED
@@ -1,14 +1,13 @@
1
+ export { default as TimerPickerModal } from "./components/TimerPickerModal";
1
2
  export {
2
- default as TimerPickerModal,
3
3
  TimerPickerModalProps,
4
4
  TimerPickerModalRef,
5
- } from "./components";
5
+ } from "./components/TimerPickerModal/types";
6
+ export { CustomTimerPickerModalStyles } from "./components/TimerPickerModal/styles";
6
7
 
8
+ export { default as TimerPicker } from "./components/TimerPicker";
7
9
  export {
8
- default as TimerPicker,
9
10
  TimerPickerProps,
10
11
  TimerPickerRef,
11
- } from "./components/TimerPicker";
12
-
13
- export { CustomTimerPickerModalStyles } from "./components/TimerPickerModal.styles";
14
- export { CustomTimerPickerStyles } from "./components/TimerPicker/TimerPicker.styles";
12
+ } from "./components/TimerPicker/types";
13
+ export { CustomTimerPickerStyles } from "./components/TimerPicker/styles";
@@ -1,5 +1,7 @@
1
1
  import React from "react";
2
+
2
3
  import { render } from "@testing-library/react-native";
4
+
3
5
  import DurationScroll from "../components/TimerPicker/DurationScroll";
4
6
 
5
7
  describe("DurationScroll", () => {
@@ -43,8 +45,8 @@ describe("DurationScroll", () => {
43
45
  it("renders the label if provided", () => {
44
46
  const { getByText } = render(
45
47
  <DurationScroll
46
- numberOfItems={59}
47
48
  label="Duration"
49
+ numberOfItems={59}
48
50
  onDurationChange={onDurationChangeMock}
49
51
  padWithNItems={1}
50
52
  styles={emptyStyles}
@@ -1,6 +1,8 @@
1
1
  import React from "react";
2
- import { Text } from "react-native";
2
+
3
3
  import { render, fireEvent } from "@testing-library/react-native";
4
+ import { Text } from "react-native";
5
+
4
6
  import Modal from "../components/Modal";
5
7
 
6
8
  describe("Modal", () => {