找回密码
 注册免广告
搜索
人人必备的 Wise 💳华侨银行送 15 新加坡币 🎁个人 IBAN 出金,注册送 $25 比特币 ฿数字货币银行卡,注册送 7 美元💲
查看: 645|回复: 0

用React Native将论坛打包成App

[复制链接]

465

主题

5019

回帖

1万

积分

版主

积分
12108
HelloWorld 发表于 2023-4-15 14:58:52 | 显示全部楼层 |阅读模式
本帖最后由 HelloWorld 于 2023-4-15 14:59 编辑

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

  • 创建expo项目:https://docs.expo.dev/guides/typ ... typescript-template
    1. yarn create expo-app project-name --template expo-template-blank-typescript
    复制代码

  • 安装webview扩展:https://docs.expo.dev/versions/latest/sdk/webview/
    1. npx expo install react-native-webview
    复制代码

  • 编辑App.ts文件
    1. import { useEffect, useRef } from 'react'
    2. import { WebView } from 'react-native-webview'
    3. import { BackHandler, StatusBar, SafeAreaView } from 'react-native'

    4. export default function App() {
    5.   const webViewRef = useRef(null)
    6.   useEffect(() => {
    7.     const backHandler = BackHandler.addEventListener(
    8.       'hardwareBackPress',
    9.       () => {
    10.         if (webViewRef.current) {
    11.           (webViewRef.current as any).goBack()
    12.           return true
    13.         }
    14.         return false
    15.       }
    16.     )
    17.     return () => backHandler.remove()
    18.   }, [])
    19.   return (
    20.     <>
    21.       <StatusBar barStyle='light-content' />
    22.       <SafeAreaView style={{ flex:0, backgroundColor: '#000000' }} />
    23.       <SafeAreaView style={{ flex:1, backgroundColor: '#000000' }}>
    24.         <WebView
    25.           ref={webViewRef}
    26.           source={{ uri: 'https://shuzijumin.com' }}
    27.           allowsBackForwardNavigationGestures
    28.         />
    29.       </SafeAreaView>
    30.     </>
    31.   )
    32. }
    复制代码

  • 编译apk:https://docs.expo.dev/build-reference/apk/
您需要登录后才可以回帖 登录 | 注册免广告

本版积分规则

排行榜|意见建议|数字居民论坛

GMT+8, 2024-5-20 14:02

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表