forked from expo/match-media
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
53 lines (49 loc) · 1.6 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import "./build";
import React from "react";
import { useMediaQuery } from "react-responsive";
import { View, Platform, Text } from "react-native";
function Header({ style, ...props } = {}) {
return (
<Text
accessibilityLabel="header"
style={[
{
fontWeight: "bold",
marginBottom: 24,
fontSize: Platform.select({ web: "2.25rem", default: 2.25 * 16 })
},
style
]}
{...props}
/>
);
}
export default function App() {
const isDesktopOrLaptop = useMediaQuery({
query: "(min-device-width: 1224px)"
});
const isBigScreen = useMediaQuery({ query: "(min-device-width: 1824px)" });
const isTabletOrMobile = useMediaQuery({ query: "(max-width: 1224px)" });
const isTabletOrMobileDevice = useMediaQuery({
query: "(max-device-width: 1224px)"
});
const isPortrait = useMediaQuery({ query: "(orientation: portrait)" });
const isRetina = useMediaQuery({ query: "(min-resolution: 2dppx)" });
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Header>Device Test!</Header>
{isDesktopOrLaptop && (
<>
<Text>You are a desktop or laptop</Text>
{isBigScreen && <Text>You also have a huge screen</Text>}
{isTabletOrMobile && <Text>You are sized like a tablet or mobile phone though</Text>}
</>
)}
{isTabletOrMobileDevice && <Text>You are a tablet or mobile phone</Text>}
<Text>
Your are in {isPortrait ? "portrait" : "landscape"} orientation
</Text>
{isRetina && <Text>You are retina</Text>}
</View>
);
}