Skip to content

Commit 880e6f0

Browse files
author
Tim Roberts
committed
📝 make example work in landscape (and with switching orientations)
1 parent be5fe20 commit 880e6f0

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
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": {

0 commit comments

Comments
 (0)