Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix tab view wheel scroll #772

Merged
merged 5 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [next]

- Fix `TabView` scroll (the item count was not correctly set) and now the scroll event is not propagated to the parent. ([#772](https://github.com/bdlukaa/fluent_ui/pull/772))
- Do not calculate the position of the flyout if the `position` parameter is provided. ([#764](https://github.com/bdlukaa/fluent_ui/issues/764))
- Add source code for Surfaces/CommandBar in example application ([#766](https://github.com/bdlukaa/fluent_ui/pull/766))
- Do not enforce a max height on `PaneItem` ([#762](https://github.com/bdlukaa/fluent_ui/issues/762))
Expand Down
1 change: 0 additions & 1 deletion example/lib/screens/navigation/tab_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ class _TabViewPageState extends State<TabViewPage> with PageMixin {
tabWidthBehavior: tabWidthBehavior,
closeButtonVisibility: closeButtonVisibilityMode,
showScrollButtons: showScrollButtons,
wheelScroll: wheelScroll,
onNewPressed: () {
setState(() {
final index = tabs!.length + 1;
Expand Down
56 changes: 28 additions & 28 deletions lib/src/controls/navigation/tab_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class TabView extends StatefulWidget {
this.shortcutsEnabled = true,
this.onReorder,
this.showScrollButtons = true,
this.wheelScroll = false,
this.scrollController,
this.minTabWidth = _kMinTileWidth,
this.maxTabWidth = _kMaxTileWidth,
Expand All @@ -74,6 +73,8 @@ class TabView extends StatefulWidget {
this.header,
this.footer,
this.closeDelayDuration = const Duration(milliseconds: 400),
@Deprecated('This property is no longer used and will be removed in the next major release.')
this.wheelScroll = false,
}) : super(key: key);

/// The index of the tab to be displayed
Expand Down Expand Up @@ -127,11 +128,8 @@ class TabView extends StatefulWidget {
/// If null, a [ScrollPosController] is created internally.
final ScrollPosController? scrollController;

// TODO: remove this property when https://github.com/flutter/flutter/issues/75180
// is fixed
/// Indicate if the mouse wheel should scroll the TabView
///
/// Defaults to `false`.
@Deprecated('This property is no longer used and will be removed in the'
' next major release.')
final bool wheelScroll;

/// Indicates the close button visibility mode
Expand Down Expand Up @@ -238,7 +236,7 @@ class _TabViewState extends State<TabView> {
@override
void didUpdateWidget(TabView oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.tabs.length != oldWidget.tabs.length) {
if (widget.tabs.length != scrollController.itemCount) {
scrollController.itemCount = widget.tabs.length;
}
if (widget.currentIndex != oldWidget.currentIndex &&
Expand Down Expand Up @@ -444,24 +442,25 @@ class _TabViewState extends State<TabView> {
.clamp(widget.minTabWidth, widget.maxTabWidth);

final Widget listView = Listener(
onPointerSignal: widget.wheelScroll
? (PointerSignalEvent e) {
if (e is PointerScrollEvent &&
scrollController.hasClients) {
if (e.scrollDelta.dy > 0) {
scrollController.forward(
align: false,
animate: false,
);
} else {
scrollController.backward(
align: false,
animate: false,
);
}
}
onPointerSignal: (PointerSignalEvent e) {
if (e is PointerScrollEvent &&
scrollController.hasClients) {
GestureBinding.instance.pointerSignalResolver.register(e,
(PointerSignalEvent event) {
if (e.scrollDelta.dy > 0) {
scrollController.forward(
align: false,
animate: false,
);
} else {
scrollController.backward(
align: false,
animate: false,
);
}
: null,
});
}
},
child: Localizations.override(
context: context,
delegates: const [
Expand Down Expand Up @@ -507,9 +506,9 @@ class _TabViewState extends State<TabView> {
!scrollController.canBackward
? () {
if (direction == TextDirection.ltr) {
scrollController.backward();
scrollController.backward(align: false);
} else {
scrollController.forward();
scrollController.forward(align: false);
}
}
: null,
Expand All @@ -531,9 +530,9 @@ class _TabViewState extends State<TabView> {
!scrollController.canForward
? () {
if (direction == TextDirection.ltr) {
scrollController.forward();
scrollController.forward(align: false);
} else {
scrollController.backward();
scrollController.backward(align: false);
}
}
: null,
Expand Down Expand Up @@ -682,6 +681,7 @@ class _TabBody extends StatefulWidget {
class __TabBodyState extends State<_TabBody> {
final _pageKey = GlobalKey<State<PageView>>();
PageController? _pageController;

PageController get pageController => _pageController!;

@override
Expand Down