react-native-timer-picker 1.2.0 → 1.2.2

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 CHANGED
@@ -25,9 +25,12 @@ Works with Expo and bare React Native apps.
25
25
  - [TimerPickerModal ⏰](#timerpickermodal-)
26
26
  - [Custom Styles 👕](#custom-styles--1)
27
27
  - [Methods 🔄](#methods-)
28
+ - [TimerPicker](#timerpicker)
28
29
  - [TimerPickerModal](#timerpickermodal)
29
30
  - [License 📝](#license-)
30
31
 
32
+ <br>
33
+
31
34
  ## Demos 📱
32
35
 
33
36
  <p>
@@ -39,6 +42,7 @@ Works with Expo and bare React Native apps.
39
42
  <img src="demos/example4.gif" width="250" height="550"/>
40
43
  </p>
41
44
 
45
+ <br>
42
46
 
43
47
  ## Peer Dependencies 👶
44
48
 
@@ -49,7 +53,9 @@ If you want the numbers to fade in/out at the top and bottom of the picker, you
49
53
  - [expo-linear-gradient](https://www.npmjs.com/package/expo-linear-gradient) (if using Expo)
50
54
  - [react-native-linear-gradient](https://www.npmjs.com/package/react-native-linear-gradient) (if using in a bare React Native project)
51
55
 
52
- To enable the linear gradient, you need to supply the component as a prop to either TimerPickerModal or TimerPicker.
56
+ **To enable the linear gradient, you need to supply the component as a prop to either TimerPickerModal or TimerPicker.**
57
+
58
+ <br>
53
59
 
54
60
  ## Installation 🚀
55
61
 
@@ -67,6 +73,8 @@ or
67
73
  yarn add react-native-timer-picker
68
74
  ```
69
75
 
76
+ <br>
77
+
70
78
  ## Examples 😎
71
79
 
72
80
  ### Timer Picker Modal (Dark Mode) 🌚
@@ -295,6 +303,8 @@ return (
295
303
  ```
296
304
  <img src="demos/example4.gif" width="250" height="550"/>
297
305
 
306
+ <br>
307
+
298
308
  ## Props 💅
299
309
 
300
310
  ### TimerPicker ⏲️
@@ -356,7 +366,8 @@ The TimerPickerModal component accepts all [TimerPicker props](#timerpicker-️)
356
366
  | modalProps | Props for the main modal component | `React.ComponentProps<typeof Modal>` | - | false |
357
367
  | containerProps | Props for the main container | `React.ComponentProps<typeof View>` | - | false |
358
368
  | contentContainerProps | Props for the content container | `React.ComponentProps<typeof View>` | - | false |
359
- | buttonContainerProps | Props for the button container | `React.ComponentProps<typeof View>` | - | false |
369
+ | buttonContainerProps | Props for the button containers | `React.ComponentProps<typeof View>` | - | false |
370
+ | buttonTouchableOpacityProps | Props for the button touchable opacities | `React.ComponentProps<typeof TouchableOpacity>` | - | false |
360
371
  | modalTitleProps | Props for the modal title text component | `React.ComponentProps<typeof Text>` | - | false |
361
372
  | styles | Custom styles for the timer picker modal | [CustomTimerPickerModalStyles](#custom-styles--1) | - | false |
362
373
 
@@ -374,15 +385,16 @@ The following custom styles can be supplied to re-style the component in any way
374
385
  | confirmButton | Style for the confirm button | TextStyle |
375
386
  | modalTitle | Style for the title of the modal | TextStyle |
376
387
 
388
+ <br>
377
389
 
378
390
  ## Methods 🔄
379
391
 
380
- ### TimerPickerModal
392
+ ### TimerPicker
381
393
 
382
- The library exposes a TimerPickerModalRef type, which can be used to type your ref to the modal:
394
+ The library exposes a TimerPickerRef type, which can be used to type your ref to the picker:
383
395
 
384
396
  ```javascript
385
- const timerPickerModalRef = useRef<TimerPickerModalRef>(null);
397
+ const timerPickerRef = useRef<TimerPickerRef>(null);
386
398
  ```
387
399
 
388
400
  It has the following available methods:
@@ -390,15 +402,21 @@ It has the following available methods:
390
402
  `reset` - imperative method to reset the selected duration to their initial values.
391
403
 
392
404
  ```javascript
393
- timerPickerModalRef.current.reset();
405
+ timerPickerRef.current.reset(options?: { animated: boolean });
394
406
  ```
395
407
 
396
408
  `setValue` - imperative method to set the selected duration to a particular value
397
409
 
398
410
  ```javascript
399
- timerPickerModalRef.current.setValue({hours: number, minutes: number, seconds: number});
411
+ timerPickerRef.current.setValue({ hours: number, minutes: number, seconds: number }, options?: { animated: boolean });
400
412
  ```
401
413
 
414
+ ### TimerPickerModal
415
+
416
+ An identical ref is also exposed for the TimerPickerModal component.
417
+
418
+ <br>
419
+
402
420
  ## License 📝
403
421
 
404
422
  This project is licensed under the [MIT License](LICENSE).
@@ -1,6 +1,14 @@
1
1
  import React from "react";
2
2
  import { View } from "react-native";
3
3
  import { generateStyles } from "./TimerPicker.styles";
4
+ export interface DurationScrollRef {
5
+ reset: (options?: {
6
+ animated?: boolean;
7
+ }) => void;
8
+ setValue: (value: number, options?: {
9
+ animated?: boolean;
10
+ }) => void;
11
+ }
4
12
  type LinearGradientPoint = {
5
13
  x: number;
6
14
  y: number;
@@ -18,7 +26,7 @@ export type LimitType = {
18
26
  interface DurationScrollProps {
19
27
  numberOfItems: number;
20
28
  label?: string | React.ReactElement;
21
- initialIndex?: number;
29
+ initialValue?: number;
22
30
  onDurationChange: (duration: number) => void;
23
31
  padNumbersWithZero?: boolean;
24
32
  disableInfiniteScroll?: boolean;
@@ -29,5 +37,5 @@ interface DurationScrollProps {
29
37
  testID?: string;
30
38
  styles: ReturnType<typeof generateStyles>;
31
39
  }
32
- declare const _default: React.MemoExoticComponent<({ numberOfItems, label, initialIndex, onDurationChange, padNumbersWithZero, disableInfiniteScroll, limit, padWithNItems, pickerGradientOverlayProps, LinearGradient, testID, styles, }: DurationScrollProps) => React.ReactElement<any, string | React.JSXElementConstructor<any>>>;
40
+ declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<DurationScrollProps & React.RefAttributes<DurationScrollRef>>>;
33
41
  export default _default;
@@ -38,11 +38,12 @@ var react_native_1 = require("react-native");
38
38
  var generateNumbers_1 = require("../../utils/generateNumbers");
39
39
  var colorToRgba_1 = require("../../utils/colorToRgba");
40
40
  var getAdjustedLimit_1 = require("../../utils/getAdjustedLimit");
41
+ var getScrollIndex_1 = require("../../utils/getScrollIndex");
41
42
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
43
  var KEY_EXTRACTOR = function (_, index) { return index.toString(); };
43
- var DurationScroll = function (_a) {
44
+ var DurationScroll = (0, react_1.forwardRef)(function (_a, ref) {
44
45
  var _b, _c, _d, _e;
45
- var numberOfItems = _a.numberOfItems, label = _a.label, _f = _a.initialIndex, initialIndex = _f === void 0 ? 0 : _f, onDurationChange = _a.onDurationChange, _g = _a.padNumbersWithZero, padNumbersWithZero = _g === void 0 ? false : _g, _h = _a.disableInfiniteScroll, disableInfiniteScroll = _h === void 0 ? false : _h, limit = _a.limit, padWithNItems = _a.padWithNItems, pickerGradientOverlayProps = _a.pickerGradientOverlayProps, LinearGradient = _a.LinearGradient, testID = _a.testID, styles = _a.styles;
46
+ var numberOfItems = _a.numberOfItems, label = _a.label, _f = _a.initialValue, initialValue = _f === void 0 ? 0 : _f, onDurationChange = _a.onDurationChange, _g = _a.padNumbersWithZero, padNumbersWithZero = _g === void 0 ? false : _g, _h = _a.disableInfiniteScroll, disableInfiniteScroll = _h === void 0 ? false : _h, limit = _a.limit, padWithNItems = _a.padWithNItems, pickerGradientOverlayProps = _a.pickerGradientOverlayProps, LinearGradient = _a.LinearGradient, testID = _a.testID, styles = _a.styles;
46
47
  var flatListRef = (0, react_1.useRef)(null);
47
48
  var data = (0, generateNumbers_1.generateNumbers)(numberOfItems, {
48
49
  padWithZero: padNumbersWithZero,
@@ -52,20 +53,47 @@ var DurationScroll = function (_a) {
52
53
  });
53
54
  var numberOfItemsToShow = 1 + padWithNItems * 2;
54
55
  var adjustedLimited = (0, getAdjustedLimit_1.getAdjustedLimit)(limit, numberOfItems);
56
+ var initialScrollIndex = (0, getScrollIndex_1.getScrollIndex)({
57
+ value: initialValue,
58
+ numberOfItems: numberOfItems,
59
+ padWithNItems: padWithNItems,
60
+ disableInfiniteScroll: disableInfiniteScroll,
61
+ });
62
+ (0, react_1.useImperativeHandle)(ref, function () { return ({
63
+ reset: function (options) {
64
+ var _a, _b;
65
+ (_a = flatListRef.current) === null || _a === void 0 ? void 0 : _a.scrollToIndex({
66
+ animated: (_b = options === null || options === void 0 ? void 0 : options.animated) !== null && _b !== void 0 ? _b : false,
67
+ index: initialScrollIndex,
68
+ });
69
+ },
70
+ setValue: function (value, options) {
71
+ var _a, _b;
72
+ (_a = flatListRef.current) === null || _a === void 0 ? void 0 : _a.scrollToIndex({
73
+ animated: (_b = options === null || options === void 0 ? void 0 : options.animated) !== null && _b !== void 0 ? _b : false,
74
+ index: (0, getScrollIndex_1.getScrollIndex)({
75
+ value: value,
76
+ numberOfItems: numberOfItems,
77
+ padWithNItems: padWithNItems,
78
+ disableInfiniteScroll: disableInfiniteScroll,
79
+ }),
80
+ });
81
+ },
82
+ }); });
55
83
  var renderItem = (0, react_1.useCallback)(function (_a) {
56
84
  var item = _a.item;
57
85
  var intItem = parseInt(item);
58
86
  return (<react_native_1.View key={item} style={styles.pickerItemContainer} testID="picker-item">
59
- <react_native_1.Text style={[
87
+ <react_native_1.Text style={[
60
88
  styles.pickerItem,
61
89
  intItem > adjustedLimited.max ||
62
90
  intItem < adjustedLimited.min
63
91
  ? styles.disabledPickerItem
64
92
  : {},
65
93
  ]}>
66
- {item}
67
- </react_native_1.Text>
68
- </react_native_1.View>);
94
+ {item}
95
+ </react_native_1.Text>
96
+ </react_native_1.View>);
69
97
  }, [
70
98
  adjustedLimited.max,
71
99
  adjustedLimited.min,
@@ -77,7 +105,9 @@ var DurationScroll = function (_a) {
77
105
  var _a, _b;
78
106
  var newIndex = Math.round(e.nativeEvent.contentOffset.y /
79
107
  styles.pickerItemContainer.height);
80
- var newDuration = (disableInfiniteScroll ? newIndex : newIndex + padWithNItems) %
108
+ var newDuration = (disableInfiniteScroll
109
+ ? newIndex
110
+ : newIndex + padWithNItems) %
81
111
  (numberOfItems + 1);
82
112
  // check limits
83
113
  if (newDuration > adjustedLimited.max) {
@@ -148,33 +178,35 @@ var DurationScroll = function (_a) {
148
178
  height: styles.pickerItemContainer.height * numberOfItemsToShow,
149
179
  overflow: "hidden",
150
180
  }}>
151
- <react_native_1.FlatList ref={flatListRef} data={data} getItemLayout={getItemLayout} initialScrollIndex={(initialIndex % numberOfItems) +
152
- numberOfItems +
153
- (disableInfiniteScroll ? padWithNItems : 0) -
154
- (padWithNItems - 1)} windowSize={numberOfItemsToShow} renderItem={renderItem} keyExtractor={KEY_EXTRACTOR} showsVerticalScrollIndicator={false} decelerationRate="fast" scrollEventThrottle={16} snapToAlignment="start"
181
+ <react_native_1.FlatList ref={flatListRef} data={data} getItemLayout={getItemLayout} initialScrollIndex={initialScrollIndex} windowSize={numberOfItemsToShow} renderItem={renderItem} keyExtractor={KEY_EXTRACTOR} showsVerticalScrollIndicator={false} decelerationRate="fast" scrollEventThrottle={16} snapToAlignment="start"
155
182
  // used in place of snapToOffset due to bug on Android
156
183
  snapToOffsets={__spreadArray([], Array(data.length), true).map(function (_, i) { return i * styles.pickerItemContainer.height; })} viewabilityConfigCallbackPairs={!disableInfiniteScroll
157
184
  ? viewabilityConfigCallbackPairs === null || viewabilityConfigCallbackPairs === void 0 ? void 0 : viewabilityConfigCallbackPairs.current
158
185
  : undefined} onMomentumScrollEnd={onMomentumScrollEnd} testID="duration-scroll-flatlist"/>
159
- <react_native_1.View style={styles.pickerLabelContainer}>
160
- {typeof label === "string" ? (<react_native_1.Text style={styles.pickerLabel}>{label}</react_native_1.Text>) : (label !== null && label !== void 0 ? label : null)}
161
- </react_native_1.View>
162
- {LinearGradient ? (<>
163
- <LinearGradient colors={[
186
+ <react_native_1.View style={styles.pickerLabelContainer}>
187
+ {typeof label === "string" ? (<react_native_1.Text style={styles.pickerLabel}>{label}</react_native_1.Text>) : (label !== null && label !== void 0 ? label : null)}
188
+ </react_native_1.View>
189
+ {LinearGradient ? (<>
190
+ <LinearGradient colors={[
164
191
  (_b = styles.pickerContainer.backgroundColor) !== null && _b !== void 0 ? _b : "white",
165
192
  (0, colorToRgba_1.colorToRgba)({
166
- color: (_c = styles.pickerContainer.backgroundColor) !== null && _c !== void 0 ? _c : "white",
193
+ color: (_c = styles.pickerContainer
194
+ .backgroundColor) !== null && _c !== void 0 ? _c : "white",
167
195
  opacity: 0,
168
196
  }),
169
197
  ]} start={{ x: 1, y: 0.3 }} end={{ x: 1, y: 1 }} {...pickerGradientOverlayProps} style={[styles.pickerGradientOverlay, { top: 0 }]}/>
170
- <LinearGradient colors={[
198
+ <LinearGradient colors={[
171
199
  (0, colorToRgba_1.colorToRgba)({
172
- color: (_d = styles.pickerContainer.backgroundColor) !== null && _d !== void 0 ? _d : "white",
200
+ color: (_d = styles.pickerContainer
201
+ .backgroundColor) !== null && _d !== void 0 ? _d : "white",
173
202
  opacity: 0,
174
203
  }),
175
204
  (_e = styles.pickerContainer.backgroundColor) !== null && _e !== void 0 ? _e : "white",
176
- ]} start={{ x: 1, y: 0 }} end={{ x: 1, y: 0.7 }} {...pickerGradientOverlayProps} style={[styles.pickerGradientOverlay, { bottom: -1 }]}/>
177
- </>) : null}
178
- </react_native_1.View>);
179
- };
205
+ ]} start={{ x: 1, y: 0 }} end={{ x: 1, y: 0.7 }} {...pickerGradientOverlayProps} style={[
206
+ styles.pickerGradientOverlay,
207
+ { bottom: -1 },
208
+ ]}/>
209
+ </>) : null}
210
+ </react_native_1.View>);
211
+ });
180
212
  exports.default = react_1.default.memo(DurationScroll);
@@ -3,6 +3,18 @@ import { View } from "react-native";
3
3
  import { LimitType } from "./DurationScroll";
4
4
  import { CustomTimerPickerStyles } from "./TimerPicker.styles";
5
5
  import { LinearGradientProps } from "./DurationScroll";
6
+ export interface TimerPickerRef {
7
+ reset: (options?: {
8
+ animated?: boolean;
9
+ }) => void;
10
+ setValue: (value: {
11
+ hours: number;
12
+ minutes: number;
13
+ seconds: number;
14
+ }, options?: {
15
+ animated?: boolean;
16
+ }) => void;
17
+ }
6
18
  export interface TimerPickerProps {
7
19
  onDurationChange?: (duration: {
8
20
  hours: number;
@@ -28,5 +40,5 @@ export interface TimerPickerProps {
28
40
  pickerGradientOverlayProps?: LinearGradientProps;
29
41
  styles?: CustomTimerPickerStyles;
30
42
  }
31
- declare const _default: React.MemoExoticComponent<({ onDurationChange, initialHours, initialMinutes, initialSeconds, hideHours, hideMinutes, hideSeconds, hourLimit, minuteLimit, secondLimit, hourLabel, minuteLabel, secondLabel, padWithNItems, disableInfiniteScroll, LinearGradient, pickerContainerProps, pickerGradientOverlayProps, styles: customStyles, }: TimerPickerProps) => React.ReactElement<any, string | React.JSXElementConstructor<any>>>;
43
+ declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<TimerPickerProps & React.RefAttributes<TimerPickerRef>>>;
32
44
  export default _default;
@@ -30,7 +30,7 @@ var react_1 = __importStar(require("react"));
30
30
  var react_native_1 = require("react-native");
31
31
  var DurationScroll_1 = __importDefault(require("./DurationScroll"));
32
32
  var TimerPicker_styles_1 = require("./TimerPicker.styles");
33
- var TimerPicker = function (_a) {
33
+ var TimerPicker = (0, react_1.forwardRef)(function (_a, ref) {
34
34
  var onDurationChange = _a.onDurationChange, _b = _a.initialHours, initialHours = _b === void 0 ? 0 : _b, _c = _a.initialMinutes, initialMinutes = _c === void 0 ? 0 : _c, _d = _a.initialSeconds, initialSeconds = _d === void 0 ? 0 : _d, _e = _a.hideHours, hideHours = _e === void 0 ? false : _e, _f = _a.hideMinutes, hideMinutes = _f === void 0 ? false : _f, _g = _a.hideSeconds, hideSeconds = _g === void 0 ? false : _g, hourLimit = _a.hourLimit, minuteLimit = _a.minuteLimit, secondLimit = _a.secondLimit, _h = _a.hourLabel, hourLabel = _h === void 0 ? "h" : _h, _j = _a.minuteLabel, minuteLabel = _j === void 0 ? "m" : _j, _k = _a.secondLabel, secondLabel = _k === void 0 ? "s" : _k, _l = _a.padWithNItems, padWithNItems = _l === void 0 ? 1 : _l, _m = _a.disableInfiniteScroll, disableInfiniteScroll = _m === void 0 ? false : _m, LinearGradient = _a.LinearGradient, pickerContainerProps = _a.pickerContainerProps, pickerGradientOverlayProps = _a.pickerGradientOverlayProps, customStyles = _a.styles;
35
35
  var checkedPadWithNItems = padWithNItems >= 0 ? Math.round(padWithNItems) : 0;
36
36
  var styles = (0, react_1.useMemo)(function () {
@@ -49,10 +49,33 @@ var TimerPicker = function (_a) {
49
49
  });
50
50
  // eslint-disable-next-line react-hooks/exhaustive-deps
51
51
  }, [selectedHours, selectedMinutes, selectedSeconds]);
52
+ var hoursDurationScrollRef = (0, react_1.useRef)(null);
53
+ var minutesDurationScrollRef = (0, react_1.useRef)(null);
54
+ var secondsDurationScrollRef = (0, react_1.useRef)(null);
55
+ (0, react_1.useImperativeHandle)(ref, function () { return ({
56
+ reset: function (options) {
57
+ var _a, _b, _c;
58
+ setSelectedHours(initialHours);
59
+ setSelectedMinutes(initialMinutes);
60
+ setSelectedSeconds(initialSeconds);
61
+ (_a = hoursDurationScrollRef.current) === null || _a === void 0 ? void 0 : _a.reset(options);
62
+ (_b = minutesDurationScrollRef.current) === null || _b === void 0 ? void 0 : _b.reset(options);
63
+ (_c = secondsDurationScrollRef.current) === null || _c === void 0 ? void 0 : _c.reset(options);
64
+ },
65
+ setValue: function (value, options) {
66
+ var _a, _b, _c;
67
+ setSelectedHours(value.hours);
68
+ setSelectedMinutes(value.minutes);
69
+ setSelectedSeconds(value.seconds);
70
+ (_a = hoursDurationScrollRef.current) === null || _a === void 0 ? void 0 : _a.setValue(value.hours, options);
71
+ (_b = minutesDurationScrollRef.current) === null || _b === void 0 ? void 0 : _b.setValue(value.minutes, options);
72
+ (_c = secondsDurationScrollRef.current) === null || _c === void 0 ? void 0 : _c.setValue(value.seconds, options);
73
+ },
74
+ }); });
52
75
  return (<react_native_1.View {...pickerContainerProps} style={styles.pickerContainer} testID="timer-picker">
53
- {!hideHours ? (<DurationScroll_1.default numberOfItems={23} label={hourLabel} initialIndex={initialHours} onDurationChange={setSelectedHours} pickerGradientOverlayProps={pickerGradientOverlayProps} disableInfiniteScroll={disableInfiniteScroll} padWithNItems={checkedPadWithNItems} limit={hourLimit} LinearGradient={LinearGradient} styles={styles} testID="duration-scroll-hour"/>) : null}
54
- {!hideMinutes ? (<DurationScroll_1.default numberOfItems={59} label={minuteLabel} initialIndex={initialMinutes} onDurationChange={setSelectedMinutes} padNumbersWithZero pickerGradientOverlayProps={pickerGradientOverlayProps} disableInfiniteScroll={disableInfiniteScroll} padWithNItems={checkedPadWithNItems} limit={minuteLimit} LinearGradient={LinearGradient} styles={styles} testID="duration-scroll-minute"/>) : null}
55
- {!hideSeconds ? (<DurationScroll_1.default numberOfItems={59} label={secondLabel} initialIndex={initialSeconds} onDurationChange={setSelectedSeconds} padNumbersWithZero pickerGradientOverlayProps={pickerGradientOverlayProps} disableInfiniteScroll={disableInfiniteScroll} padWithNItems={checkedPadWithNItems} limit={secondLimit} LinearGradient={LinearGradient} styles={styles} testID="duration-scroll-second"/>) : null}
56
- </react_native_1.View>);
57
- };
76
+ {!hideHours ? (<DurationScroll_1.default ref={hoursDurationScrollRef} numberOfItems={23} label={hourLabel} initialValue={initialHours} onDurationChange={setSelectedHours} pickerGradientOverlayProps={pickerGradientOverlayProps} disableInfiniteScroll={disableInfiniteScroll} padWithNItems={checkedPadWithNItems} limit={hourLimit} LinearGradient={LinearGradient} styles={styles} testID="duration-scroll-hour"/>) : null}
77
+ {!hideMinutes ? (<DurationScroll_1.default ref={minutesDurationScrollRef} numberOfItems={59} label={minuteLabel} initialValue={initialMinutes} onDurationChange={setSelectedMinutes} padNumbersWithZero pickerGradientOverlayProps={pickerGradientOverlayProps} disableInfiniteScroll={disableInfiniteScroll} padWithNItems={checkedPadWithNItems} limit={minuteLimit} LinearGradient={LinearGradient} styles={styles} testID="duration-scroll-minute"/>) : null}
78
+ {!hideSeconds ? (<DurationScroll_1.default ref={secondsDurationScrollRef} numberOfItems={59} label={secondLabel} initialValue={initialSeconds} onDurationChange={setSelectedSeconds} padNumbersWithZero pickerGradientOverlayProps={pickerGradientOverlayProps} disableInfiniteScroll={disableInfiniteScroll} padWithNItems={checkedPadWithNItems} limit={secondLimit} LinearGradient={LinearGradient} styles={styles} testID="duration-scroll-second"/>) : null}
79
+ </react_native_1.View>);
80
+ });
58
81
  exports.default = react_1.default.memo(TimerPicker);
@@ -1,14 +1,18 @@
1
1
  import React from "react";
2
- import { View, Text } from "react-native";
2
+ import { View, Text, TouchableOpacity } from "react-native";
3
3
  import { TimerPickerProps } from "./TimerPicker";
4
4
  import Modal from "./Modal";
5
5
  import { CustomTimerPickerModalStyles } from "./TimerPickerModal.styles";
6
6
  export interface TimerPickerModalRef {
7
- reset: () => void;
7
+ reset: (options?: {
8
+ animated?: boolean;
9
+ }) => void;
8
10
  setValue: (value: {
9
11
  hours: number;
10
12
  minutes: number;
11
13
  seconds: number;
14
+ }, options?: {
15
+ animated?: boolean;
12
16
  }) => void;
13
17
  }
14
18
  export interface TimerPickerModalProps extends TimerPickerProps {
@@ -29,6 +33,7 @@ export interface TimerPickerModalProps extends TimerPickerProps {
29
33
  containerProps?: React.ComponentProps<typeof View>;
30
34
  contentContainerProps?: React.ComponentProps<typeof View>;
31
35
  buttonContainerProps?: React.ComponentProps<typeof View>;
36
+ buttonTouchableOpacityProps: React.ComponentProps<typeof TouchableOpacity>;
32
37
  modalTitleProps?: React.ComponentProps<typeof Text>;
33
38
  styles?: CustomTimerPickerModalStyles;
34
39
  }
@@ -32,7 +32,7 @@ var TimerPicker_1 = __importDefault(require("./TimerPicker"));
32
32
  var Modal_1 = __importDefault(require("./Modal"));
33
33
  var TimerPickerModal_styles_1 = require("./TimerPickerModal.styles");
34
34
  var TimerPickerModal = (0, react_1.forwardRef)(function (_a, ref) {
35
- var visible = _a.visible, setIsVisible = _a.setIsVisible, onConfirm = _a.onConfirm, onCancel = _a.onCancel, onDurationChange = _a.onDurationChange, closeOnOverlayPress = _a.closeOnOverlayPress, _b = _a.initialHours, initialHours = _b === void 0 ? 0 : _b, _c = _a.initialMinutes, initialMinutes = _c === void 0 ? 0 : _c, _d = _a.initialSeconds, initialSeconds = _d === void 0 ? 0 : _d, _e = _a.hideHours, hideHours = _e === void 0 ? false : _e, _f = _a.hideMinutes, hideMinutes = _f === void 0 ? false : _f, _g = _a.hideSeconds, hideSeconds = _g === void 0 ? false : _g, hourLimit = _a.hourLimit, minuteLimit = _a.minuteLimit, secondLimit = _a.secondLimit, _h = _a.hourLabel, hourLabel = _h === void 0 ? "h" : _h, _j = _a.minuteLabel, minuteLabel = _j === void 0 ? "m" : _j, _k = _a.secondLabel, secondLabel = _k === void 0 ? "s" : _k, _l = _a.padWithNItems, padWithNItems = _l === void 0 ? 1 : _l, _m = _a.disableInfiniteScroll, disableInfiniteScroll = _m === void 0 ? false : _m, _o = _a.hideCancelButton, hideCancelButton = _o === void 0 ? false : _o, _p = _a.confirmButtonText, confirmButtonText = _p === void 0 ? "Confirm" : _p, _q = _a.cancelButtonText, cancelButtonText = _q === void 0 ? "Cancel" : _q, modalTitle = _a.modalTitle, LinearGradient = _a.LinearGradient, modalProps = _a.modalProps, containerProps = _a.containerProps, contentContainerProps = _a.contentContainerProps, pickerContainerProps = _a.pickerContainerProps, buttonContainerProps = _a.buttonContainerProps, modalTitleProps = _a.modalTitleProps, pickerGradientOverlayProps = _a.pickerGradientOverlayProps, customStyles = _a.styles;
35
+ var visible = _a.visible, setIsVisible = _a.setIsVisible, onConfirm = _a.onConfirm, onCancel = _a.onCancel, onDurationChange = _a.onDurationChange, closeOnOverlayPress = _a.closeOnOverlayPress, _b = _a.initialHours, initialHours = _b === void 0 ? 0 : _b, _c = _a.initialMinutes, initialMinutes = _c === void 0 ? 0 : _c, _d = _a.initialSeconds, initialSeconds = _d === void 0 ? 0 : _d, _e = _a.hideHours, hideHours = _e === void 0 ? false : _e, _f = _a.hideMinutes, hideMinutes = _f === void 0 ? false : _f, _g = _a.hideSeconds, hideSeconds = _g === void 0 ? false : _g, hourLimit = _a.hourLimit, minuteLimit = _a.minuteLimit, secondLimit = _a.secondLimit, _h = _a.hourLabel, hourLabel = _h === void 0 ? "h" : _h, _j = _a.minuteLabel, minuteLabel = _j === void 0 ? "m" : _j, _k = _a.secondLabel, secondLabel = _k === void 0 ? "s" : _k, _l = _a.padWithNItems, padWithNItems = _l === void 0 ? 1 : _l, _m = _a.disableInfiniteScroll, disableInfiniteScroll = _m === void 0 ? false : _m, _o = _a.hideCancelButton, hideCancelButton = _o === void 0 ? false : _o, _p = _a.confirmButtonText, confirmButtonText = _p === void 0 ? "Confirm" : _p, _q = _a.cancelButtonText, cancelButtonText = _q === void 0 ? "Cancel" : _q, modalTitle = _a.modalTitle, LinearGradient = _a.LinearGradient, modalProps = _a.modalProps, containerProps = _a.containerProps, contentContainerProps = _a.contentContainerProps, pickerContainerProps = _a.pickerContainerProps, buttonContainerProps = _a.buttonContainerProps, buttonTouchableOpacityProps = _a.buttonTouchableOpacityProps, modalTitleProps = _a.modalTitleProps, pickerGradientOverlayProps = _a.pickerGradientOverlayProps, customStyles = _a.styles;
36
36
  var styles = (0, TimerPickerModal_styles_1.generateStyles)(customStyles);
37
37
  var _r = (0, react_1.useState)({
38
38
  hours: initialHours,
@@ -66,8 +66,10 @@ var TimerPickerModal = (0, react_1.forwardRef)(function (_a, ref) {
66
66
  setSelectedDuration(duration);
67
67
  onDurationChange === null || onDurationChange === void 0 ? void 0 : onDurationChange(duration);
68
68
  }, [onDurationChange]);
69
+ var timerPickerRef = (0, react_1.useRef)(null);
69
70
  (0, react_1.useImperativeHandle)(ref, function () { return ({
70
- reset: function () {
71
+ reset: function (options) {
72
+ var _a;
71
73
  var initialDuration = {
72
74
  hours: initialHours,
73
75
  minutes: initialMinutes,
@@ -75,11 +77,13 @@ var TimerPickerModal = (0, react_1.forwardRef)(function (_a, ref) {
75
77
  };
76
78
  setSelectedDuration(initialDuration);
77
79
  setConfirmedDuration(initialDuration);
78
- setIsVisible(false);
80
+ (_a = timerPickerRef.current) === null || _a === void 0 ? void 0 : _a.reset(options);
79
81
  },
80
- setValue: function (value) {
82
+ setValue: function (value, options) {
83
+ var _a;
81
84
  setSelectedDuration(value);
82
85
  setConfirmedDuration(value);
86
+ (_a = timerPickerRef.current) === null || _a === void 0 ? void 0 : _a.setValue(value, options);
83
87
  },
84
88
  }); });
85
89
  return (<Modal_1.default isVisible={visible} onOverlayPress={closeOnOverlayPress ? hideModal : undefined} {...modalProps} testID="timer-picker-modal">
@@ -88,20 +92,20 @@ var TimerPickerModal = (0, react_1.forwardRef)(function (_a, ref) {
88
92
  {modalTitle ? (<react_native_1.Text {...modalTitleProps} style={styles.modalTitle}>
89
93
  {modalTitle}
90
94
  </react_native_1.Text>) : null}
91
- <TimerPicker_1.default onDurationChange={durationChange} initialHours={confirmedDuration.hours} initialMinutes={confirmedDuration.minutes} initialSeconds={confirmedDuration.seconds} hideHours={hideHours} hideMinutes={hideMinutes} hideSeconds={hideSeconds} hourLimit={hourLimit} minuteLimit={minuteLimit} secondLimit={secondLimit} hourLabel={hourLabel} minuteLabel={minuteLabel} secondLabel={secondLabel} padWithNItems={padWithNItems} disableInfiniteScroll={disableInfiniteScroll} LinearGradient={LinearGradient} pickerContainerProps={pickerContainerProps} pickerGradientOverlayProps={pickerGradientOverlayProps} styles={customStyles}/>
95
+ <TimerPicker_1.default ref={timerPickerRef} onDurationChange={durationChange} initialHours={confirmedDuration.hours} initialMinutes={confirmedDuration.minutes} initialSeconds={confirmedDuration.seconds} hideHours={hideHours} hideMinutes={hideMinutes} hideSeconds={hideSeconds} hourLimit={hourLimit} minuteLimit={minuteLimit} secondLimit={secondLimit} hourLabel={hourLabel} minuteLabel={minuteLabel} secondLabel={secondLabel} padWithNItems={padWithNItems} disableInfiniteScroll={disableInfiniteScroll} LinearGradient={LinearGradient} pickerContainerProps={pickerContainerProps} pickerGradientOverlayProps={pickerGradientOverlayProps} styles={customStyles}/>
92
96
  <react_native_1.View {...buttonContainerProps} style={styles.buttonContainer}>
93
- {!hideCancelButton ? (<react_native_1.TouchableOpacity onPress={cancel}>
97
+ {!hideCancelButton ? (<react_native_1.TouchableOpacity onPress={cancel} {...buttonTouchableOpacityProps}>
94
98
  <react_native_1.Text style={[
95
- styles.cancelButton,
96
99
  styles.button,
100
+ styles.cancelButton,
97
101
  ]}>
98
102
  {cancelButtonText}
99
103
  </react_native_1.Text>
100
104
  </react_native_1.TouchableOpacity>) : null}
101
- <react_native_1.TouchableOpacity onPress={confirm}>
105
+ <react_native_1.TouchableOpacity onPress={confirm} {...buttonTouchableOpacityProps}>
102
106
  <react_native_1.Text style={[
103
- styles.confirmButton,
104
107
  styles.button,
108
+ styles.confirmButton,
105
109
  ]}>
106
110
  {confirmButtonText}
107
111
  </react_native_1.Text>
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { default as TimerPickerModal, TimerPickerModalProps, TimerPickerModalRef, } from "./components";
2
- export { default as TimerPicker, TimerPickerProps, } from "./components/TimerPicker";
2
+ export { default as TimerPicker, TimerPickerProps, TimerPickerRef, } from "./components/TimerPicker";
3
3
  export { CustomTimerPickerModalStyles } from "./components/TimerPickerModal.styles";
4
4
  export { CustomTimerPickerStyles } from "./components/TimerPicker/TimerPicker.styles";
@@ -0,0 +1,6 @@
1
+ export declare const getScrollIndex: (variables: {
2
+ value: number;
3
+ numberOfItems: number;
4
+ padWithNItems: number;
5
+ disableInfiniteScroll?: boolean | undefined;
6
+ }) => number;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getScrollIndex = void 0;
4
+ var getScrollIndex = function (variables) {
5
+ var value = variables.value, numberOfItems = variables.numberOfItems, padWithNItems = variables.padWithNItems, disableInfiniteScroll = variables.disableInfiniteScroll;
6
+ return (((value + numberOfItems) % (numberOfItems * 3)) +
7
+ (disableInfiniteScroll ? padWithNItems : 0) -
8
+ (padWithNItems - 1));
9
+ };
10
+ exports.getScrollIndex = getScrollIndex;
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.2.0",
9
+ "version": "1.2.2",
10
10
  "main": "dist/index.js",
11
11
  "types": "dist/index.d.ts",
12
12
  "scripts": {