1
1
import _ from 'lodash' ;
2
2
import React , { Component } from 'react' ;
3
3
import { StyleSheet , ScrollView } from 'react-native' ;
4
- import { Colors , Typography , View , Button , TabBar } from 'react-native-ui-lib' ;
4
+ import { Colors , View , Button , TabBar } from 'react-native-ui-lib' ;
5
5
6
6
7
7
const labelsArray = [
@@ -16,30 +16,30 @@ const themeColors = [Colors.violet30, Colors.green30, Colors.red30, Colors.blue3
16
16
17
17
18
18
export default class TabBarScreen extends Component {
19
- constructor ( props ) {
20
- super ( props ) ;
21
-
22
- this . state = {
23
- selectedIndex : 1 ,
24
- selectedIndex1 : 1 ,
25
- labels : labelsArray [ 0 ] ,
26
- currentTabs : [ ] ,
27
- themeColor : themeColors [ 0 ]
28
- } ;
29
-
30
- this . counter = 0 ;
31
- this . colorCounter = 0 ;
32
- }
19
+ state = {
20
+ selectedIndex : 1 ,
21
+ selectedIndex1 : 1 ,
22
+ selectedIndex2 : 1 ,
23
+ labels : labelsArray [ 0 ] ,
24
+ currentTabs : [ ] ,
25
+ themeColor : themeColors [ 0 ]
26
+ } ;
27
+
28
+ counter = 0 ;
29
+ colorCounter = 0 ;
30
+ tabbar : any = undefined ;
33
31
34
32
/** Index change */
35
33
changeIndex = ( ) => {
36
34
let index ;
37
-
38
- do {
39
- index = Math . floor ( Math . random ( ) * this . tabbar . props . children . length ) ;
40
- } while ( index === this . state . selectedIndex ) ;
41
35
42
- this . setState ( { selectedIndex : index } ) ;
36
+ if ( this . tabbar ) {
37
+ do {
38
+ index = Math . floor ( Math . random ( ) * this . tabbar . props . children . length ) ;
39
+ } while ( index === this . state . selectedIndex ) ;
40
+
41
+ this . setState ( { selectedIndex : index } ) ;
42
+ }
43
43
} ;
44
44
45
45
/** Labels change */
@@ -74,8 +74,8 @@ export default class TabBarScreen extends Component {
74
74
addTab = ( ) => {
75
75
const random = Math . floor ( Math . random ( ) * 100000 ) ;
76
76
const newTabs = this . state . currentTabs ;
77
-
78
- newTabs . push ( { id : random , displayLabel : `tab # ${ this . state . currentTabs . length } ` } ) ;
77
+ const item = { id : random , displayLabel : `tab # ${ this . state . currentTabs . length } ` } ;
78
+ newTabs . push ( item ) ;
79
79
this . setState ( { currentTabs : newTabs } ) ;
80
80
} ;
81
81
@@ -90,7 +90,7 @@ export default class TabBarScreen extends Component {
90
90
} ;
91
91
92
92
/** Actions */
93
- getTabs ( showAddTab ) {
93
+ getTabs ( showAddTab : boolean ) {
94
94
const tabs = _ . map ( this . state . currentTabs , tab => this . renderTabs ( tab ) ) ;
95
95
96
96
if ( showAddTab ) {
@@ -104,7 +104,7 @@ export default class TabBarScreen extends Component {
104
104
}
105
105
106
106
/** Renders */
107
- renderTabs ( tab ) {
107
+ renderTabs ( tab : any ) {
108
108
return < TabBar . Item key = { tab . id } label = { tab . displayLabel } onPress = { tab . onPress } /> ;
109
109
}
110
110
@@ -154,8 +154,8 @@ export default class TabBarScreen extends Component {
154
154
</ TabBar >
155
155
156
156
< View center row >
157
- < Button size = { ' small' } margin-20 label = { `Add tabs` } onPress = { this . addTab } />
158
- < Button size = { ' small' } margin-20 label = { `Remove tabs` } onPress = { this . removeTab } />
157
+ < Button size = { Button . sizes . small } margin-20 label = { `Add tabs` } onPress = { this . addTab } />
158
+ < Button size = { Button . sizes . small } margin-20 label = { `Remove tabs` } onPress = { this . removeTab } />
159
159
</ View >
160
160
< TabBar style = { styles . tabbar } selectedIndex = { 0 } enableShadow >
161
161
{ this . getTabs ( false ) }
@@ -170,7 +170,7 @@ export default class TabBarScreen extends Component {
170
170
</ TabBar >
171
171
172
172
< Button
173
- size = { ' small' }
173
+ size = { Button . sizes . small }
174
174
margin-20
175
175
label = { `Change index: ${ this . state . selectedIndex } ` }
176
176
onPress = { this . changeIndex }
@@ -188,13 +188,13 @@ export default class TabBarScreen extends Component {
188
188
</ TabBar >
189
189
190
190
< View row >
191
- < Button size = { ' small' } margin-20 label = { `Change Labels` } onPress = { this . changeLabels } />
192
- < Button size = { ' small' } margin-20 label = { `Change Color` } onPress = { this . changeColors } />
191
+ < Button size = { Button . sizes . small } margin-20 label = { `Change Labels` } onPress = { this . changeLabels } />
192
+ < Button size = { Button . sizes . small } margin-20 label = { `Change Color` } onPress = { this . changeColors } />
193
193
</ View >
194
194
< TabBar
195
195
style = { styles . tabbar }
196
196
selectedIndex = { this . state . selectedIndex1 }
197
- onChangeIndex = { index => this . setState ( { selectedIndex1 : index } ) }
197
+ onChangeIndex = { ( index : number ) => this . setState ( { selectedIndex1 : index } ) }
198
198
indicatorStyle = { { backgroundColor : this . state . themeColor } }
199
199
enableShadow
200
200
>
@@ -205,7 +205,7 @@ export default class TabBarScreen extends Component {
205
205
< TabBar
206
206
style = { styles . tabbar }
207
207
selectedIndex = { this . state . selectedIndex2 }
208
- onChangeIndex = { index => this . setState ( { selectedIndex2 : index } ) }
208
+ onChangeIndex = { ( index : number ) => this . setState ( { selectedIndex2 : index } ) }
209
209
enableShadow
210
210
>
211
211
< TabBar . Item label = { this . state . labels [ 0 ] } />
0 commit comments