项目中,涉及到类似支付宝的应用增删模块,这几天简单的实现了下.
基本雏形实现了.后面的细节稍后再做处理.写篇博客记录下.

效果图:
editItem_resulut

实现思路 ==>
UI: 一开始采用外部ScrollView内部FlatList和ScrollView实现,后来发现有点臃肿,于是采用外部FlatList,内部ScrollView实现.然后发现其实代码差不太多…….浪费表情,其中依赖几个三方库:react-native-scrollable-tab-view,react-native-underline-tabbar.本来想使用SectionList实现的,但是感觉使用SectionList会更麻烦.
逻辑: 通过数据中 id 和 tag实现

废话不多缩,首先,新建一个项目,添加相应库:
第一种实现:

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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
/**
* UI 通过 外部ScrollView 内部 FlatList或者 ScrollView 实现 (使用三方库react-native-scrollable-tab-view&&react-native-underline-tabbar)
* 逻辑 通过 数据中 id 和 tag实现
* */
import React, { Component } from 'react'
import {
StyleSheet,
View,
Image,
Text,
Dimensions,
TouchableOpacity,
FlatList,
Linking,
ScrollView
} from 'react-native'
const { width } = Dimensions.get('window')
import ScrollableTabView from 'react-native-scrollable-tab-view'
import TabBar from 'react-native-underline-tabbar'

