Skip to content

Commit 904bca7

Browse files
committed
feat: add dep page & jsontree component
1 parent d185223 commit 904bca7

File tree

15 files changed

+182
-37
lines changed

15 files changed

+182
-37
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
],
4141
"author": "",
4242
"dependencies": {
43-
"@babel/runtime": "^7.7.7",
4443
"@react-native-async-storage/async-storage": "^1.13.2",
4544
"@react-native-community/cameraroll": "^4.0.1",
4645
"@react-native-community/clipboard": "^1.5.1",
@@ -69,6 +68,7 @@
6968
"react-native": "^0.64.0",
7069
"react-native-gesture-handler": "^1.8.0",
7170
"react-native-image-resizer": "^1.4.0",
71+
"react-native-json-tree": "^1.3.0",
7272
"react-native-pager-view": "^5.4.0",
7373
"react-native-reanimated": "^1.13.1",
7474
"react-native-safe-area-context": "^3.1.8",
@@ -80,6 +80,7 @@
8080
},
8181
"devDependencies": {
8282
"@babel/core": "^7.8.0",
83+
"@babel/runtime": "^7.7.7",
8384
"@tarojs/cli": "3.3.3",
8485
"@tarojs/mini-runner": "3.3.3",
8586
"@tarojs/rn-runner": "3.3.3",

src/app.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export default {
6666
'pages/apis/pages/device/vibrate/index',
6767
// api 相关 end
6868
'pages/about/index',
69+
'pages/about/dep',
6970
'pages/webview/index',
7071
],
7172
window: {

src/pages/about/dep.config.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* @Author: zhiqingchen
3+
* @Date: 2021-07-19 15:54:39
4+
* @LastEditors: zhiqingchen
5+
* @LastEditTime: 2021-07-28 18:29:49
6+
* @FilePath: /taro-react-native/src/pages/dep/index.config.ts
7+
*/
8+
export default {
9+
navigationBarTitleText: '依赖列表',
10+
}

src/pages/about/dep.scss

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import '../../styles/variables.scss';
2+
3+
.page {
4+
padding: 40px 32px;
5+
}

src/pages/about/dep.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component } from 'react'
2+
import { View } from '@tarojs/components';
3+
import { dependencies, devDependencies } from '../../../package.json';
4+
import Header from '../components/head/head'
5+
import JSONTree from '../components/jsontree'
6+
7+
import './dep.scss';
8+
9+
export default class Index extends Component<any, any> {
10+
render() {
11+
return <View className="page">
12+
<Header title='dependencies'></Header>
13+
<JSONTree data={dependencies} />
14+
<Header title='devDependencies'></Header>
15+
<JSONTree data={devDependencies} />
16+
</View>
17+
}
18+
}

src/pages/about/index.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
margin-top: 40px;
5151
align-items: center;
5252
&-text {
53+
padding: 20px;
5354
font-size: $font-size-sm;
5455
color: $color-grey-2;
5556
}
56-
}
57+
}

src/pages/about/index.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import { Component, Fragment } from 'react'
99
import Taro from '@tarojs/taro';
1010
import { View, Image, Text } from '@tarojs/components';
11+
import { version as taroVersion } from '@tarojs/taro/package.json';
12+
import { version as rnVersion } from 'react-native/package.json';
1113
import './index.scss';
1214

1315
export default class Index extends Component<any, any> {
@@ -97,9 +99,14 @@ export default class Index extends Component<any, any> {
9799
)
98100
})}
99101
</View>
100-
{/* <View className='page-footer'>
101-
<Text className='page-footer-text'>Copyright(c) XXXXXXXXXXXXXXXXXXXXXX</Text>
102-
</View> */}
102+
<View className='page-footer' onClick={() => {
103+
Taro.navigateTo({
104+
url: '/pages/about/dep'
105+
})
106+
}}
107+
>
108+
<Text className='page-footer-text'>Taro: {taroVersion} React Native: {rnVersion}</Text>
109+
</View>
103110
</View>
104111
)
105112
}

src/pages/apis/pages/basic/system/index.tsx

+3-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { Component } from 'react'
99
import Taro from '@tarojs/taro'
1010
import { View, Button } from '@tarojs/components'
11+
import JSONTree from '../../../../components/jsontree'
1112
import './index.scss'
1213

