HelloWorld 发表于 2023-4-15 14:58:52

用React Native将论坛打包成App

本帖最后由 HelloWorld 于 2023-4-15 14:59 编辑

Apk下载地址:com.shuzijumin.app_1.0.0_1.apk


[*]创建expo项目:https://docs.expo.dev/guides/typ ... typescript-template
yarn create expo-app project-name --template expo-template-blank-typescript
[*]安装webview扩展:https://docs.expo.dev/versions/latest/sdk/webview/
npx expo install react-native-webview
[*]编辑App.ts文件
import { useEffect, useRef } from 'react'
import { WebView } from 'react-native-webview'
import { BackHandler, StatusBar, SafeAreaView } from 'react-native'

export default function App() {
const webViewRef = useRef(null)
useEffect(() => {
    const backHandler = BackHandler.addEventListener(
      'hardwareBackPress',
      () => {
      if (webViewRef.current) {
          (webViewRef.current as any).goBack()
          return true
      }
      return false
      }
    )
    return () => backHandler.remove()
}, [])
return (
    <>
      <StatusBar barStyle='light-content' />
      <SafeAreaView style={{ flex:0, backgroundColor: '#000000' }} />
      <SafeAreaView style={{ flex:1, backgroundColor: '#000000' }}>
      <WebView
          ref={webViewRef}
          source={{ uri: 'https://shuzijumin.com' }}
          allowsBackForwardNavigationGestures
      />
      </SafeAreaView>
    </>
)
}
[*]编译apk:https://docs.expo.dev/build-reference/apk/
页: [1]
查看完整版本: 用React Native将论坛打包成App