Phecda

refactor: add RNDeviceInfo

@@ -298,6 +298,8 @@ PODS: @@ -298,6 +298,8 @@ PODS:
298 - React 298 - React
299 - RNCMaskedView (0.1.7): 299 - RNCMaskedView (0.1.7):
300 - React 300 - React
  301 + - RNDeviceInfo (5.5.4):
  302 + - React
301 - RNGestureHandler (1.6.1): 303 - RNGestureHandler (1.6.1):
302 - React 304 - React
303 - RNReanimated (1.7.1): 305 - RNReanimated (1.7.1):
@@ -346,6 +348,7 @@ DEPENDENCIES: @@ -346,6 +348,7 @@ DEPENDENCIES:
346 - ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`) 348 - ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
347 - ReactNativeDarkMode (from `../node_modules/react-native-dark-mode`) 349 - ReactNativeDarkMode (from `../node_modules/react-native-dark-mode`)
348 - "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)" 350 - "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)"
  351 + - RNDeviceInfo (from `../node_modules/react-native-device-info`)
349 - RNGestureHandler (from `../node_modules/react-native-gesture-handler`) 352 - RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
350 - RNReanimated (from `../node_modules/react-native-reanimated`) 353 - RNReanimated (from `../node_modules/react-native-reanimated`)
351 - RNScreens (from `../node_modules/react-native-screens`) 354 - RNScreens (from `../node_modules/react-native-screens`)
@@ -422,6 +425,8 @@ EXTERNAL SOURCES: @@ -422,6 +425,8 @@ EXTERNAL SOURCES:
422 :path: "../node_modules/react-native-dark-mode" 425 :path: "../node_modules/react-native-dark-mode"
423 RNCMaskedView: 426 RNCMaskedView:
424 :path: "../node_modules/@react-native-community/masked-view" 427 :path: "../node_modules/@react-native-community/masked-view"
  428 + RNDeviceInfo:
  429 + :path: "../node_modules/react-native-device-info"
425 RNGestureHandler: 430 RNGestureHandler:
426 :path: "../node_modules/react-native-gesture-handler" 431 :path: "../node_modules/react-native-gesture-handler"
427 RNReanimated: 432 RNReanimated:
@@ -472,6 +477,7 @@ SPEC CHECKSUMS: @@ -472,6 +477,7 @@ SPEC CHECKSUMS:
472 ReactCommon: 3585806280c51d5c2c0d3aa5a99014c3badb629d 477 ReactCommon: 3585806280c51d5c2c0d3aa5a99014c3badb629d
473 ReactNativeDarkMode: 0178ffca3b10f6a7c9f49d6f9810232b328fa949 478 ReactNativeDarkMode: 0178ffca3b10f6a7c9f49d6f9810232b328fa949
474 RNCMaskedView: 76c40a1d41c3e2535df09246a2b5487f04de0814 479 RNCMaskedView: 76c40a1d41c3e2535df09246a2b5487f04de0814
  480 + RNDeviceInfo: 6a3d16fce033f6979c4a6a41e62244d183e8c765
475 RNGestureHandler: 8f09cd560f8d533eb36da5a6c5a843af9f056b38 481 RNGestureHandler: 8f09cd560f8d533eb36da5a6c5a843af9f056b38
476 RNReanimated: 4e102df74a9674fa943e05f97f3362b6e44d0b48 482 RNReanimated: 4e102df74a9674fa943e05f97f3362b6e44d0b48
477 RNScreens: b5c0e1b2b04512919e78bd3898e144a157ce2363 483 RNScreens: b5c0e1b2b04512919e78bd3898e144a157ce2363
@@ -20,6 +20,7 @@ @@ -20,6 +20,7 @@
20 "react": "16.11.0", 20 "react": "16.11.0",
21 "react-native": "0.62.1", 21 "react-native": "0.62.1",
22 "react-native-dark-mode": "^0.2.2", 22 "react-native-dark-mode": "^0.2.2",
  23 + "react-native-device-info": "^5.5.4",
23 "react-native-elements": "^1.2.7", 24 "react-native-elements": "^1.2.7",
24 "react-native-gesture-handler": "^1.6.1", 25 "react-native-gesture-handler": "^1.6.1",
25 "react-native-reanimated": "^1.7.1", 26 "react-native-reanimated": "^1.7.1",
1 import React from 'react'; 1 import React from 'react';
2 import { NavigationContainer } from '@react-navigation/native'; 2 import { NavigationContainer } from '@react-navigation/native';
3 import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; 3 import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
  4 +import { createStackNavigator } from '@react-navigation/stack';
4 import Fontisto from 'react-native-vector-icons/Fontisto'; 5 import Fontisto from 'react-native-vector-icons/Fontisto';
5 import Ionicons from 'react-native-vector-icons/Ionicons'; 6 import Ionicons from 'react-native-vector-icons/Ionicons';
6 -import { MainTabParamList } from '../type/Navigation'; 7 +import { MainTabParamList, MainStackParamList } from '../type/Navigation';
7 import WelcomePage from './WelcomePage'; 8 import WelcomePage from './WelcomePage';
8 import SystemInfo from './SystemInfo'; 9 import SystemInfo from './SystemInfo';
9 import DesignList from './DesignList'; 10 import DesignList from './DesignList';
10 import { useDynamicValue } from 'react-native-dark-mode'; 11 import { useDynamicValue } from 'react-native-dark-mode';
11 import { colorPreset } from '../design'; 12 import { colorPreset } from '../design';
  13 +import RNDeviceInfoList from './RNDeviceInfo';
12 14
13 const MainTab = createBottomTabNavigator<MainTabParamList>(); 15 const MainTab = createBottomTabNavigator<MainTabParamList>();
14 16
15 -export default () => { 17 +const Home = () => {
16 const backgroundColor = useDynamicValue(colorPreset.backgroundColor.primary); 18 const backgroundColor = useDynamicValue(colorPreset.backgroundColor.primary);
17 const tintColor = useDynamicValue(colorPreset.linkColor); 19 const tintColor = useDynamicValue(colorPreset.linkColor);
18 const opaqueSeparator = useDynamicValue(colorPreset.separator.opaque); 20 const opaqueSeparator = useDynamicValue(colorPreset.separator.opaque);
19 return ( 21 return (
20 - <NavigationContainer>  
21 <MainTab.Navigator 22 <MainTab.Navigator
22 screenOptions={({ route }) => { 23 screenOptions={({ route }) => {
23 const routeName = route.name; 24 const routeName = route.name;
@@ -64,6 +65,21 @@ export default () => { @@ -64,6 +65,21 @@ export default () => {
64 <MainTab.Screen name="SystemInfo" component={SystemInfo} /> 65 <MainTab.Screen name="SystemInfo" component={SystemInfo} />
65 <MainTab.Screen name="DesignList" component={DesignList} /> 66 <MainTab.Screen name="DesignList" component={DesignList} />
66 </MainTab.Navigator> 67 </MainTab.Navigator>
  68 + );
  69 +};
  70 +
  71 +const MainStack = createStackNavigator<MainStackParamList>();
  72 +
  73 +export default () => {
  74 + return (
  75 + <NavigationContainer>
  76 + <MainStack.Navigator>
  77 + <MainStack.Screen name="MainTab" component={Home} />
  78 + <MainStack.Screen
  79 + name="RNDeviceInfoList"
  80 + component={RNDeviceInfoList}
  81 + />
  82 + </MainStack.Navigator>
67 </NavigationContainer> 83 </NavigationContainer>
68 ); 84 );
69 }; 85 };
  1 +import React, { useState, useCallback, useEffect } from 'react';
  2 +import { StackNavigationProp } from '@react-navigation/stack';
  3 +import DeviceInfo from 'react-native-device-info';
  4 +import { ListItem, BGScroll, Card, Divider, BGList } from '../component/View';
  5 +import { MainStackParamList } from '../type/Navigation';
  6 +
  7 +type NavigationProp = StackNavigationProp<
  8 + MainStackParamList,
  9 + 'RNDeviceInfoList'
  10 +>;
  11 +
  12 +type DeviceInfoMethod = keyof typeof DeviceInfo;
  13 +
  14 +const keys = Object.keys(DeviceInfo).filter(
  15 + (k) => !k.startsWith('use') && !/Sync/.test(k)
  16 +) as Array<DeviceInfoMethod>;
  17 +
  18 +const DeviceInfoItem = ({ k }: { k: DeviceInfoMethod }) => {
  19 + const [v, setV] = useState('');
  20 + const onEval = useCallback(async () => {
  21 + const method = DeviceInfo[k];
  22 + let result = '';
  23 + try {
  24 + const r = await method('');
  25 + result = typeof r === 'object' ? JSON.stringify(r) : String(r);
  26 + } catch (error) {
  27 + result = `err: ${error}`;
  28 + }
  29 + setV(result);
  30 + }, [k]);
  31 + useEffect(() => {
  32 + onEval();
  33 + }, [onEval]);
  34 + return <ListItem title={k} subtitle={v} onPress={onEval} />;
  35 +};
  36 +
  37 +const RNDeviceInfoList = ({ navigation }: { navigation: NavigationProp }) => {
  38 + return (
  39 + <BGList
  40 + data={keys}
  41 + renderItem={({ item }) => {
  42 + return <DeviceInfoItem k={item} />;
  43 + }}
  44 + />
  45 + );
  46 +};
  47 +
  48 +export default RNDeviceInfoList;
@@ -9,13 +9,15 @@ export default () => { @@ -9,13 +9,15 @@ export default () => {
9 <Card shadow> 9 <Card shadow>
10 <ListItem 10 <ListItem
11 title={'width'} 11 title={'width'}
12 - rightTitle={`${width}pt`} 12 + rightTitle={`${Number.isInteger(width) ? width : width.toFixed(2)}pt`}
13 rightSubtitle={`${width * scale}px`} 13 rightSubtitle={`${width * scale}px`}
14 /> 14 />
15 <Divider /> 15 <Divider />
16 <ListItem 16 <ListItem
17 title={'height'} 17 title={'height'}
18 - rightTitle={`${height}pt`} 18 + rightTitle={`${
  19 + Number.isInteger(height) ? height : height.toFixed(2)
  20 + }pt`}
19 rightSubtitle={`${height * scale}px`} 21 rightSubtitle={`${height * scale}px`}
20 /> 22 />
21 <Divider /> 23 <Divider />
@@ -3,3 +3,8 @@ export type MainTabParamList = { @@ -3,3 +3,8 @@ export type MainTabParamList = {
3 SystemInfo: undefined; 3 SystemInfo: undefined;
4 DesignList: undefined; 4 DesignList: undefined;
5 }; 5 };
  6 +
  7 +export type MainStackParamList = {
  8 + MainTab: undefined;
  9 + RNDeviceInfoList: undefined;
  10 +};
@@ -6596,6 +6596,11 @@ react-native-dark-mode@^0.2.2: @@ -6596,6 +6596,11 @@ react-native-dark-mode@^0.2.2:
6596 events "^3.0.0" 6596 events "^3.0.0"
6597 toolkit.ts "^0.0.2" 6597 toolkit.ts "^0.0.2"
6598 6598
  6599 +react-native-device-info@^5.5.4:
  6600 + version "5.5.4"
  6601 + resolved "https://registry.npm.taobao.org/react-native-device-info/download/react-native-device-info-5.5.4.tgz#470770db4e8a35c55b8269473d81790102074057"
  6602 + integrity sha1-Rwdw206KNcVbgmlHPYF5AQIHQFc=
  6603 +
6599 react-native-elements@^1.2.7: 6604 react-native-elements@^1.2.7:
6600 version "1.2.7" 6605 version "1.2.7"
6601 resolved "https://registry.npm.taobao.org/react-native-elements/download/react-native-elements-1.2.7.tgz#1eca2db715c41722aeb67aea62bd2a4621adb134" 6606 resolved "https://registry.npm.taobao.org/react-native-elements/download/react-native-elements-1.2.7.tgz#1eca2db715c41722aeb67aea62bd2a4621adb134"