feat(navigation): 实现原生导航模块并优化项目结构
- 新增 NavigationManager 和 NavigationPackage 类,实现原生导航功能 - 更新 MainApplication,集成导航模块- 修改 App.tsx,使用新导航模块进行页面跳转 - 优化 NavigationHelper,使用新的消息格式 - 更新 Hospital.tsx,改进页面展示 - 引入 babel-plugin-module-resolver 和更新 tsconfig,优化项目路径配置
这个提交包含在:
父节点
da6c39d068
当前提交
2047b101ca
@ -9,6 +9,7 @@ import com.facebook.react.ReactNativeHost
|
||||
import com.facebook.react.ReactPackage
|
||||
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
|
||||
import com.facebook.react.defaults.DefaultReactNativeHost
|
||||
import com.trust.ywx.specs.navigation.NavigationPackage
|
||||
|
||||
class MainApplication : Application(), ReactApplication {
|
||||
|
||||
@ -17,7 +18,7 @@ class MainApplication : Application(), ReactApplication {
|
||||
override fun getPackages(): List<ReactPackage> =
|
||||
PackageList(this).packages.apply {
|
||||
// Packages that cannot be autolinked yet can be added manually here, for example:
|
||||
// add(MyReactNativePackage())
|
||||
add(NavigationPackage())
|
||||
}
|
||||
|
||||
override fun getJSMainModuleName(): String = "index"
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
package com.trust.ywx.specs
|
||||
|
||||
package com.trust.ywx.specs.navigation
|
||||
|
||||
import android.content.Intent
|
||||
import com.facebook.react.bridge.ReactApplicationContext
|
||||
import com.trust.ywx.AppManager
|
||||
import com.trust.ywx.BuzActivity
|
||||
import com.trust.ywx.specs.NativeNavigationManagerSpec
|
||||
import com.trust.ywx.specs.navigation.NavigationHelper
|
||||
|
||||
class NavigationManager(reactContext: ReactApplicationContext) :
|
||||
NativeNavigationManagerSpec(reactContext) {
|
||||
@ -20,4 +18,8 @@ class NavigationManager(reactContext: ReactApplicationContext) :
|
||||
|
||||
}
|
||||
|
||||
override fun getName() = NAME
|
||||
companion object {
|
||||
const val NAME = "NavigationManager"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package com.trust.ywx.specs.navigation
|
||||
|
||||
import com.facebook.react.BaseReactPackage
|
||||
import com.facebook.react.bridge.NativeModule
|
||||
import com.facebook.react.bridge.ReactApplicationContext
|
||||
import com.facebook.react.module.model.ReactModuleInfo
|
||||
import com.facebook.react.module.model.ReactModuleInfoProvider
|
||||
|
||||
class NavigationPackage : BaseReactPackage() {
|
||||
override fun getModule(
|
||||
name: String,
|
||||
reactContext: ReactApplicationContext
|
||||
): NativeModule? = if (name == NavigationManager.NAME) {
|
||||
NavigationManager(reactContext)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
override fun getReactModuleInfoProvider() = ReactModuleInfoProvider {
|
||||
mapOf(
|
||||
NavigationManager.NAME to ReactModuleInfo(
|
||||
name = NavigationManager.NAME,
|
||||
className = NavigationManager.NAME,
|
||||
canOverrideExistingModule = false,
|
||||
needsEagerInit = false,
|
||||
isCxxModule = false,
|
||||
isTurboModule = true
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,18 @@
|
||||
module.exports = {
|
||||
presets: ['module:@react-native/babel-preset'],
|
||||
plugins: [
|
||||
[
|
||||
'module-resolver',
|
||||
{
|
||||
root: ['.'],
|
||||
alias: {
|
||||
'@': './src',
|
||||
'@ywx': './src/ywq',
|
||||
'@app': './src/app',
|
||||
'@hospital': './src/hospital',
|
||||
'@common': './src/common',
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
"dependencies": {
|
||||
"@react-native-async-storage/async-storage": "^2.2.0",
|
||||
"@react-native/new-app-screen": "0.80.1",
|
||||
"babel-plugin-module-resolver": "^5.0.2",
|
||||
"react": "19.1.0",
|
||||
"react-native": "0.80.1",
|
||||
"react-native-storage": "^1.0.1"
|
||||
|
||||
@ -12,7 +12,7 @@ import {
|
||||
useColorScheme,
|
||||
View,
|
||||
} from 'react-native';
|
||||
import { pushByName } from '../common/NavigationHelper.ts';
|
||||
import * as navigation from '@common/NavigationHelper.ts';
|
||||
|
||||
function App() {
|
||||
const isDarkMode = useColorScheme() === 'dark';
|
||||
@ -24,7 +24,8 @@ function App() {
|
||||
<Button
|
||||
title={'进入互联网医院'}
|
||||
onPress={() => {
|
||||
pushByName('hospital', {});
|
||||
console.log('>>>>', navigation);
|
||||
navigation.pushByName('hospital', {});
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
|
||||
@ -4,7 +4,7 @@ import NavigationManager from '../../specs/NativeNavigationManager.ts';
|
||||
export const pushByName = (name: string, params: any) => {
|
||||
storageApp
|
||||
.save({
|
||||
key: `MessageActivity_${name}`,
|
||||
key: `MessageActivity-${name}`,
|
||||
data: params,
|
||||
expires: 1000 * 3600,
|
||||
})
|
||||
@ -13,7 +13,7 @@ export const pushByName = (name: string, params: any) => {
|
||||
});
|
||||
};
|
||||
export const pop = (name: string) => {
|
||||
storageApp.remove({ key: `MessageActivity_${name}` }).finally(() => {
|
||||
storageApp.remove({ key: `MessageActivity-${name}` }).finally(() => {
|
||||
NavigationManager.pop(name);
|
||||
});
|
||||
};
|
||||
|
||||
@ -9,6 +9,7 @@ import {
|
||||
Button,
|
||||
StatusBar,
|
||||
StyleSheet,
|
||||
Text,
|
||||
useColorScheme,
|
||||
View,
|
||||
} from 'react-native';
|
||||
@ -21,7 +22,7 @@ function Hospital() {
|
||||
<View style={styles.container}>
|
||||
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
|
||||
<View style={{ height: 100 }} />
|
||||
<View>互联网医院</View>
|
||||
<Text>互联网医院</Text>
|
||||
<Button
|
||||
title={'返回'}
|
||||
onPress={() => {
|
||||
|
||||
@ -1,3 +1,25 @@
|
||||
{
|
||||
"extends": "@react-native/typescript-config"
|
||||
"extends": "@react-native/typescript-config",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
],
|
||||
"@ywx/*": [
|
||||
"src/ywq/*"
|
||||
],
|
||||
"@app/*": [
|
||||
"src/app/*"
|
||||
],
|
||||
"@hospital/*": [
|
||||
"src/hospital/*"
|
||||
],
|
||||
"@common/*": [
|
||||
"src/common/*"
|
||||
],
|
||||
},
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true
|
||||
}
|
||||
}
|
||||
|
||||
101
yarn.lock
101
yarn.lock
@ -2305,6 +2305,17 @@ babel-plugin-jest-hoist@^29.6.3:
|
||||
"@types/babel__core" "^7.1.14"
|
||||
"@types/babel__traverse" "^7.0.6"
|
||||
|
||||
babel-plugin-module-resolver@^5.0.2:
|
||||
version "5.0.2"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/babel-plugin-module-resolver/-/babel-plugin-module-resolver-5.0.2.tgz#cdeac5d4aaa3b08dd1ac23ddbf516660ed2d293e"
|
||||
integrity sha512-9KtaCazHee2xc0ibfqsDeamwDps6FZNo5S0Q81dUqEuFzVwPhcT4J5jOqIVvgCA3Q/wO9hKYxN/Ds3tIsp5ygg==
|
||||
dependencies:
|
||||
find-babel-config "^2.1.1"
|
||||
glob "^9.3.3"
|
||||
pkg-up "^3.1.0"
|
||||
reselect "^4.1.7"
|
||||
resolve "^1.22.8"
|
||||
|
||||
babel-plugin-polyfill-corejs2@^0.4.14:
|
||||
version "0.4.14"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.4.14.tgz"
|
||||
@ -3502,6 +3513,20 @@ finalhandler@1.1.2:
|
||||
statuses "~1.5.0"
|
||||
unpipe "~1.0.0"
|
||||
|
||||
find-babel-config@^2.1.1:
|
||||
version "2.1.2"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/find-babel-config/-/find-babel-config-2.1.2.tgz#2841b1bfbbbcdb971e1e39df8cbc43dafa901716"
|
||||
integrity sha512-ZfZp1rQyp4gyuxqt1ZqjFGVeVBvmpURMqdIWXbPRfB97Bf6BzdK/xSIbylEINzQ0kB5tlDQfn9HkNXXWsqTqLg==
|
||||
dependencies:
|
||||
json5 "^2.2.3"
|
||||
|
||||
find-up@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/find-up/-/find-up-3.0.0.tgz#49169f1d7993430646da61ecc5ae355c21c97b73"
|
||||
integrity sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==
|
||||
dependencies:
|
||||
locate-path "^3.0.0"
|
||||
|
||||
find-up@^4.0.0, find-up@^4.1.0:
|
||||
version "4.1.0"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/find-up/-/find-up-4.1.0.tgz"
|
||||
@ -3669,6 +3694,16 @@ glob@^7.1.1, glob@^7.1.3, glob@^7.1.4:
|
||||
once "^1.3.0"
|
||||
path-is-absolute "^1.0.0"
|
||||
|
||||
glob@^9.3.3:
|
||||
version "9.3.5"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/glob/-/glob-9.3.5.tgz#ca2ed8ca452781a3009685607fdf025a899dfe21"
|
||||
integrity sha512-e1LleDykUz2Iu+MTYdkSsuWX8lvAjAcs0Xef0lNIu0S2wOAzuTxCJtcd9S3cijlwYF18EsU3rzb8jPVobxDh9Q==
|
||||
dependencies:
|
||||
fs.realpath "^1.0.0"
|
||||
minimatch "^8.0.2"
|
||||
minipass "^4.2.4"
|
||||
path-scurry "^1.6.1"
|
||||
|
||||
globals@^13.19.0:
|
||||
version "13.24.0"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/globals/-/globals-13.24.0.tgz"
|
||||
@ -4748,6 +4783,14 @@ lines-and-columns@^1.1.6:
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/lines-and-columns/-/lines-and-columns-1.2.4.tgz"
|
||||
integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==
|
||||
|
||||
locate-path@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e"
|
||||
integrity sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==
|
||||
dependencies:
|
||||
p-locate "^3.0.0"
|
||||
path-exists "^3.0.0"
|
||||
|
||||
locate-path@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/locate-path/-/locate-path-5.0.0.tgz"
|
||||
@ -4806,6 +4849,11 @@ loose-envify@^1.0.0, loose-envify@^1.4.0:
|
||||
dependencies:
|
||||
js-tokens "^3.0.0 || ^4.0.0"
|
||||
|
||||
lru-cache@^10.2.0:
|
||||
version "10.4.3"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/lru-cache/-/lru-cache-10.4.3.tgz#410fc8a17b70e598013df257c2446b7f3383f119"
|
||||
integrity sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==
|
||||
|
||||
lru-cache@^5.1.1:
|
||||
version "5.1.1"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/lru-cache/-/lru-cache-5.1.1.tgz"
|
||||
@ -5109,6 +5157,13 @@ minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2:
|
||||
dependencies:
|
||||
brace-expansion "^1.1.7"
|
||||
|
||||
minimatch@^8.0.2:
|
||||
version "8.0.4"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/minimatch/-/minimatch-8.0.4.tgz#847c1b25c014d4e9a7f68aaf63dedd668a626229"
|
||||
integrity sha512-W0Wvr9HyFXZRGIDgCicunpQ299OKXs9RgZfaukz4qAW/pJhcpUfupc9c+OObPOFueNy8VSrZgEmDtk6Kh4WzDA==
|
||||
dependencies:
|
||||
brace-expansion "^2.0.1"
|
||||
|
||||
minimatch@^9.0.4:
|
||||
version "9.0.5"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/minimatch/-/minimatch-9.0.5.tgz"
|
||||
@ -5121,6 +5176,16 @@ minimist@1.2.0:
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/minimist/-/minimist-1.2.0.tgz"
|
||||
integrity sha512-7Wl+Jz+IGWuSdgsQEJ4JunV0si/iMhg42MnQQG6h1R6TNeVenp4U9x5CC5v/gYqz/fENLQITAWXidNtVL0NNbw==
|
||||
|
||||
minipass@^4.2.4:
|
||||
version "4.2.8"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/minipass/-/minipass-4.2.8.tgz#f0010f64393ecfc1d1ccb5f582bcaf45f48e1a3a"
|
||||
integrity sha512-fNzuVyifolSLFL4NzpF+wEF4qrgqaaKX0haXPQEdQ7NKAN+WecoKMHV09YcuL/DHxrUsYQOK3MiuDf7Ip2OXfQ==
|
||||
|
||||
"minipass@^5.0.0 || ^6.0.2 || ^7.0.0":
|
||||
version "7.1.2"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/minipass/-/minipass-7.1.2.tgz#93a9626ce5e5e66bd4db86849e7515e92340a707"
|
||||
integrity sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==
|
||||
|
||||
mkdirp@^1.0.4:
|
||||
version "1.0.4"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/mkdirp/-/mkdirp-1.0.4.tgz"
|
||||
@ -5386,7 +5451,7 @@ own-keys@^1.0.1:
|
||||
object-keys "^1.1.1"
|
||||
safe-push-apply "^1.0.0"
|
||||
|
||||
p-limit@^2.2.0:
|
||||
p-limit@^2.0.0, p-limit@^2.2.0:
|
||||
version "2.3.0"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/p-limit/-/p-limit-2.3.0.tgz"
|
||||
integrity sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==
|
||||
@ -5400,6 +5465,13 @@ p-limit@^3.0.2, p-limit@^3.1.0:
|
||||
dependencies:
|
||||
yocto-queue "^0.1.0"
|
||||
|
||||
p-locate@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/p-locate/-/p-locate-3.0.0.tgz#322d69a05c0264b25997d9f40cd8a891ab0064a4"
|
||||
integrity sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==
|
||||
dependencies:
|
||||
p-limit "^2.0.0"
|
||||
|
||||
p-locate@^4.1.0:
|
||||
version "4.1.0"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/p-locate/-/p-locate-4.1.0.tgz"
|
||||
@ -5449,6 +5521,11 @@ parseurl@~1.3.3:
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/parseurl/-/parseurl-1.3.3.tgz"
|
||||
integrity sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==
|
||||
|
||||
path-exists@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515"
|
||||
integrity sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==
|
||||
|
||||
path-exists@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/path-exists/-/path-exists-4.0.0.tgz"
|
||||
@ -5469,6 +5546,14 @@ path-parse@^1.0.7:
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/path-parse/-/path-parse-1.0.7.tgz"
|
||||
integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==
|
||||
|
||||
path-scurry@^1.6.1:
|
||||
version "1.11.1"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/path-scurry/-/path-scurry-1.11.1.tgz#7960a668888594a0720b12a911d1a742ab9f11d2"
|
||||
integrity sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==
|
||||
dependencies:
|
||||
lru-cache "^10.2.0"
|
||||
minipass "^5.0.0 || ^6.0.2 || ^7.0.0"
|
||||
|
||||
path-type@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/path-type/-/path-type-4.0.0.tgz"
|
||||
@ -5508,6 +5593,13 @@ pkg-dir@^4.2.0:
|
||||
dependencies:
|
||||
find-up "^4.0.0"
|
||||
|
||||
pkg-up@^3.1.0:
|
||||
version "3.1.0"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/pkg-up/-/pkg-up-3.1.0.tgz#100ec235cc150e4fd42519412596a28512a0def5"
|
||||
integrity sha512-nDywThFk1i4BQK4twPQ6TA4RT8bDY96yeuCVBWL3ePARCiEKDRSrNGbFIgUJpLp+XeIR65v8ra7WuJOFUBtkMA==
|
||||
dependencies:
|
||||
find-up "^3.0.0"
|
||||
|
||||
possible-typed-array-names@^1.0.0:
|
||||
version "1.1.0"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz"
|
||||
@ -5801,6 +5893,11 @@ require-main-filename@^2.0.0:
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/require-main-filename/-/require-main-filename-2.0.0.tgz"
|
||||
integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==
|
||||
|
||||
reselect@^4.1.7:
|
||||
version "4.1.8"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/reselect/-/reselect-4.1.8.tgz#3f5dc671ea168dccdeb3e141236f69f02eaec524"
|
||||
integrity sha512-ab9EmR80F/zQTMNeneUr4cv+jSwPJgIlvEmVwLerwrWVbpLlBuls9XHzIeTFy4cegU2NHBp3va0LKOzU5qFEYQ==
|
||||
|
||||
resolve-cwd@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/resolve-cwd/-/resolve-cwd-3.0.0.tgz"
|
||||
@ -5828,7 +5925,7 @@ resolve.exports@^2.0.0:
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/resolve.exports/-/resolve.exports-2.0.3.tgz"
|
||||
integrity sha512-OcXjMsGdhL4XnbShKpAcSqPMzQoYkYyhbEaeSko47MjRP9NfEQMhZkXL1DoFlt9LWQn4YttrdnV6X2OiyzBi+A==
|
||||
|
||||
resolve@^1.20.0, resolve@^1.22.10:
|
||||
resolve@^1.20.0, resolve@^1.22.10, resolve@^1.22.8:
|
||||
version "1.22.10"
|
||||
resolved "https://nexus-inner.51trust.com/repository/npm/resolve/-/resolve-1.22.10.tgz"
|
||||
integrity sha512-NPRy+/ncIMeDlTAsuqwKIiferiawhefFJtkNSW0qZJEqMEb+qBt/77B/jGeeek+F0uOeN05CDa6HXbbIgtVX4w==
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户