-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ useEffect 땜에 첫 랜더링이 안되는 에러 onLoad써서 처리함
- Loading branch information
Showing
1 changed file
with
41 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,46 @@ | ||
import * as React from "react"; | ||
import { WebView } from "react-native-webview"; | ||
import { StyleSheet, View, StatusBar } from "react-native"; | ||
import Constants from "expo-constants"; | ||
import React, { useEffect, useRef } from 'react'; | ||
import { WebView, WebViewMessageEvent } from 'react-native-webview'; | ||
import { StyleSheet, View, StatusBar } from 'react-native'; | ||
import Constants from 'expo-constants'; | ||
|
||
export default function App() { | ||
return ( | ||
<> | ||
<View style={styles.statusbar}> | ||
<StatusBar backgroundColor="transparent" barStyle="dark-content" translucent={true} /> | ||
</View> | ||
<WebView | ||
style={styles.container} | ||
source={{ uri: "http://localhost:3000/auth" }} | ||
allowsBackForwardNavigationGestures={true} | ||
/> | ||
</> | ||
); | ||
export default function App(): React.ReactElement { | ||
const statusBarHeight: number = Constants.statusBarHeight; | ||
const webViewRef = useRef<WebView>(null); | ||
|
||
const handleWebViewLoad = () => { | ||
webViewRef.current?.postMessage(statusBarHeight.toString()); | ||
}; | ||
|
||
useEffect(() => { | ||
if (webViewRef.current) { | ||
webViewRef.current.postMessage(statusBarHeight.toString()); | ||
} | ||
}, [statusBarHeight]); | ||
|
||
return ( | ||
<> | ||
<View style={styles.statusbar}> | ||
<StatusBar | ||
backgroundColor='transparent' | ||
barStyle='dark-content' | ||
translucent={true} | ||
/> | ||
</View> | ||
<WebView | ||
style={styles.container} | ||
source={{ uri: 'http://localhost:3000/auth' }} | ||
ref={webViewRef} | ||
onLoad={handleWebViewLoad} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
}, | ||
statusbar: { | ||
backgroundColor: 'transparent', | ||
} | ||
container: { | ||
flex: 1, | ||
}, | ||
statusbar: { | ||
backgroundColor: 'transparent', | ||
}, | ||
}); |