refactor(android): 重构 Android代码并优化性能
- 修复了使用 navigator.getBattery().then() 的冗余调用 -移除了不必要的电量监听器 - 优化了相机、定位、电池等信息的获取方式 -重命名了部分函数以提高可读性 - 调整了事件处理和状态管理的实现
这个提交包含在:
父节点
b1f82a5d78
当前提交
c8840ac185
文件差异因一行或多行过长而隐藏
文件差异因一行或多行过长而隐藏
文件差异因一行或多行过长而隐藏
@ -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 Toast from 'react-native-toast-message';
|
||||||
import { AppProvider } from '@app/contexts/AppProvider.tsx';
|
import { AppProvider } from '@app/contexts/AppProvider.tsx';
|
||||||
import { RootSiblingParent } from 'react-native-root-siblings';
|
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;
|
export default App;
|
||||||
|
|||||||
@ -1,12 +1,38 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { StyleSheet, View } from 'react-native';
|
import { Button, StyleSheet, View } from 'react-native';
|
||||||
import { StackScreenProps } from '@react-navigation/stack';
|
import { StackScreenProps } from '@react-navigation/stack';
|
||||||
import { MainParamList } from '@app/routes/MainParamList';
|
import { MainParamList } from '@app/routes/MainParamList';
|
||||||
|
import { Apps, NavigationPushByName } from '@common/NavigationHelper.ts';
|
||||||
|
import { showMessage } from '@common/ToastHelper.ts';
|
||||||
|
|
||||||
type Props = StackScreenProps<MainParamList, 'MainView'>;
|
type Props = StackScreenProps<MainParamList, 'MainView'>;
|
||||||
|
|
||||||
export default function WebViewScreen(props: Props) {
|
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({
|
const styles = StyleSheet.create({
|
||||||
|
|||||||
@ -7,12 +7,12 @@ export enum Apps {
|
|||||||
Ywq = 'ywq',
|
Ywq = 'ywq',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const pushByName = (name: string, params: any) => {
|
export const NavigationPushByName = (name: string, params: any) => {
|
||||||
saveItem(`MessageActivity-${name}`, params).finally(() => {
|
saveItem(`MessageActivity-${name}`, params).finally(() => {
|
||||||
NavigationManager.navigate(name);
|
NavigationManager.navigate(name);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
export const pop = () => {
|
export const NavigationPop = () => {
|
||||||
NavigationManager.pop();
|
NavigationManager.pop();
|
||||||
};
|
};
|
||||||
export const getDataFromName = (name: string) =>
|
export const getDataFromName = (name: string) =>
|
||||||
|
|||||||
@ -4,16 +4,17 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
|
|||||||
export const storageApp = new Storage({
|
export const storageApp = new Storage({
|
||||||
size: 1000,
|
size: 1000,
|
||||||
storageBackend: AsyncStorage,
|
storageBackend: AsyncStorage,
|
||||||
defaultExpires: 1000 * 3600 * 24 * 60,
|
// defaultExpires: 1000 * 3600 * 24 * 60,
|
||||||
enableCache: true,
|
enableCache: true,
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
* 缓存一个键值对
|
* 缓存一个键值对
|
||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param value
|
||||||
|
* @param expires
|
||||||
*/
|
*/
|
||||||
export const saveItem = (key: string, value: any) =>
|
export const saveItem = (key: string, value: any, expires?: number | null) =>
|
||||||
storageApp.save({ key, data: value });
|
storageApp.save({ key, data: value, expires });
|
||||||
/**
|
/**
|
||||||
* 获取一个键值对
|
* 获取一个键值对
|
||||||
* @param key
|
* @param key
|
||||||
|
|||||||
@ -13,7 +13,7 @@ import {
|
|||||||
useColorScheme,
|
useColorScheme,
|
||||||
View,
|
View,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { pop } from '@common/NavigationHelper.ts';
|
import { NavigationPop } from '@common/NavigationHelper.ts';
|
||||||
import { showMessage } from '@common/ToastHelper.ts';
|
import { showMessage } from '@common/ToastHelper.ts';
|
||||||
import Toast from 'react-native-toast-message';
|
import Toast from 'react-native-toast-message';
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ function HospitalMain() {
|
|||||||
<Button
|
<Button
|
||||||
title={'返回'}
|
title={'返回'}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
pop();
|
NavigationPop();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<View style={{ height: 15 }} />
|
<View style={{ height: 15 }} />
|
||||||
|
|||||||
@ -14,6 +14,8 @@ import {
|
|||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { showMessage } from '@common/ToastHelper.ts';
|
import { showMessage } from '@common/ToastHelper.ts';
|
||||||
import Toast from 'react-native-toast-message';
|
import Toast from 'react-native-toast-message';
|
||||||
|
import Alert from '@common/components/Alert.tsx';
|
||||||
|
import { NavigationPop } from '@common/NavigationHelper.ts';
|
||||||
|
|
||||||
function YwqMain() {
|
function YwqMain() {
|
||||||
const isDarkMode = useColorScheme() === 'dark';
|
const isDarkMode = useColorScheme() === 'dark';
|
||||||
@ -22,7 +24,16 @@ function YwqMain() {
|
|||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
|
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
|
||||||
<View style={{ height: 100 }} />
|
<View style={{ height: 100 }} />
|
||||||
<Button title={'onConfirm'} onPress={() => {}} />
|
<Button
|
||||||
|
title={'onConfirm'}
|
||||||
|
onPress={() => {
|
||||||
|
Alert.show('hello Alert', undefined, {
|
||||||
|
action: () => {
|
||||||
|
NavigationPop();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<View style={{ height: 15 }} />
|
<View style={{ height: 15 }} />
|
||||||
<Button
|
<Button
|
||||||
title={'Toast'}
|
title={'Toast'}
|
||||||
@ -31,6 +42,7 @@ function YwqMain() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Toast />
|
<Toast />
|
||||||
|
<Alert ref={ref => Alert.setRef(ref)} />
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户