export default class One extends Component {
// 构造
constructor(props) {
super(props)
// 初始状态
this.state = {
startEdit: false, // 是否点击了编辑 默认未点击false
myApplyData: [],
otherApplyData: [],
applyData: [
{
title: '我的应用',
sub: [
{
id: '10086',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqgy1fu39hosiwoj30j60qyq96.jpg',
name: '价费通10086',
},
{
id: '10010',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftzsj15hgvj30sg15hkbw.jpg',
name: '展示中心10010',
}
],
},
{
title: '政务服务',
sub: [
{
subTitle: '政企',
sub: [
{
id: '10086',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqgy1fu39hosiwoj30j60qyq96.jpg',
name: '价费通10086',
tag: true,
},
{
id: '10010',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftzsj15hgvj30sg15hkbw.jpg',
name: '展示中心10010',
tag: true,
},
{
id: '9',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftzsj15hgvj30sg15hkbw.jpg',
name: '办事平台',
tag: false,
},
{
id: '10',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqgy1ftwcw4f4a5j30sg10j1g9.jpg',
name: '少儿图书馆',
tag: false,
},
],
},
{
subTitle: '第三方服务',
sub: [
{
id: '11',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftzsj15hgvj30sg15hkbw.jpg',
name: '价费通',
tag: false,
},
{
id: '12',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqgy1ftwcw4f4a5j30sg10j1g9.jpg',
name: '价费通',
tag: false,
},
{
id: '13',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftzsj15hgvj30sg15hkbw.jpg',
name: '价费通',
tag: false,
},
{
id: '14',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqgy1ftwcw4f4a5j30sg10j1g9.jpg',
name: '价费通',
tag: false,
},
{
id: '15',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqgy1ftwcw4f4a5j30sg10j1g9.jpg',
name: '价费通',
tag: false,
},
{
id: '16',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftu6gl83ewj30k80tites.jpg',
name: '价费通',
tag: false,
},
{
id: '17',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftu6gl83ewj30k80tites.jpg',
name: '价费通',
tag: false,
},
{
id: '18',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftu6gl83ewj30k80tites.jpg',
name: '价费通',
tag: false,
},
],
},
],
},
{
title: '政企应用',
sub: [
{
subTitle: '按主题',
sub: [
{
id: '19',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftdtot8zd3j30ju0pt137.jpg',
name: '价费通',
tag: false,
},
{
id: '20',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ft5q7ys128j30sg10gnk5.jpg',
name: '价费通',
tag: false,
},
],
},
{
subTitle: '按部门',
sub: [
{
id: '21',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftdtot8zd3j30ju0pt137.jpg',
name: '价费通',
tag: false,
},
],
},
{
subTitle: '按证件',
sub: [
{
id: '22',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ft5q7ys128j30sg10gnk5.jpg',
name: '价费通',
tag: false,
},
],
},
{
subTitle: '主体周期',
sub: [
{
id: '23',
icon:
'http://ww1.sinaimg.cn/large/0065oQSqly1fsoe3k2gkkj30g50niwla.jpg',
name: '价费通',
tag: false,
},
{
id: '24',
icon:
'http://ww1.sinaimg.cn/large/0065oQSqly1fsoe3k2gkkj30g50niwla.jpg',
name: '价费通',
tag: false,
},
],
},
],
},
],
}
}

componentDidMount() {
var data = this.state.applyData
//赋值 我的应用数据
this.setState({
myApplyData: data[0].sub,
})
//赋值 其他应用数据
this.setState({
otherApplyData: data.slice(1),
})
}


/**
* 点击编辑
* */
editAction = () => {
this.setState({
startEdit:!this.state.startEdit
})
}

/**
* 去除我的应用
* */
subAction = item => {
var data = this.state.myApplyData // 我的应用数据
var otherData = this.state.otherApplyData //其他应用数据
var selectId = item.item.id // 选中的id

//修改我的应用数据源
data.map((item,index) =>{
if(item.id == selectId){
data.splice(index,1)
}
})

//修改其他应用数据源
otherData.map((item,index) =>{
item.sub.map((item,index) =>{
item.sub.map((item,index) =>{
if(item.id == selectId){
item.tag = false
}
})
})
})

// 重新赋值
this.setState({
myApplyData:data,
otherApplyData:otherData
})

}

/**
* 点击其他应用
* */
otherAction =(item) =>{
var data = this.state.myApplyData // 我的应用数据
var otherData = this.state.otherApplyData //其他应用数据
var selectId = item.id //id
console.log(item)
//根据数据中tag值判断
if(item.tag == true){
//在我的应用当中,需要去除
data.map((item,index) =>{
if(item.id == selectId){
data.splice(index,1)
}
})
otherData.map((item,index) =>{
item.sub.map((item,index) =>{
item.sub.map((item,index) =>{
if(item.id == selectId){
item.tag = false
}
})
})
})

}else {
//不在我的应用当中,需要添加
data.push(item)
otherData.map((item,index) =>{
item.sub.map((item,index) =>{
item.sub.map((item,index) =>{
if(item.id == selectId){
item.tag = true
}
})
})
})

}

// 重新赋值
this.setState({
myApplyData:data,
otherApplyData:otherData
})


}

/**
* 去详情页面
* */
goDetailsAction = item => {
alert('去详情')
}

render() {
return (
<View style={styles.container}>
{/*我的应用条-编辑*/}
<MyApplyEdit
applyEditData={this.state.myApplyData}
editAction={() => {
this.editAction()
}}
/>
<ScrollView>
{/*我的应用*/}
<View style={{ marginTop: 10, backgroundColor: '#ffffff' }}>
<View
style={{
flexDirection: 'row',
alignItems: 'center',
marginTop: 10,
}}
>
<View
style={{
marginLeft: 10,
width: 8,
height: 20,
backgroundColor: 'blue',
}}
/>
<Text style={{ marginLeft: 10, fontWeight: '700' }}>
我的应用
</Text>
</View>
<FlatList
data={this.state.myApplyData}
style={{ marginBottom: 20 }}
renderItem={item => this.renderMyApplyRow(item)}
keyExtractor={this.keyMyApplyExtractor}
numColumns={4}
/>
</View>
{/*其他应用*/}
{this.state.otherApplyData.map((item, index) => (
<View key={index}>
{/*标题*/}
<View
style={{
paddingTop: 10,
alignItems: 'center',
backgroundColor: 'white',
flexDirection: 'row',
alignItems: 'center',
marginTop: 10,
}}
>
<View
style={{
marginLeft: 10,
width: 8,
height: 20,
backgroundColor: 'blue',
}}
/>
<Text style={{ marginLeft: 10, fontWeight: '700' }}>
{item.title}
</Text>
</View>
{/*主体内容*/}
<ScrollableTabView
style={{ backgroundColor: 'white' }}
tabBarActiveTextColor="#118EE9"
renderTabBar={() => <TabBar underlineColor="#118EE9" />}
>
{item.sub.map((item, index) => (
<View key={index} tabLabel={{ label: item.subTitle }}>
<ScrollView>
<View
style={{
flexDirection: 'row',
height: 250,
flexWrap: 'wrap',
}}
>
{item.sub.map((item, index) => (
<TouchableOpacity
key={index}
onPress={() => this.goDetailsAction(item)}
>
<View style={{ marginTop: 25 }}>
<Image
style={{
width: 55,
height: 55,
marginLeft: (width - 55 * 4) / 8,
marginRight: (width - 55 * 4) / 8,
}}
source={{ uri: item.icon }}
/>
<Text
style={{
alignSelf: 'center',
marginTop: 15,
marginBottom: 10,
}}
>
{item.name}
</Text>
<TouchableOpacity
style={{
position: 'absolute',
top: -10,
right: 10,
}}
onPress={() => this.otherAction(item)}
>
<Image
source={
item.tag ? require('./image/sub.png') : require('./image/add.png')
}
style={{
opacity: this.state.startEdit ? 1 : 0,
width: 15,
height: 15,
}}
/>
</TouchableOpacity>
</View>
</TouchableOpacity>
))}
</View>
</ScrollView>
</View>
))}
</ScrollableTabView>
</View>
))}
</ScrollView>
</View>
)
}


//-------------------------------我的应用start --------------------------------

/**
* 我的应用render
* */
renderMyApplyRow = item => (
<TouchableOpacity onPress={() => this.goDetailsAction(item)}>
<View style={{ marginTop: 25 }}>
<Image
style={{
width: 55,
height: 55,
marginLeft: (width - 55 * 4) / 8,
marginRight: (width - 55 * 4) / 8,
}}
source={{ uri: item.item.icon }}
/>
<Text style={{ alignSelf: 'center', marginTop: 15, marginBottom: 10 }}>
{item.item.name}
</Text>
<TouchableOpacity
style={{ position: 'absolute', top: -10, right: 10 }}
onPress={() => this.subAction(item)}
>
<Image
source={require('./image/sub.png')}
style={{
opacity: this.state.startEdit ? 1 : 0,
width: 15,
height: 15,
}}
/>
</TouchableOpacity>
</View>
</TouchableOpacity>
)

// 使用json中的key动态绑定key
keyMyApplyExtractor = item => item.id

//-------------------------------我的应用end --------------------------------

}


