Commit cf71fecf authored by Matt Perry's avatar Matt Perry

Fix tab indicator animation so it doesn't snap to the previous tab.

If you tap multiple tabs in a row, the tab animation used to snap to the
last selected tab when starting a new animation. Fix that.

Also use the BuilderTransition so we don't have to rebuild the tab bar
every frame.
parent de7d8efc
...@@ -21,6 +21,7 @@ import 'package:sky/widgets/icon.dart'; ...@@ -21,6 +21,7 @@ import 'package:sky/widgets/icon.dart';
import 'package:sky/widgets/ink_well.dart'; import 'package:sky/widgets/ink_well.dart';
import 'package:sky/widgets/scrollable.dart'; import 'package:sky/widgets/scrollable.dart';
import 'package:sky/widgets/theme.dart'; import 'package:sky/widgets/theme.dart';
import 'package:sky/widgets/transitions.dart';
import 'package:sky/widgets/framework.dart'; import 'package:sky/widgets/framework.dart';
import 'package:vector_math/vector_math.dart'; import 'package:vector_math/vector_math.dart';
...@@ -425,26 +426,11 @@ class TabBar extends Scrollable { ...@@ -425,26 +426,11 @@ class TabBar extends Scrollable {
scrollBehavior.isScrollable = source.isScrollable; scrollBehavior.isScrollable = source.isScrollable;
} }
void didMount() {
_indicatorAnimation.addListener(_indicatorAnimationUpdated);
super.didMount();
}
void didUnmount() {
_indicatorAnimation.removeListener(_indicatorAnimationUpdated);
super.didUnmount();
}
void _indicatorAnimationUpdated() {
setState(() {
});
}
AnimatedRect get _indicatorRect => _indicatorAnimation.variable as AnimatedRect; AnimatedRect get _indicatorRect => _indicatorAnimation.variable as AnimatedRect;
void _startIndicatorAnimation(int fromTabIndex, int toTabIndex) { void _startIndicatorAnimation(int fromTabIndex, int toTabIndex) {
_indicatorRect _indicatorRect
..begin = _tabIndicatorRect(fromTabIndex) ..begin = (_indicatorRect.value == null ? _tabIndicatorRect(fromTabIndex) : _indicatorRect.value)
..end = _tabIndicatorRect(toTabIndex); ..end = _tabIndicatorRect(toTabIndex);
_indicatorAnimation _indicatorAnimation
..progress = 0.0 ..progress = 0.0
...@@ -554,15 +540,22 @@ class TabBar extends Scrollable { ...@@ -554,15 +540,22 @@ class TabBar extends Scrollable {
data: new IconThemeData(color: iconThemeColor), data: new IconThemeData(color: iconThemeColor),
child: new DefaultTextStyle( child: new DefaultTextStyle(
style: textStyle, style: textStyle,
child: new TabBarWrapper( child: new BuilderTransition(
children: tabs, variables: [_indicatorRect],
selectedIndex: selectedIndex, direction: Direction.forward,
backgroundColor: backgroundColor, performance: _indicatorAnimation,
indicatorColor: indicatorColor, builder: () {
indicatorRect: _indicatorRect.value, return new TabBarWrapper(
textAndIcons: textAndIcons, children: tabs,
isScrollable: isScrollable, selectedIndex: selectedIndex,
onLayoutChanged: _layoutChanged backgroundColor: backgroundColor,
indicatorColor: indicatorColor,
indicatorRect: _indicatorRect.value,
textAndIcons: textAndIcons,
isScrollable: isScrollable,
onLayoutChanged: _layoutChanged
);
}
) )
) )
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment