Skip to content

Commit df2aa1c

Browse files
committed
minor fix in tab controller indicator animation
1 parent 00f29ab commit df2aa1c

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

src/incubator/TabController/TabBar.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,21 @@ import {Colors, Spacings} from '../../style';
1313
import {Constants} from '../../helpers';
1414

1515
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;
1731

1832
/**
1933
* @description: TabController's TabBar component
@@ -87,6 +101,7 @@ class TabBar extends PureComponent {
87101
_clock = new Clock();
88102
_itemsWidths = _.times(React.Children.count(this.props.children), () => null);
89103
_indicatorWidth = new Value(0);
104+
_prevIndicatorWidth = new Value(0);
90105
_prevOffset = new Value(0);
91106
_offset = new Value(0);
92107

@@ -113,11 +128,11 @@ class TabBar extends PureComponent {
113128
}
114129
};
115130

116-
runTiming(targetValue, duration) {
131+
runTiming(targetValue, prevValue, duration) {
117132
const clock = new Clock();
118133
const state = {
119134
finished: new Value(0),
120-
position: new Value(0),
135+
position: prevValue,
121136
time: new Value(0),
122137
frameTime: new Value(0),
123138
};
@@ -129,9 +144,15 @@ class TabBar extends PureComponent {
129144
};
130145

131146
return block([
132-
startClock(clock),
147+
cond(clockRunning(clock), [], [startClock(clock)]),
133148
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+
]),
135156
state.position,
136157
]);
137158
}
@@ -141,8 +162,8 @@ class TabBar extends PureComponent {
141162
const {indicatorStyle} = this.props;
142163
if (itemsWidths) {
143164
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),
146167
};
147168
return <Reanimated.View style={[styles.selectedIndicator, indicatorStyle, transitionStyle]} />;
148169
}
@@ -218,7 +239,6 @@ class TabBar extends PureComponent {
218239
}
219240
}
220241

221-
222242
const styles = StyleSheet.create({
223243
tabBar: {
224244
flex: 1,

0 commit comments

Comments
 (0)