웹뷰앱 뒤로가기


  • Level 5

    웹뷰로 앱을 만들었습니다
    안드로이드에서는 뒤로가기 터치시 앱이 아에 꺼지는 현상이 있다고 해서

    import * as React from 'react';
    import { WebView } from 'react-native-webview';
    const webview = useRef<WebView>(null);
      
      const onAndroidBackPress = (): boolean => {
        if (webview.current) {
          webview.current.goBack();
          return true; // prevent default behavior (exit app)
        }
        return false;
      };
    
      useEffect((): (() => void) => {
        BackHandler.addEventListener('hardwareBackPress', onAndroidBackPress);
        return (): void => {
          BackHandler.removeEventListener('hardwareBackPress', onAndroidBackPress);
        };
      }, []); // Never re-run this effect
    export default class App extends React.Component {
      render() {
        return <WebView source={{ uri: 'https://1st-cafe.com/' }} style={{ marginTop: 20 }} />;
      }
    }
    

    찾아보고 참고하여 이렇게 했는데요
    expo build:android 로 앱을 받아서 실행하니 로딩화면만 나오고 앱이 종료됩니다
    구름ide에 실행으로 expo 앱으로도 해보았는데 작동하지 않네요..

POPULAR TOPICS

SUGGESTED TOPICS