diff --git a/android/App.tsx b/android/App.tsx index ecc29bd..b299f61 100644 --- a/android/App.tsx +++ b/android/App.tsx @@ -1,48 +1,39 @@ -import Constants from "expo-constants"; -import { randomUUID } from "expo-crypto"; import { StatusBar } from "expo-status-bar"; -import { useCallback, useRef, useState } from "react"; +import { useCallback, useState } from "react"; import { Button, StyleSheet, Text, View } from "react-native"; -import WebView, { WebViewMessageEvent } from "react-native-webview"; +import { WasmContextProvider, useWasm } from "./components/WasmContextProvider"; +import Constants from "expo-constants"; -export default function App() { +function MyApp(): JSX.Element { + const { call } = useWasm(); const [count, setCount] = useState(0); - const backendBaseUrl = Constants.expoConfig?.extra?.backendBaseUrl ?? null; - if (backendBaseUrl === null) - throw new Error("BACKEND_BASE_URL is not defined"); - const ref = useRef(null); - const uri = `${backendBaseUrl}/assets/index.html`; - const handleOnMessage = useCallback((event: WebViewMessageEvent): void => { - const message = JSON.parse(event.nativeEvent.data); - console.log("onMessage", message); - setCount(message.result); - }, []); const handleOnPress = useCallback((): void => { - const id = randomUUID(); - const message = { - id, - name: "add", - args: [count, 1], - }; - console.log("postMessage", message); - ref.current?.postMessage(JSON.stringify(message)); - }, [count, ref]); + (async () => { + const result = await call("add", [count, 1]); + setCount(result as number); + })(); + }, [count]); return ( - {count}