diff --git a/example/App.tsx b/example/App.tsx index e9f7a93..00842c9 100644 --- a/example/App.tsx +++ b/example/App.tsx @@ -1,11 +1,11 @@ import React, { useMemo, useState } from "react"; import { - Dimensions, ScrollView, StyleSheet, Text, TouchableOpacity, View, + useWindowDimensions, } from "react-native"; import { LinearGradient } from "expo-linear-gradient"; @@ -13,9 +13,9 @@ import { TimerPicker, TimerPickerModal } from "./src"; import { formatTime } from "./utils/formatTime"; -const { width: screenWidth } = Dimensions.get("window"); - export default function App() { + const { width: screenWidth } = useWindowDimensions(); + const [showPickerExample1, setShowPickerExample1] = useState(false); const [showPickerExample2, setShowPickerExample2] = useState(false); const [alarmStringExample1, setAlarmStringExample1] = useState< @@ -27,7 +27,12 @@ export default function App() { const renderExample1 = useMemo(() => { return ( - + {alarmStringExample1 !== null ? "Alarm set for" @@ -74,11 +79,16 @@ export default function App() { /> ); - }, [alarmStringExample1, showPickerExample1]); + }, [alarmStringExample1, screenWidth, showPickerExample1]); const renderExample2 = useMemo(() => { return ( - + {alarmStringExample2 !== null ? "Alarm set for" @@ -122,11 +132,16 @@ export default function App() { /> ); - }, [alarmStringExample2, showPickerExample2]); + }, [alarmStringExample2, screenWidth, showPickerExample2]); const renderExample3 = useMemo(() => { return ( - + ); - }, []); + }, [screenWidth]); const renderExample4 = useMemo(() => { return ( - + ); - }, []); + }, [screenWidth]); return ( @@ -196,7 +216,6 @@ const styles = StyleSheet.create({ container: { alignItems: "center", justifyContent: "center", - width: screenWidth, }, page1Container: { backgroundColor: "#514242", diff --git a/example/app.json b/example/app.json index 05e5eb2..9592555 100644 --- a/example/app.json +++ b/example/app.json @@ -3,7 +3,6 @@ "name": "example", "slug": "example", "version": "1.0.0", - "orientation": "portrait", "icon": "./assets/icon.png", "userInterfaceStyle": "light", "splash": { diff --git a/package.json b/package.json index c475f1c..ba3ea78 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "url": "https://github.com/troberts-28" }, "license": "MIT", - "version": "1.2.5", + "version": "1.2.6", "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { diff --git a/src/components/Modal/index.tsx b/src/components/Modal/index.tsx index 523595b..8a6d5f8 100644 --- a/src/components/Modal/index.tsx +++ b/src/components/Modal/index.tsx @@ -1,12 +1,11 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import React, { useCallback, useEffect, useRef, useState } from "react"; +import React, { useCallback, useEffect, useRef } from "react"; import { Animated, - DeviceEventEmitter, - Dimensions, Easing, Modal as ReactNativeModal, TouchableWithoutFeedback, + useWindowDimensions, } from "react-native"; import { styles } from "./Modal.styles"; @@ -36,40 +35,18 @@ export const Modal = ({ overlayStyle, testID, }: ModalProps): React.ReactElement => { - const [screenHeight, setScreenHeight] = useState( - Dimensions.get("window").height - ); - const [screenWidth, setScreenWidth] = useState( - Dimensions.get("window").width - ); + const { width: screenWidth, height: screenHeight } = useWindowDimensions(); const isMounted = useRef(false); const animatedOpacity = useRef(new Animated.Value(0)); - const handleDimensionsUpdate = (dimensionsUpdate: any) => { - const updatedScreenWidth = dimensionsUpdate.window.width; - const updateadScreenHeight = dimensionsUpdate.window.height; - if ( - updatedScreenWidth !== screenWidth || - updateadScreenHeight !== screenHeight - ) { - setScreenHeight(updateadScreenHeight); - setScreenWidth(updatedScreenWidth); - } - }; - useEffect(() => { isMounted.current = true; if (isVisible) { show(); } - const deviceEventEmitter = DeviceEventEmitter.addListener( - "didUpdateDimensions", - handleDimensionsUpdate - ); return () => { - deviceEventEmitter.remove(); isMounted.current = false; }; // eslint-disable-next-line react-hooks/exhaustive-deps