// 上方的编辑 我的应用框 UI
class MyApplyEdit extends React.Component {
render() {
const { applyEditData } = this.props
return (
<View
style={{
paddingTop: 5,
paddingBottom: 5,
alignItems: 'center',
flexDirection: 'row',
backgroundColor: '#ffffff',
}}
>
<Text style={{ marginLeft: 10, fontWeight: '700' }}>我的应用</Text>
<ScrollView
showsHorizontalScrollIndicator={false}
showsVerticalScrollIndicator={false}
horizontal={true}
style={{ marginRight: 15 }}
>
{applyEditData.map((item, index) => (
<Image
key={index}
style={{ width: 30, height: 30, marginLeft: 10 }}
source={{ uri: item.icon }}
/>
))}
</ScrollView>
<TouchableOpacity onPress={() => this.props.editAction()}>
<View
style={{
borderRadius: 4,
marginRight: 10,
paddingTop: 5,
paddingBottom: 5,
paddingLeft: 10,
paddingRight: 10,
borderWidth: 1,
borderColor: 'blue',
}}
>
<Text style={{ color: 'blue' }}>编辑</Text>
</View>
</TouchableOpacity>
</View>
)
}
}


const styles = StyleSheet.create({
container: {
flex: 1,
},
icon: {
width: 22,
height: 22,
},
})


第二种实现

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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
/**
* UI 通过 外部FlatList 内部 ScrollView + view 实现 (使用三方库react-native-scrollable-tab-view&&react-native-underline-tabbar)
* 逻辑 通过 数据中 id 和 tag实现
* */
import React, { Component } from 'react'
import {
StyleSheet,
View,
Image,
Text,
Dimensions,
TouchableOpacity,
FlatList,
Linking,
ScrollView
} from 'react-native'
const { width } = Dimensions.get('window')
import ScrollableTabView from 'react-native-scrollable-tab-view'
import TabBar from 'react-native-underline-tabbar'

