Fix TabBar jag when user interrupts ballistic scroll (#64380)

This commit is contained in:
Hansol Lee
2020-09-10 07:35:05 +09:00
committed by GitHub
parent 127e67902e
commit 389b5b6c3a
2 changed files with 46 additions and 0 deletions

View File

@@ -1347,6 +1347,8 @@ class _TabBarViewState extends State<TabBarView> {
} else if (notification is ScrollEndNotification) {
_controller.index = _pageController.page.round();
_currentIndex = _controller.index;
if (!_controller.indexIsChanging)
_controller.offset = (_pageController.page - _controller.index).clamp(-1.0, 1.0) as double;
}
_warpUnderwayCount -= 1;

View File

@@ -2728,6 +2728,50 @@ void main() {
// There was a time where this would throw an exception
// because we tried to send a notification on dispose.
});
testWidgets('TabController\'s animation value should be in sync with TabBarView\'s scroll value when user interrupts ballistic scroll', (WidgetTester tester) async {
final TabController tabController = TabController(
vsync: const TestVSync(),
length: 3,
);
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: SizedBox.expand(
child: Center(
child: SizedBox(
width: 400.0,
height: 400.0,
child: TabBarView(
controller: tabController,
children: const <Widget>[
Center(child: Text('0')),
Center(child: Text('1')),
Center(child: Text('2')),
],
),
),
),
),
));
final PageView pageView = tester.widget(find.byType(PageView));
final PageController pageController = pageView.controller;
final ScrollPosition position = pageController.position;
expect(tabController.index, 0);
expect(position.pixels, 0.0);
pageController.jumpTo(300.0);
await tester.pump();
expect(tabController.animation.value, pageController.page);
// Touch TabBarView while ballistic scrolling is happening and
// check if tabController's animation value properly follows page value.
await tester.startGesture(tester.getCenter(find.byType(PageView)));
await tester.pump();
expect(tabController.animation.value, pageController.page);
});
}
class KeepAliveInk extends StatefulWidget {