Skip to content

Commit d6915ee

Browse files
committed
Merge branch 'patch/v2.0.1'
2 parents cf7e1c1 + e0f6774 commit d6915ee

File tree

8 files changed

+478
-95
lines changed

8 files changed

+478
-95
lines changed

examples/example-expo/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
},
1111
"dependencies": {
1212
"@expo/vector-icons": "^14.0.3",
13-
"expo": "^52.0.0",
13+
"expo": "^52.0.11",
1414
"expo-av": "~15.0.1",
1515
"expo-haptics": "~14.0.0",
1616
"expo-linear-gradient": "~14.0.1",
1717
"react": "18.3.1",
18-
"react-native": "0.76.2"
18+
"react-native": "0.76.3"
1919
},
2020
"devDependencies": {
2121
"@babel/core": "^7.24.0",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"url": "https://github.com/troberts-28"
77
},
88
"license": "MIT",
9-
"version": "2.0.0",
9+
"version": "2.0.1",
1010
"main": "dist/commonjs/index.js",
1111
"module": "dist/module/index.js",
1212
"types": "dist/typescript/index.d.ts",

src/components/DurationScroll/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const DurationScroll = forwardRef<DurationScrollRef, DurationScrollProps>(
7777

7878
if (!disableInfiniteScroll && repeatNumbersNTimes < 2) {
7979
return 2;
80-
} else if (repeatNumbersNTimes < 1) {
80+
} else if (repeatNumbersNTimes < 1 || isNaN(repeatNumbersNTimes)) {
8181
return 1;
8282
}
8383

src/components/TimerPicker/index.tsx

+12-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import React, {
99

1010
import { View } from "react-native";
1111

12+
import { getSafeInitialValue } from "../../utils/getSafeInitialValue";
1213
import DurationScroll from "../DurationScroll";
1314
import type { DurationScrollRef } from "../DurationScroll/types";
1415

@@ -57,7 +58,7 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
5758
} = props;
5859

5960
const safePadWithNItems = useMemo(() => {
60-
if (padWithNItems < 0) {
61+
if (padWithNItems < 0 || isNaN(padWithNItems)) {
6162
return 0;
6263
}
6364

@@ -70,6 +71,16 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
7071
return Math.round(padWithNItems);
7172
}, [hideHours, padWithNItems]);
7273

74+
const safeInitialValue = useMemo(
75+
() =>
76+
getSafeInitialValue({
77+
hours: initialValue?.hours,
78+
minutes: initialValue?.minutes,
79+
seconds: initialValue?.seconds,
80+
}),
81+
[initialValue?.hours, initialValue?.minutes, initialValue?.seconds]
82+
);
83+
7384
const styles = useMemo(
7485
() =>
7586
generateStyles(customStyles, {
@@ -79,15 +90,6 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
7990
[safePadWithNItems, customStyles]
8091
);
8192

82-
const safeInitialValue = useMemo(
83-
() => ({
84-
hours: initialValue?.hours ?? 0,
85-
minutes: initialValue?.minutes ?? 0,
86-
seconds: initialValue?.seconds ?? 0,
87-
}),
88-
[initialValue?.hours, initialValue?.minutes, initialValue?.seconds]
89-
);
90-
9193
const [selectedHours, setSelectedHours] = useState(
9294
safeInitialValue.hours
9395
);

src/components/TimerPickerModal/index.tsx

+10-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import React, {
99

1010
import { View, Text, TouchableOpacity } from "react-native";
1111

12+
import { getSafeInitialValue } from "../../utils/getSafeInitialValue";
1213
import Modal from "../Modal";
1314
import TimerPicker from "../TimerPicker";
1415
import type { TimerPickerRef } from "../TimerPicker/types";
@@ -40,15 +41,17 @@ const TimerPickerModal = forwardRef<TimerPickerModalRef, TimerPickerModalProps>(
4041
...otherProps
4142
} = props;
4243

43-
const styles = generateStyles(customStyles);
44+
const styles = generateStyles(customStyles, {
45+
hasModalTitle: Boolean(modalTitle),
46+
});
4447

4548
const timerPickerRef = useRef<TimerPickerRef>(null);
4649

47-
const safeInitialValue = {
48-
hours: initialValue?.hours ?? 0,
49-
minutes: initialValue?.minutes ?? 0,
50-
seconds: initialValue?.seconds ?? 0,
51-
};
50+
const safeInitialValue = getSafeInitialValue({
51+
hours: initialValue?.hours,
52+
minutes: initialValue?.minutes,
53+
seconds: initialValue?.seconds,
54+
});
5255

5356
const [selectedDuration, setSelectedDuration] =
5457
useState(safeInitialValue);
@@ -150,7 +153,7 @@ const TimerPickerModal = forwardRef<TimerPickerModalRef, TimerPickerModalProps>(
150153
{...otherProps}
151154
aggressivelyGetLatestDuration
152155
onDurationChange={durationChangeHandler}
153-
styles={customStyles}
156+
styles={styles.timerPickerStyles}
154157
/>
155158
<View
156159
{...buttonContainerProps}

src/components/TimerPickerModal/styles.ts

+63-23
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,54 @@ const LIGHT_MODE_BACKGROUND_COLOR = "#F1F1F1";
1919
const LIGHT_MODE_TEXT_COLOR = "#1B1B1B";
2020

2121
export const generateStyles = (
22-
customStyles: CustomTimerPickerModalStyles | undefined
23-
) =>
24-
StyleSheet.create({
22+
customStyles: CustomTimerPickerModalStyles | undefined,
23+
variables?: {
24+
hasModalTitle: boolean;
25+
}
26+
) => {
27+
const {
28+
button: customButtonStyle,
29+
buttonContainer: customButtonContainerStyle,
30+
cancelButton: customCancelButtonStyle,
31+
confirmButton: customConfirmButtonStyle,
32+
container: customContainerStyle,
33+
contentContainer: customContentContainerStyle,
34+
modalTitle: customModalTitleStyle,
35+
...customTimerPickerStyles
36+
} = customStyles ?? {};
37+
38+
return StyleSheet.create({
2539
container: {
2640
justifyContent: "center",
27-
alignItems: "center",
2841
overflow: "hidden",
29-
...customStyles?.container,
42+
...customContainerStyle,
43+
// disable setting alignItems here because it can affect
44+
// the FlatList's ability to calculate its layout, which can
45+
// stop snapToOffsets working properly
46+
alignItems: undefined,
3047
},
3148
contentContainer: {
3249
backgroundColor:
33-
customStyles?.backgroundColor ??
34-
(customStyles?.theme === "dark"
50+
customTimerPickerStyles?.backgroundColor ??
51+
(customTimerPickerStyles?.theme === "dark"
3552
? DARK_MODE_BACKGROUND_COLOR
3653
: LIGHT_MODE_BACKGROUND_COLOR),
3754
justifyContent: "center",
3855
alignItems: "center",
3956
borderRadius: 20,
40-
padding: 20,
41-
...customStyles?.contentContainer,
57+
overflow: "hidden",
58+
...customContentContainerStyle,
59+
// disable setting padding here because it can affect
60+
// the FlatList's ability to calculate its layout, which can
61+
// stop snapToOffsets working properly
62+
paddingHorizontal: 0,
63+
paddingVertical: 0,
4264
},
4365
buttonContainer: {
4466
flexDirection: "row",
4567
marginTop: 25,
46-
...customStyles?.buttonContainer,
68+
marginBottom: 20,
69+
...customButtonContainerStyle,
4770
},
4871
button: {
4972
marginHorizontal: 12,
@@ -53,36 +76,53 @@ export const generateStyles = (
5376
borderRadius: 10,
5477
fontSize: 16,
5578
overflow: "hidden",
56-
...customStyles?.text,
57-
...customStyles?.button,
79+
...customTimerPickerStyles?.text,
80+
...customButtonStyle,
5881
},
5982
cancelButton: {
6083
borderColor: "gray",
6184
color:
62-
customStyles?.theme === "dark" ? DARK_MODE_TEXT_COLOR : "gray",
85+
customTimerPickerStyles?.theme === "dark"
86+
? DARK_MODE_TEXT_COLOR
87+
: "gray",
6388
backgroundColor:
64-
customStyles?.theme === "dark" ? "gray" : undefined,
65-
...customStyles?.text,
66-
...customStyles?.cancelButton,
89+
customTimerPickerStyles?.theme === "dark" ? "gray" : undefined,
90+
...customTimerPickerStyles?.text,
91+
...customCancelButtonStyle,
6792
},
6893
confirmButton: {
6994
borderColor: "green",
7095
color:
71-
customStyles?.theme === "dark" ? DARK_MODE_TEXT_COLOR : "green",
96+
customTimerPickerStyles?.theme === "dark"
97+
? DARK_MODE_TEXT_COLOR
98+
: "green",
7299
backgroundColor:
73-
customStyles?.theme === "dark" ? "green" : undefined,
74-
...customStyles?.text,
75-
...customStyles?.confirmButton,
100+
customTimerPickerStyles?.theme === "dark" ? "green" : undefined,
101+
...customTimerPickerStyles?.text,
102+
...customConfirmButtonStyle,
76103
},
77104
modalTitle: {
78105
fontSize: 24,
79106
fontWeight: "600",
107+
marginTop: 20,
80108
marginBottom: 15,
81109
color:
82-
customStyles?.theme === "dark"
110+
customTimerPickerStyles?.theme === "dark"
83111
? DARK_MODE_TEXT_COLOR
84112
: LIGHT_MODE_TEXT_COLOR,
85-
...customStyles?.text,
86-
...customStyles?.modalTitle,
113+
...customTimerPickerStyles?.text,
114+
...customModalTitleStyle,
115+
},
116+
timerPickerStyles: {
117+
...customTimerPickerStyles,
118+
pickerContainer: {
119+
// set padding here instead of on modal content container because it can affect
120+
// the FlatList's ability to calculate its layout, which can
121+
// stop snapToOffsets working properly
122+
paddingHorizontal: 20,
123+
paddingTop: !variables?.hasModalTitle ? 20 : 0,
124+
...(customTimerPickerStyles?.pickerContainer ?? {}),
125+
},
87126
},
88127
});
128+
};

src/utils/getSafeInitialValue.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const getSafeInitialValue = (
2+
initialValue:
3+
| {
4+
hours?: number;
5+
minutes?: number;
6+
seconds?: number;
7+
}
8+
| undefined
9+
) => ({
10+
hours:
11+
typeof initialValue?.hours === "number" && !isNaN(initialValue?.hours)
12+
? initialValue.hours
13+
: 0,
14+
minutes:
15+
typeof initialValue?.minutes === "number" &&
16+
!isNaN(initialValue?.minutes)
17+
? initialValue.minutes
18+
: 0,
19+
seconds:
20+
typeof initialValue?.seconds === "number" &&
21+
!isNaN(initialValue?.seconds)
22+
? initialValue.seconds
23+
: 0,
24+
});

0 commit comments

Comments
 (0)