view.tsx
3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* eslint-disable @typescript-eslint/camelcase */
/**
* @author sheng
* @description 功能介绍列表页
* @date 2020/09/03
*/
import React, { memo, useState, useLayoutEffect, useEffect } from 'react'
import { Text, View, FlatList, Pressable, InteractionManager } from 'react-native'
import { Icons } from '../../../assets/icons'
import { styles } from './style'
import { dateFormat, setUnit } from '../../../libs/utils'
import { Toast, Divider, Empty, ModalManager } from 'react-native-mb-ui'
import { getVersionList } from '../../../api/version'
import { NavigationProp } from '@react-navigation/native'
import { RouteList } from '../../../router/route'
interface Items {
version: string;
create_time: number;
remark: string;
id: number;
}
interface ItemProp {
onClick: () => void;
item: Items;
}
const Item = memo(({ onClick, item }: ItemProp) => {
const { version, create_time } = item
return (
<>
<Pressable
style={styles.item}
android_ripple={{ color: '#eee' }}
onPress={onClick}
>
<View style={styles.content}>
<Text style={styles.title}>商品交易所{version}主要更新</Text>
<Text style={styles.subtitle}>{dateFormat('MM/DD', new Date(create_time).getTime())}</Text>
</View>
<Icons name='you' size={setUnit(32)} color='#C2C3C4' />
</Pressable>
<Divider style={{ marginLeft: setUnit(25) }} />
</>
)
})
let http
const Page: React.FC<{ navigation: NavigationProp<RouteList> }> = ({ navigation }) => {
const [records, setRecords] = useState([])
useLayoutEffect(() => {
navigation.setOptions({
headerLeft: () => (
<Icons
name='guanbi'
color='#555'
size={setUnit(32)}
style={{ paddingHorizontal: setUnit(24) }}
onPress={(): void => navigation.goBack()}
/>
)
})
}, [navigation])
useEffect(() => {
const fetchData = (): void => {
InteractionManager.runAfterInteractions(() => {
Toast.loading()
http = getVersionList(res => {
setRecords(res?.reverse() || [])
Toast.hideLoading()
}, err => {
Toast.hideLoading()
ModalManager.alert({
title: '错误',
content: err
})
})
})
}
fetchData()
return (): void => {
if (http) http.cancel()
}
}, [])
return (
<View style={styles.container}>
<FlatList
data={records}
contentContainerStyle={!records.length ? styles.containerStyle : {}}
keyExtractor={(item: Items): string => item.id?.toString()}
renderItem={({ item }: { item: Items }): React.ReactElement => (
<Item
onClick={(): void => navigation.navigate('FeatureDetail', { content: item.remark || '' })}
item={item}
/>
)}
ListEmptyComponent={(): React.ReactElement => <Empty style={{ paddingTop: 100 }} />}
/>
</View>
)
}
export default Page