@@ -13,7 +13,21 @@ import {Colors, Spacings} from '../../style';
13
13
import { Constants } from '../../helpers' ;
14
14
15
15
const DEFAULT_HEIGHT = 48 ;
16
- const { Code, Clock, Value, add, sub, cond, eq, stopClock, startClock, timing, block, set} = Reanimated ;
16
+ const {
17
+ Code,
18
+ Clock,
19
+ Value,
20
+ add,
21
+ sub,
22
+ cond,
23
+ eq,
24
+ stopClock,
25
+ startClock,
26
+ clockRunning,
27
+ timing,
28
+ block,
29
+ set,
30
+ } = Reanimated ;
17
31
18
32
/**
19
33
* @description : TabController's TabBar component
@@ -87,6 +101,7 @@ class TabBar extends PureComponent {
87
101
_clock = new Clock ( ) ;
88
102
_itemsWidths = _ . times ( React . Children . count ( this . props . children ) , ( ) => null ) ;
89
103
_indicatorWidth = new Value ( 0 ) ;
104
+ _prevIndicatorWidth = new Value ( 0 ) ;
90
105
_prevOffset = new Value ( 0 ) ;
91
106
_offset = new Value ( 0 ) ;
92
107
@@ -113,11 +128,11 @@ class TabBar extends PureComponent {
113
128
}
114
129
} ;
115
130
116
- runTiming ( targetValue , duration ) {
131
+ runTiming ( targetValue , prevValue , duration ) {
117
132
const clock = new Clock ( ) ;
118
133
const state = {
119
134
finished : new Value ( 0 ) ,
120
- position : new Value ( 0 ) ,
135
+ position : prevValue ,
121
136
time : new Value ( 0 ) ,
122
137
frameTime : new Value ( 0 ) ,
123
138
} ;
@@ -129,9 +144,15 @@ class TabBar extends PureComponent {
129
144
} ;
130
145
131
146
return block ( [
132
- startClock ( clock ) ,
147
+ cond ( clockRunning ( clock ) , [ ] , [ startClock ( clock ) ] ) ,
133
148
timing ( clock , state , config ) ,
134
- cond ( state . finished , [ stopClock ( clock ) , set ( state . finished , 0 ) , set ( state . time , 0 ) , set ( state . frameTime , 0 ) ] ) ,
149
+ cond ( state . finished , [
150
+ stopClock ( clock ) ,
151
+ set ( state . finished , 0 ) ,
152
+ set ( state . time , 0 ) ,
153
+ set ( state . frameTime , 0 ) ,
154
+ set ( prevValue , state . position ) ,
155
+ ] ) ,
135
156
state . position ,
136
157
] ) ;
137
158
}
@@ -141,8 +162,8 @@ class TabBar extends PureComponent {
141
162
const { indicatorStyle} = this . props ;
142
163
if ( itemsWidths ) {
143
164
const transitionStyle = {
144
- width : this . runTiming ( this . _indicatorWidth , 400 ) ,
145
- left : this . runTiming ( this . _offset , 300 ) ,
165
+ width : this . runTiming ( this . _indicatorWidth , this . _prevIndicatorWidth , 300 ) ,
166
+ left : this . runTiming ( this . _offset , this . _prevOffset , 400 ) ,
146
167
} ;
147
168
return < Reanimated . View style = { [ styles . selectedIndicator , indicatorStyle , transitionStyle ] } /> ;
148
169
}
@@ -218,7 +239,6 @@ class TabBar extends PureComponent {
218
239
}
219
240
}
220
241
221
-
222
242
const styles = StyleSheet . create ( {
223
243
tabBar : {
224
244
flex : 1 ,
0 commit comments