export default class Two extends Component {
// 构造
constructor(props) {
super(props)
// 初始状态
this.state = {
startEdit: false, // 是否点击了编辑 默认未点击false
myApplyData: [],
otherApplyData: [],
applyData: [
{
title: '我的应用',
sub: [
{
id: '10086',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqgy1fu39hosiwoj30j60qyq96.jpg',
name: '价费通10086',
},
{
id: '10010',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftzsj15hgvj30sg15hkbw.jpg',
name: '展示中心10010',
}
],
},
{
title: '政务服务',
sub: [
{
subTitle: '政企',
sub: [
{
id: '10086',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqgy1fu39hosiwoj30j60qyq96.jpg',
name: '价费通10086',
tag: true,
},
{
id: '10010',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftzsj15hgvj30sg15hkbw.jpg',
name: '展示中心10010',
tag: true,
},
{
id: '9',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftzsj15hgvj30sg15hkbw.jpg',
name: '办事平台',
tag: false,
},
{
id: '10',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqgy1ftwcw4f4a5j30sg10j1g9.jpg',
name: '少儿图书馆',
tag: false,
},
],
},
{
subTitle: '第三方服务',
sub: [
{
id: '11',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftzsj15hgvj30sg15hkbw.jpg',
name: '价费通',
tag: false,
},
{
id: '12',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqgy1ftwcw4f4a5j30sg10j1g9.jpg',
name: '价费通',
tag: false,
},
{
id: '13',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftzsj15hgvj30sg15hkbw.jpg',
name: '价费通',
tag: false,
},
{
id: '14',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqgy1ftwcw4f4a5j30sg10j1g9.jpg',
name: '价费通',
tag: false,
},
{
id: '15',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqgy1ftwcw4f4a5j30sg10j1g9.jpg',
name: '价费通',
tag: false,
},
{
id: '16',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftu6gl83ewj30k80tites.jpg',
name: '价费通',
tag: false,
},
{
id: '17',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftu6gl83ewj30k80tites.jpg',
name: '价费通',
tag: false,
},
{
id: '18',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftu6gl83ewj30k80tites.jpg',
name: '价费通',
tag: false,
},
],
},
],
},
{
title: '政企应用',
sub: [
{
subTitle: '按主题',
sub: [
{
id: '19',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftdtot8zd3j30ju0pt137.jpg',
name: '价费通',
tag: false,
},
{
id: '20',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ft5q7ys128j30sg10gnk5.jpg',
name: '价费通',
tag: false,
},
],
},
{
subTitle: '按部门',
sub: [
{
id: '21',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ftdtot8zd3j30ju0pt137.jpg',
name: '价费通',
tag: false,
},
],
},
{
subTitle: '按证件',
sub: [
{
id: '22',
icon:
'https://ww1.sinaimg.cn/large/0065oQSqly1ft5q7ys128j30sg10gnk5.jpg',
name: '价费通',
tag: false,
},
],
},
{
subTitle: '主体周期',
sub: [
{
id: '23',
icon:
'http://ww1.sinaimg.cn/large/0065oQSqly1fsoe3k2gkkj30g50niwla.jpg',
name: '价费通',
tag: false,
},
{
id: '24',
icon:
'http://ww1.sinaimg.cn/large/0065oQSqly1fsoe3k2gkkj30g50niwla.jpg',
name: '价费通',
tag: false,
},
],
},
],
},
],
}
}

componentDidMount() {
var data = this.state.applyData
//赋值 我的应用数据
this.setState({
myApplyData: data[0].sub,
})
//赋值 其他应用数据
this.setState({
otherApplyData: data.slice(1),
})
}


render() {
return (
<View>
{/*我的应用条-编辑*/}
<MyApplyEdit
applyEditData={this.state.myApplyData}
editAction={() => {
this.editAction()
}}
/>
{/*应用列表*/}
<FlatList
data={this.state.otherApplyData}
style={{ marginBottom: 20 }}
ListHeaderComponent={this.ListHeaderComponent}
renderItem={item => this.renderItem(item)}
keyExtractor={this.keyExtractor}
/>
</View>
)
}

/**
* 去详情
* */
goDetailsAction =(item) =>{
alert('去详情')
}

/**
* 去除我的应用
* */
subAction = item => {
var data = this.state.myApplyData // 我的应用数据
var otherData = this.state.otherApplyData //其他应用数据
var selectId = item.id // 选中的id

//修改我的应用数据源
data.map((item,index) =>{
if(item.id == selectId){
data.splice(index,1)
}
})

//修改其他应用数据源
otherData.map((item,index) =>{
item.sub.map((item,index) =>{
item.sub.map((item,index) =>{
if(item.id == selectId){
item.tag = false
}
})
})
})

// 重新赋值
this.setState({
myApplyData:data,
otherApplyData:otherData
})

}

/**
* 点击其他应用
* */
otherAction =(item) =>{
var data = this.state.myApplyData // 我的应用数据
var otherData = this.state.otherApplyData //其他应用数据
var selectId = item.id //id
console.log(item)
//根据数据中tag值判断
if(item.tag == true){
//在我的应用当中,需要去除
data.map((item,index) =>{
if(item.id == selectId){
data.splice(index,1)
}
})
otherData.map((item,index) =>{
item.sub.map((item,index) =>{
item.sub.map((item,index) =>{
if(item.id == selectId){
item.tag = false
}
})
})
})

}else {
//不在我的应用当中,需要添加
data.push(item)
otherData.map((item,index) =>{
item.sub.map((item,index) =>{
item.sub.map((item,index) =>{
if(item.id == selectId){
item.tag = true
}
})
})
})

}

// 重新赋值
this.setState({
myApplyData:data,
otherApplyData:otherData
})


}

ListHeaderComponent =()=>{
var data = this.state.myApplyData
return(
<View style={{marginTop:10}}>
<HeaderView title='我的应用'/>
<View style={{flexDirection:'row',backgroundColor:'#ffffff'}}>
{
data.map((item,index) =>(
<TouchableOpacity key={index} onPress={() => this.goDetailsAction(item)}>
<View style={{ marginTop: 25 }}>
<Image
style={{
width: 55,
height: 55,
marginLeft: (width - 55 * 4) / 8,
marginRight: (width - 55 * 4) / 8,
}}
source={{ uri: item.icon }}
/>
<Text style={{ alignSelf: 'center', marginTop: 15, marginBottom: 10 }}>
{item.name}
</Text>
<TouchableOpacity
style={{ position: 'absolute', top: -10, right: 10 }}
onPress={() => this.subAction(item)}
>
<Image
source={require('./image/sub.png')}
style={{
opacity: this.state.startEdit ? 1 : 0,
width: 15,
height: 15,
}}
/>
</TouchableOpacity>
</View>
</TouchableOpacity>
))
}
</View>
</View>
)
}

renderItem =(item)=>{
console.log(item)
return(
<View style={{marginTop:10}}>
<HeaderView title={item.item.title}/>
<ScrollableTabView
style={{ backgroundColor: 'white' }}
tabBarActiveTextColor="#118EE9"
renderTabBar={() => <TabBar underlineColor="#118EE9" />}
>
{item.item.sub.map((item, index) => (
<View key={index} tabLabel={{ label: item.subTitle }}>
<ScrollView>
<View
style={{
flexDirection: 'row',
height: 250,
flexWrap: 'wrap',
}}
>
{item.sub.map((item, index) => (
<TouchableOpacity
key={index}
onPress={() => this.goDetailsAction(item)}
>
<View style={{ marginTop: 25 }}>
<Image
style={{
width: 55,
height: 55,
marginLeft: (width - 55 * 4) / 8,
marginRight: (width - 55 * 4) / 8,
}}
source={{ uri: item.icon }}
/>
<Text
style={{
alignSelf: 'center',
marginTop: 15,
marginBottom: 10,
}}
>
{item.name}
</Text>
<TouchableOpacity
style={{
position: 'absolute',
top: -10,
right: 10,
}}
onPress={() => this.otherAction(item)}
>
<Image
source={
item.tag ? require('./image/sub.png') : require('./image/add.png')
}
style={{
opacity: this.state.startEdit ? 1 : 0,
width: 15,
height: 15,
}}
/>
</TouchableOpacity>
</View>
</TouchableOpacity>
))}
</View>
</ScrollView>
</View>
))}
</ScrollableTabView>
</View>
)
}

keyExtractor = item => item.title



/**
* 点击编辑
* */
editAction = () => {
this.setState({
startEdit:!this.state.startEdit
})
}


}


