1
1
import React , { Component } from 'react' ;
2
2
import { ActivityIndicator } from 'react-native' ;
3
3
import {
4
+ Assets ,
4
5
TabController ,
5
6
Colors ,
6
7
View ,
@@ -28,16 +29,21 @@ const TABS = [
28
29
] ;
29
30
30
31
class TabControllerScreen extends Component {
31
- state = {
32
- asCarousel : true ,
33
- centerSelected : false ,
34
- fewItems : false ,
35
- selectedIndex : 0 ,
36
- items : _ . chain ( TABS )
37
- . map ( ( tab ) => ( { label : tab , key : tab } ) )
38
- . value ( ) ,
39
- key : Date . now ( )
40
- } ;
32
+ constructor ( props ) {
33
+ super ( props ) ;
34
+
35
+
36
+ this . state = {
37
+ asCarousel : true ,
38
+ centerSelected : false ,
39
+ fewItems : false ,
40
+ selectedIndex : 0 ,
41
+ key : Date . now ( )
42
+ } ;
43
+
44
+ const items = this . generateTabItems ( ) ;
45
+ this . state . items = items ;
46
+ }
41
47
42
48
componentDidMount ( ) {
43
49
// this.slow();
@@ -53,33 +59,25 @@ class TabControllerScreen extends Component {
53
59
} , 10 ) ;
54
60
}
55
61
56
- addTab = ( ) => {
57
- const { tabsCount} = this . state ;
62
+ onAddItem = ( ) => {
63
+ console . warn ( 'Add Item' ) ;
64
+ }
58
65
59
- if ( tabsCount < 6 ) {
60
- this . setState ( {
61
- tabsCount : tabsCount + 1 ,
62
- key : Date . now ( ) ,
63
- selectedIndex : tabsCount
64
- } ) ;
66
+ generateTabItems = ( fewItems = this . state . fewItems , centerSelected = this . state . centerSelected ) => {
67
+ let items = _ . chain ( TABS )
68
+ . take ( fewItems ? 3 : TABS . length )
69
+ . map ( ( tab ) => ( { label : tab , key : tab } ) )
70
+ . value ( ) ;
71
+
72
+ if ( ! centerSelected ) {
73
+ items = [ ...items , { icon : Assets . icons . demo . add , key : 'add' , ignore : true , width : 60 , onPress : this . onAddItem } ] ;
65
74
}
66
- } ;
75
+ return items ;
76
+ }
67
77
68
78
toggleItemsCount = ( ) => {
69
79
const { fewItems} = this . state ;
70
-
71
- let items ;
72
- if ( fewItems ) {
73
- items = _ . chain ( TABS )
74
- . map ( ( tab ) => ( { label : tab , key : tab } ) )
75
- . value ( ) ;
76
- } else {
77
- items = _ . chain ( TABS )
78
- . take ( 3 )
79
- . map ( ( tab ) => ( { label : tab , key : tab } ) )
80
- . value ( ) ;
81
- }
82
-
80
+ const items = this . generateTabItems ( ! fewItems ) ;
83
81
this . setState ( { fewItems : ! fewItems , items, key : Date . now ( ) } ) ;
84
82
} ;
85
83
@@ -91,8 +89,10 @@ class TabControllerScreen extends Component {
91
89
} ;
92
90
93
91
toggleCenterSelected = ( ) => {
92
+ const { fewItems, centerSelected} = this . state ;
94
93
this . setState ( {
95
- centerSelected : ! this . state . centerSelected ,
94
+ items : this . generateTabItems ( fewItems , ! centerSelected ) ,
95
+ centerSelected : ! centerSelected ,
96
96
key : Date . now ( )
97
97
} ) ;
98
98
} ;
0 commit comments