1314
export default class Index extends Component<any, any> {
@@ -63,15 +64,8 @@ export default class Index extends Component<any, any> {
6364
>
6465
clear
6566
</Button>
66-
<View style={{padding: 20}}>
67-
{Object.keys(info).map(key => {
68-
const value = info[key];
69-
return (
70-
<View key={key}>{`${key}: ${value}`}</View>
71-
)
72-
})}
73-
</View>
67+
<JSONTree data={info} />
7468
</View>
7569
)
7670
}
77-
}
71+
}

src/pages/apis/pages/device/accelerometer/index.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@
77
*/
88
import Taro from "@tarojs/taro-rn";
99
import { Button, View } from "@tarojs/components";
10+
import { useState } from "react";
11+
import JSONTree from '../../../../components/jsontree';
1012

1113
import "./index.scss";
1214

1315
const Index = () => {
16+
const [accelerometer1, setAccelerometer1] = useState({});
17+
const [accelerometer2, setAccelerometer2] = useState({});
1418

15-
const _handleCallback1 = (...res) => {
19+
const _handleCallback1 = (res) => {
1620
console.log("回调函数 C1", res);
21+
setAccelerometer1(res);
1722
}
1823

19-
const _handleCallback2 = (...res) => {
24+
const _handleCallback2 = (res) => {
2025
console.log("回调函数 C2", res);
26+
setAccelerometer2(res);
2127
}
2228

2329
return (
@@ -32,6 +38,7 @@ const Index = () => {
3238
>
3339
Taro.onAccelerometerChange(C1)
3440
</Button>
41+
<JSONTree data={accelerometer1} />
3542
<Button
3643
type="primary"
3744
className="api-page-btn-success"
@@ -41,6 +48,7 @@ const Index = () => {
4148
>
4249
Taro.onAccelerometerChange(C2)
4350
</Button>
51+
<JSONTree data={accelerometer2} />
4452
<Button
4553
type="primary"
4654
className="api-page-btn-warning"

src/pages/apis/pages/device/deviceMotion/index.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@
77
*/
88
import Taro from "@tarojs/taro-rn";
99
import { Button, View } from "@tarojs/components";
10+
import { useState } from "react";
11+
import JSONTree from '../../../../components/jsontree';
1012

1113
import "./index.scss";
1214

1315
const Index = () => {
16+
const [deviceMotion1, setDeviceMotion1] = useState({});
17+
const [deviceMotion2, setDeviceMotion2] = useState({});
1418

15-
const _handleCallback1 = (...res) => {
19+
const _handleCallback1 = (res) => {
1620
console.log("回调函数 C1", res);
21+
setDeviceMotion1(res);
1722
}
1823

19-
const _handleCallback2 = (...res) => {
24+
const _handleCallback2 = (res) => {
2025
console.log("回调函数 C2", res);
26+
setDeviceMotion2(res);
2127
}
2228

2329
return (
@@ -32,6 +38,7 @@ const Index = () => {
3238
>
3339
Taro.onDeviceMotionChange(C1)
3440
</Button>
41+
<JSONTree data={deviceMotion1} />
3542
<Button
3643
type="primary"
3744
className="api-page-btn-success"
@@ -41,6 +48,7 @@ const Index = () => {
4148
>
4249
Taro.onDeviceMotionChange(C2)
4350
</Button>
51+
<JSONTree data={deviceMotion2} />
4452
<Button
4553
type="primary"
4654
className="api-page-btn-warning"

src/pages/apis/pages/device/gyroscope/index.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@
77
*/
88
import Taro from "@tarojs/taro-rn";
99
import { Button, View } from "@tarojs/components";
10+
import { useState } from "react";
11+
import JSONTree from '../../../../components/jsontree';
1012

1113
import "./index.scss";
1214

1315
const Index = () => {
16+
const [gyroscope1, setGyroscope1] = useState({});
17+
const [gyroscope2, setGyroscope2] = useState({});
1418

15-
const _handleCallback1 = (...res) => {
19+
const _handleCallback1 = (res) => {
1620
console.log("回调函数 C1", res);
21+
setGyroscope1(res);
1722
}
1823

19-
const _handleCallback2 = (...res) => {
24+
const _handleCallback2 = (res) => {
2025
console.log("回调函数 C2", res);
26+
setGyroscope2(res);
2127
}
2228

2329
return (
@@ -32,6 +38,7 @@ const Index = () => {
3238
>
3339
Taro.onGyroscopeChange(C1)
3440
</Button>
41+
<JSONTree data={gyroscope1} />
3542
<Button
3643
type="primary"
3744
className="api-page-btn-success"
@@ -41,6 +48,7 @@ const Index = () => {
4148
>
4249
Taro.onGyroscopeChange(C2)
4350
</Button>
51+
<JSONTree data={gyroscope2} />
4452
<Button
4553
type="primary"
4654
className="api-page-btn-warning"

src/pages/apis/pages/device/scanCode/index.tsx

+3-14
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
*/
88
import { useState } from "react";
99
import Taro from "@tarojs/taro-rn";
10-
import { Button, View, Text } from "@tarojs/components";
10+
import { Button, View } from "@tarojs/components";
11+
import JSONTree from '../../../../components/jsontree';
1112

1213
import "./index.scss";
1314

1415
const Index = () => {
1516
const [info, setInfo] = useState({});
1617

17-
const infoKeys = Object.keys(info);
18-
1918
return (
2019
<View className="api-page">
2120
<View className="api-page__body">
@@ -38,17 +37,7 @@ const Index = () => {
3837
>
3938
Taro.scanCode
4039
</Button>
41-
{infoKeys.length > 0 && (
42-
<View className='common-border'>
43-
{infoKeys.map(key => {
44-
return (
45-
<View key={key}>
46-
<Text>{key}: {info[key]}</Text>
47-
</View>
48-
)
49-
})}
50-
</View>
51-
)}
40+
<JSONTree data={info} />
5241
</View>
5342
</View>
5443
)

src/pages/apis/pages/location/index/index.tsx

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,25 @@
66
* @FilePath: /taro-react-native/src/pages/apis/pages/location/index/index.tsx
77
*/
88
import Taro from '@tarojs/taro';
9-
import { View, Button, Text } from '@tarojs/components';
9+
import { useState } from "react";
10+
import { View, Button } from '@tarojs/components';
11+
import JSONTree from '../../../../components/jsontree';
1012

1113
import './index.scss'
1214

1315
const PageView = () => {
16+
const [location, setLocation] = useState({});
17+
const [location1, setLocation1] = useState({});
18+
const [location2, setLocation2] = useState({});
1419

1520
const _handleCallback1 = (res) => {
1621
console.log("回调函数 C1", res);
22+
setLocation1(res)
1723
}
1824

1925
const _handleCallback2 = (res) => {
2026
console.log("回调函数 C2", res);
27+
setLocation2(res)
2128
}
2229

2330
return (
@@ -29,25 +36,28 @@ const PageView = () => {
2936
onClick={() => {
3037
Taro.getLocation({
3138
success: res => {
32-
console.log(999, res)
39+
setLocation(res)
3340
}
3441
})
3542
}}
3643
>Taro.getLocation</Button>
44+
<JSONTree data={location} />
3745
<Button
3846
type="primary"
3947
className="api-page-btn-success"
4048
onClick={() => {
4149
Taro.onLocationChange(_handleCallback1)
4250
}}
4351
>Taro.onLocationChange(C1)</Button>
52+
<JSONTree data={location1} />
4453
<Button
4554
type="primary"
4655
className="api-page-btn-success"
4756
onClick={() => {
4857
Taro.onLocationChange(_handleCallback2)
4958
}}
5059
>Taro.onLocationChange(C2)</Button>
60+
<JSONTree data={location2} />
5161
<Button
5262
type="primary"
5363
className="api-page-btn-warning"
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import JSONTree from 'react-native-json-tree'
2+
import { View } from '@tarojs/components'
3+
4+
const theme = {
5+
scheme: 'monokai',
6+
author: 'wimer hazenberg (http://www.monokai.nl)',
7+
base00: '#272822',
8+
base01: '#383830',
9+
base02: '#49483e',
10+
base03: '#75715e',
11+
base04: '#a59f85',
12+
base05: '#f8f8f2',
13+
base06: '#f5f4f1',
14+
base07: '#f9f8f5',
15+
base08: '#f92672',
16+
base09: '#fd971f',
17+
base0A: '#f4bf75',
18+
base0B: '#a6e22e',
19+
base0C: '#a1efe4',
20+
base0D: '#66d9ef',
21+
base0E: '#ae81ff',
22+
base0F: '#cc6633'
23+
};
24+
25+
export default (props) => {
26+
return (Object.keys(props.data).length > 0 ? <JSONTree {...props} theme={theme} hideRoot /> : <View></View>)
27+
}

0 commit comments

Comments
 (0)