-
Notifications
You must be signed in to change notification settings - Fork 141
/
AutomaticSlidingThreePage.js
191 lines (177 loc) · 5.6 KB
/
AutomaticSlidingThreePage.js
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import React, {Component} from 'react'
import {Dimensions, Image, StyleSheet, Text, View,ScrollView,Platform,SafeAreaView} from 'react-native'
import AutoDragSortableView from '../widget/AutoDragSortableView'
import {AUTO_TEST_DATA} from '../data/base/BaseConstant'
const {width} = Dimensions.get('window')
const parentWidth = width
const childrenWidth = width/3 - 20
const childrenHeight = 48*4
const headerViewHeight = 160
const bottomViewHeight = 40
export default class AutomaticSlidingThreePage extends Component {
constructor(props) {
super()
this.state = {
data: AUTO_TEST_DATA,
}
}
render() {
// Write a temporary example
const renderHeaderView = (
<View style={styles.aheader}>
<Image source={{uri: 'https://avatars0.githubusercontent.com/u/15728691?s=460&v=4'}} style={styles.aheader_img}/>
<View style={styles.aheader_context}>
<Text style={styles.aheader_title}>mochixuan</Text>
<Text style={styles.aheader_desc}>Android, React-Native, Flutter, React, Web。Learn new knowledge and share new knowledge.</Text>
</View>
</View>
)
const renderBottomView = (
<View style={styles.abottom}>
<Text style={styles.abottom_desc}>yarn add react-native-drag-sort</Text>
</View>
)
return (
<SafeAreaView style={{flex: 1, backgroundColor: '#fff'}}>
<View style={styles.header}>
<Text style={styles.header_title}>Automatic Sliding: Three Line</Text>
</View>
<AutoDragSortableView
dataSource={this.state.data}
parentWidth={parentWidth}
childrenWidth= {childrenWidth}
marginChildrenBottom={10}
marginChildrenRight={10}
marginChildrenLeft = {10}
marginChildrenTop = {10}
childrenHeight={childrenHeight}
onDataChange = {(data)=>{
if (data.length != this.state.data.length) {
this.setState({
data: data
})
}
}}
keyExtractor={(item,index)=> item.txt} // FlatList作用一样,优化
renderItem={(item,index)=>{
return this.renderItem(item,index)
}}
renderHeaderView = {renderHeaderView}
headerViewHeight={headerViewHeight}
renderBottomView = {renderBottomView}
bottomViewHeight={bottomViewHeight}
/>
</SafeAreaView>
)
}
renderItem(item,index) {
return (
<View style={styles.item}>
<View style={styles.item_icon_swipe}>
<Image style={styles.item_icon} source={item.icon}/>
</View>
<View style={styles.item_text_swipe}>
<Text style={styles.item_text}>{item.txt}</Text>
</View>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#f0f0f0',
},
header: {
height: 48,
justifyContent: 'center',
alignItems: 'center',
borderBottomColor: '#2ecc71',
borderBottomWidth: 2,
},
header_title: {
color: '#333',
fontSize: 24,
fontWeight: 'bold'
},
item: {
width: childrenWidth,
height: childrenHeight,
justifyContent: 'space-around',
alignItems: 'center',
backgroundColor: '#f39c12',
borderRadius: 4,
},
item_icon_swipe: {
width: childrenWidth*0.7,
height: childrenWidth*0.7,
backgroundColor: '#fff',
borderRadius: childrenWidth*0.35,
justifyContent: 'center',
alignItems: 'center',
},
item_icon: {
width: childrenWidth*0.5,
height: childrenWidth*0.5,
resizeMode: 'contain',
},
item_text_swipe: {
backgroundColor: '#fff',
width: 56,
height: 30,
borderRadius: 15,
justifyContent: 'center',
alignItems: 'center',
},
item_text: {
color: '#444',
fontSize: 20,
fontWeight: 'bold',
},
aheader: {
height: headerViewHeight,
flexDirection: 'row',
borderBottomColor: '#2ecc71',
borderBottomWidth: 2,
zIndex: 100,
backgroundColor: '#fff'
},
aheader_img: {
width: headerViewHeight * 0.6,
height: headerViewHeight * 0.6,
resizeMode: 'cover',
borderRadius: headerViewHeight * 0.3,
marginLeft: 16,
marginTop: 10,
},
aheader_context: {
marginLeft: 8,
height: headerViewHeight * 0.4,
marginTop: 10
},
aheader_title: {
color: '#333',
fontSize: 20,
marginBottom: 10,
fontWeight: 'bold'
},
aheader_desc: {
color: '#444',
fontSize: 16,
width: width - headerViewHeight * 0.6 - 32
},
abottom: {
justifyContent: 'center',
alignItems: 'center',
height: bottomViewHeight,
backgroundColor: '#fff',
zIndex: 100,
borderTopColor: '#2ecc71',
borderTopWidth: 2,
},
abottom_desc: {
color: '#333',
fontSize: 20,
fontWeight: 'bold'
}
})