Skip to content

Commit 9cbd755

Browse files
author
Tim Roberts
committed
Merge branch 'patch-v1.2.6'
2 parents 25277c9 + 9e2c2ab commit 9cbd755

File tree

4 files changed

+35
-40
lines changed

4 files changed

+35
-40
lines changed

example/App.tsx

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import React, { useMemo, useState } from "react";
22
import {
3-
Dimensions,
43
ScrollView,
54
StyleSheet,
65
Text,
76
TouchableOpacity,
87
View,
8+
useWindowDimensions,
99
} from "react-native";
1010
import { LinearGradient } from "expo-linear-gradient";
1111

1212
import { TimerPicker, TimerPickerModal } from "./src";
1313

1414
import { formatTime } from "./utils/formatTime";
1515

16-
const { width: screenWidth } = Dimensions.get("window");
17-
1816
export default function App() {
17+
const { width: screenWidth } = useWindowDimensions();
18+
1919
const [showPickerExample1, setShowPickerExample1] = useState(false);
2020
const [showPickerExample2, setShowPickerExample2] = useState(false);
2121
const [alarmStringExample1, setAlarmStringExample1] = useState<
@@ -27,7 +27,12 @@ export default function App() {
2727

2828
const renderExample1 = useMemo(() => {
2929
return (
30-
<View style={[styles.container, styles.page1Container]}>
30+
<View
31+
style={[
32+
styles.container,
33+
styles.page1Container,
34+
{ width: screenWidth },
35+
]}>
3136
<Text style={styles.textDark}>
3237
{alarmStringExample1 !== null
3338
? "Alarm set for"
@@ -74,11 +79,16 @@ export default function App() {
7479
/>
7580
</View>
7681
);
77-
}, [alarmStringExample1, showPickerExample1]);
82+
}, [alarmStringExample1, screenWidth, showPickerExample1]);
7883

7984
const renderExample2 = useMemo(() => {
8085
return (
81-
<View style={[styles.container, styles.page2Container]}>
86+
<View
87+
style={[
88+
styles.container,
89+
styles.page2Container,
90+
{ width: screenWidth },
91+
]}>
8292
<Text style={styles.textLight}>
8393
{alarmStringExample2 !== null
8494
? "Alarm set for"
@@ -122,11 +132,16 @@ export default function App() {
122132
/>
123133
</View>
124134
);
125-
}, [alarmStringExample2, showPickerExample2]);
135+
}, [alarmStringExample2, screenWidth, showPickerExample2]);
126136

127137
const renderExample3 = useMemo(() => {
128138
return (
129-
<View style={[styles.container, styles.page3Container]}>
139+
<View
140+
style={[
141+
styles.container,
142+
styles.page3Container,
143+
{ width: screenWidth },
144+
]}>
130145
<TimerPicker
131146
padWithNItems={2}
132147
hourLabel=":"
@@ -150,11 +165,16 @@ export default function App() {
150165
/>
151166
</View>
152167
);
153-
}, []);
168+
}, [screenWidth]);
154169

155170
const renderExample4 = useMemo(() => {
156171
return (
157-
<View style={[styles.container, styles.page4Container]}>
172+
<View
173+
style={[
174+
styles.container,
175+
styles.page4Container,
176+
{ width: screenWidth },
177+
]}>
158178
<TimerPicker
159179
padWithNItems={3}
160180
hideHours
@@ -180,7 +200,7 @@ export default function App() {
180200
/>
181201
</View>
182202
);
183-
}, []);
203+
}, [screenWidth]);
184204

185205
return (
186206
<ScrollView horizontal pagingEnabled>
@@ -196,7 +216,6 @@ const styles = StyleSheet.create({
196216
container: {
197217
alignItems: "center",
198218
justifyContent: "center",
199-
width: screenWidth,
200219
},
201220
page1Container: {
202221
backgroundColor: "#514242",

example/app.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"name": "example",
44
"slug": "example",
55
"version": "1.0.0",
6-
"orientation": "portrait",
76
"icon": "./assets/icon.png",
87
"userInterfaceStyle": "light",
98
"splash": {

package.json

Lines changed: 1 addition & 1 deletion
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": "1.2.5",
9+
"version": "1.2.6",
1010
"main": "dist/index.js",
1111
"types": "dist/index.d.ts",
1212
"scripts": {

src/components/Modal/index.tsx

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import React, { useCallback, useEffect, useRef, useState } from "react";
2+
import React, { useCallback, useEffect, useRef } from "react";
33
import {
44
Animated,
5-
DeviceEventEmitter,
6-
Dimensions,
75
Easing,
86
Modal as ReactNativeModal,
97
TouchableWithoutFeedback,
8+
useWindowDimensions,
109
} from "react-native";
1110

1211
import { styles } from "./Modal.styles";
@@ -36,40 +35,18 @@ export const Modal = ({
3635
overlayStyle,
3736
testID,
3837
}: ModalProps): React.ReactElement => {
39-
const [screenHeight, setScreenHeight] = useState(
40-
Dimensions.get("window").height
41-
);
42-
const [screenWidth, setScreenWidth] = useState(
43-
Dimensions.get("window").width
44-
);
38+
const { width: screenWidth, height: screenHeight } = useWindowDimensions();
4539

4640
const isMounted = useRef(false);
4741
const animatedOpacity = useRef(new Animated.Value(0));
4842

49-
const handleDimensionsUpdate = (dimensionsUpdate: any) => {
50-
const updatedScreenWidth = dimensionsUpdate.window.width;
51-
const updateadScreenHeight = dimensionsUpdate.window.height;
52-
if (
53-
updatedScreenWidth !== screenWidth ||
54-
updateadScreenHeight !== screenHeight
55-
) {
56-
setScreenHeight(updateadScreenHeight);
57-
setScreenWidth(updatedScreenWidth);
58-
}
59-
};
60-
6143
useEffect(() => {
6244
isMounted.current = true;
6345
if (isVisible) {
6446
show();
6547
}
66-
const deviceEventEmitter = DeviceEventEmitter.addListener(
67-
"didUpdateDimensions",
68-
handleDimensionsUpdate
69-
);
7048

7149
return () => {
72-
deviceEventEmitter.remove();
7350
isMounted.current = false;
7451
};
7552
// eslint-disable-next-line react-hooks/exhaustive-deps

0 commit comments

Comments
 (0)