-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
73 lines (68 loc) · 2.03 KB
/
App.tsx
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import WebView, { WebViewMessageEvent } from "react-native-webview";
import { useState } from "react";
import { match } from "ts-pattern";
import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
export default function App() {
const [safeMode, setSafeMode] = useState<"top" | "bottom" | "all" | "none">(
"all"
);
const [topBackground, setTopBackground] = useState("#F1F1E7");
const [bottomBackground, setBottomBackground] = useState("#FFFFFF");
const handleMessage = (event: WebViewMessageEvent) => {
const { type, payload } = JSON.parse(event.nativeEvent.data);
switch (type) {
case "setSafeMode":
setSafeMode(payload);
match(payload as "top" | "bottom" | "all")
.with("all", () => {
setTopBackground("#F1F1E7");
setBottomBackground("#FFFFFF");
})
.with("top", () => {
setTopBackground("#F1F1E7");
})
.with("bottom", () => {
setBottomBackground("#FFFFFF");
});
break;
case "setTopBackground":
setTopBackground(payload);
break;
case "setBottomBackground":
setBottomBackground(payload);
break;
default:
break;
}
};
return (
<SafeAreaProvider>
{match(safeMode)
.with("all", "top", () => (
<SafeAreaView
edges={["top"]}
accessibilityIgnoresInvertColors={true}
style={{ backgroundColor: topBackground }}
/>
))
.otherwise(() => null)}
<WebView
source={{
uri: "https://refri-webview.vercel.app",
}}
textZoom={100}
onMessage={handleMessage}
decelerationRate="normal"
allowsBackForwardNavigationGestures
/>
{match(safeMode)
.with("all", "bottom", () => (
<SafeAreaView
edges={["bottom"]}
style={{ backgroundColor: bottomBackground }}
/>
))
.otherwise(() => null)}
</SafeAreaProvider>
);
}