refactor(android): 重构 Android代码并优化性能

- 修复了使用 navigator.getBattery().then() 的冗余调用
-移除了不必要的电量监听器
- 优化了相机、定位、电池等信息的获取方式
-重命名了部分函数以提高可读性
- 调整了事件处理和状态管理的实现
这个提交包含在:
xuqm 2025-07-22 15:31:41 +08:00
父节点 b1f82a5d78
当前提交 c8840ac185
共有 9 个文件被更改,包括 55 次插入22 次删除

文件差异因一行或多行过长而隐藏

文件差异因一行或多行过长而隐藏

文件差异因一行或多行过长而隐藏

查看文件

@ -1,4 +1,4 @@
import { StatusBar, StyleSheet, useColorScheme } from 'react-native';
import { StatusBar, useColorScheme } from 'react-native';
import Toast from 'react-native-toast-message';
import { AppProvider } from '@app/contexts/AppProvider.tsx';
import { RootSiblingParent } from 'react-native-root-siblings';
@ -32,10 +32,4 @@ function App() {
);
}
const styles = StyleSheet.create({
tooltip: {
backgroundColor: 'rgba(0, 0, 0, 0)',
},
});
export default App;

查看文件

@ -1,12 +1,38 @@
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { Button, StyleSheet, View } from 'react-native';
import { StackScreenProps } from '@react-navigation/stack';
import { MainParamList } from '@app/routes/MainParamList';
import { Apps, NavigationPushByName } from '@common/NavigationHelper.ts';
import { showMessage } from '@common/ToastHelper.ts';
type Props = StackScreenProps<MainParamList, 'MainView'>;
export default function WebViewScreen(props: Props) {
return <View style={styles.container}></View>;
return (
<View style={styles.container}>
<View style={{ height: 100 }} />
<Button
title={'进入互联网医院'}
onPress={() => {
NavigationPushByName(Apps.Hospital, {});
}}
/>
<View style={{ height: 15 }} />
<Button
title={'进入医网签'}
onPress={() => {
NavigationPushByName(Apps.Ywq, {});
}}
/>
<View style={{ height: 15 }} />
<Button
title={'Toast'}
onPress={() => {
showMessage('APP页面弹出toast');
}}
/>
</View>
);
}
const styles = StyleSheet.create({

查看文件

@ -7,12 +7,12 @@ export enum Apps {
Ywq = 'ywq',
}
export const pushByName = (name: string, params: any) => {
export const NavigationPushByName = (name: string, params: any) => {
saveItem(`MessageActivity-${name}`, params).finally(() => {
NavigationManager.navigate(name);
});
};
export const pop = () => {
export const NavigationPop = () => {
NavigationManager.pop();
};
export const getDataFromName = (name: string) =>

查看文件

@ -4,16 +4,17 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
export const storageApp = new Storage({
size: 1000,
storageBackend: AsyncStorage,
defaultExpires: 1000 * 3600 * 24 * 60,
// defaultExpires: 1000 * 3600 * 24 * 60,
enableCache: true,
});
/**
*
* @param key
* @param value
* @param expires
*/
export const saveItem = (key: string, value: any) =>
storageApp.save({ key, data: value });
export const saveItem = (key: string, value: any, expires?: number | null) =>
storageApp.save({ key, data: value, expires });
/**
*
* @param key

查看文件

@ -13,7 +13,7 @@ import {
useColorScheme,
View,
} from 'react-native';
import { pop } from '@common/NavigationHelper.ts';
import { NavigationPop } from '@common/NavigationHelper.ts';
import { showMessage } from '@common/ToastHelper.ts';
import Toast from 'react-native-toast-message';
@ -28,7 +28,7 @@ function HospitalMain() {
<Button
title={'返回'}
onPress={() => {
pop();
NavigationPop();
}}
/>
<View style={{ height: 15 }} />

查看文件

@ -14,6 +14,8 @@ import {
} from 'react-native';
import { showMessage } from '@common/ToastHelper.ts';
import Toast from 'react-native-toast-message';
import Alert from '@common/components/Alert.tsx';
import { NavigationPop } from '@common/NavigationHelper.ts';
function YwqMain() {
const isDarkMode = useColorScheme() === 'dark';
@ -22,7 +24,16 @@ function YwqMain() {
<View style={styles.container}>
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
<View style={{ height: 100 }} />
<Button title={'onConfirm'} onPress={() => {}} />
<Button
title={'onConfirm'}
onPress={() => {
Alert.show('hello Alert', undefined, {
action: () => {
NavigationPop();
},
});
}}
/>
<View style={{ height: 15 }} />
<Button
title={'Toast'}
@ -31,6 +42,7 @@ function YwqMain() {
}}
/>
<Toast />
<Alert ref={ref => Alert.setRef(ref)} />
</View>
);
}