// 上方的编辑 我的应用框 UI
class MyApplyEdit extends React.Component {
render() {
const { applyEditData } = this.props
return (
<View
style={{
paddingTop: 5,
paddingBottom: 5,
alignItems: 'center',
flexDirection: 'row',
backgroundColor: '#ffffff',
}}
>
<Text style={{ marginLeft: 10, fontWeight: '700' }}>我的应用</Text>
<ScrollView
showsHorizontalScrollIndicator={false}
showsVerticalScrollIndicator={false}
horizontal={true}
style={{ marginRight: 15 }}
>
{applyEditData.map((item, index) => (
<Image
key={index}
style={{ width: 30, height: 30, marginLeft: 10 }}
source={{ uri: item.icon }}
/>
))}
</ScrollView>
<TouchableOpacity onPress={() => this.props.editAction()}>
<View
style={{
borderRadius: 4,
marginRight: 10,
paddingTop: 5,
paddingBottom: 5,
paddingLeft: 10,
paddingRight: 10,
borderWidth: 1,
borderColor: 'blue',
}}
>
<Text style={{ color: 'blue' }}>编辑</Text>
</View>
</TouchableOpacity>
</View>
)
}
}


// 头视图
class HeaderView extends React.Component {
render() {
const { title } = this.props
return (
<View
style={{
backgroundColor:'#ffffff',
flexDirection: 'row',
alignItems: 'center',
paddingTop:10
}}
>
<View
style={{
marginLeft: 10,
width: 8,
height: 20,
backgroundColor: 'blue',
}}
/>
<Text style={{ marginLeft: 10, fontWeight: '700' }}>
{title}
</Text>
</View>
)
}
}


const styles = StyleSheet.create({
container: {
flex: 1,
},
icon: {
width: 22,
height: 22,
},
})


以后就是两种实现,基本的功能实现了,至于细节优化点等日后慢慢再做吧.
源码