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

Add _NavigationViewScrollBehavior #279

Merged
merged 2 commits into from
Apr 10, 2022
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Date format: DD/MM/YYYY

## [3.10.3]

- Do not use duplicated `Scrollbar`s ([#279](https://github.com/bdlukaa/fluent_ui/pull/279/))

## [3.10.2] - [09/04/2022]

- `NavigationView` without pane no longer throws error ([#276](https://github.com/bdlukaa/fluent_ui/issues/276))
Expand Down
50 changes: 17 additions & 33 deletions lib/src/controls/navigation/navigation_view/pane.dart
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,11 @@ class _TopNavigationPane extends StatelessWidget {
_TopNavigationPane({
required this.pane,
this.listKey,
this.scrollbarKey,
this.appBar,
}) : super(key: pane.key);

final NavigationPane pane;
final GlobalKey? listKey;
final GlobalKey? scrollbarKey;
final NavigationAppBar? appBar;

Widget _buildItem(BuildContext context, NavigationPaneItem item) {
Expand Down Expand Up @@ -465,14 +463,12 @@ class _CompactNavigationPane extends StatelessWidget {
required this.pane,
this.paneKey,
this.listKey,
this.scrollbarKey,
this.onToggle,
}) : super(key: pane.key);

final NavigationPane pane;
final Key? paneKey;
final GlobalKey? listKey;
final GlobalKey? scrollbarKey;
final VoidCallback? onToggle;

Widget _buildItem(BuildContext context, NavigationPaneItem item) {
Expand Down Expand Up @@ -544,17 +540,12 @@ class _CompactNavigationPane extends StatelessWidget {
),
),
Expanded(
child: Scrollbar(
key: scrollbarKey,
controller: pane.scrollController,
isAlwaysShown: false,
child: ListView(
key: listKey,
primary: true,
children: pane.items.map((item) {
return _buildItem(context, item);
}).toList(),
),
child: ListView(
key: listKey,
primary: true,
children: pane.items.map((item) {
return _buildItem(context, item);
}).toList(),
),
),
ListView(
Expand All @@ -577,15 +568,13 @@ class _OpenNavigationPane extends StatefulWidget {
required this.theme,
this.paneKey,
this.listKey,
this.scrollbarKey,
this.onToggle,
this.onItemSelected,
}) : super(key: pane.key);

final NavigationPane pane;
final Key? paneKey;
final GlobalKey? listKey;
final GlobalKey? scrollbarKey;
final VoidCallback? onToggle;
final VoidCallback? onItemSelected;

Expand Down Expand Up @@ -715,22 +704,17 @@ class _OpenNavigationPaneState extends State<_OpenNavigationPane>
child: widget.pane.autoSuggestBox!,
),
Expanded(
child: Scrollbar(
key: widget.scrollbarKey,
controller: widget.pane.scrollController,
isAlwaysShown: false,
child: ListView(
key: widget.listKey,
primary: true,
children: widget.pane.items.map((item) {
return _OpenNavigationPane.buildItem(
context,
widget.pane,
item,
widget.onItemSelected,
);
}).toList(),
),
child: ListView(
key: widget.listKey,
primary: true,
children: widget.pane.items.map((item) {
return _OpenNavigationPane.buildItem(
context,
widget.pane,
item,
widget.onItemSelected,
);
}).toList(),
),
),
ListView(
Expand Down
48 changes: 33 additions & 15 deletions lib/src/controls/navigation/navigation_view/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class NavigationViewState extends State<NavigationView> {
/// The key used to animate between open and compact display mode
final _panelKey = GlobalKey();
final _listKey = GlobalKey();
final _scrollbarKey = GlobalKey();
final _contentKey = GlobalKey();
final _overlayKey = GlobalKey();

Expand Down Expand Up @@ -298,12 +297,10 @@ class NavigationViewState extends State<NavigationView> {
case PaneDisplayMode.top:
paneResult = Column(children: [
appBar,
PrimaryScrollController(
controller: scrollController,
PaneScrollConfiguration(
child: _TopNavigationPane(
pane: pane,
listKey: _listKey,
scrollbarKey: _scrollbarKey,
appBar: widget.appBar,
),
),
Expand Down Expand Up @@ -348,8 +345,7 @@ class NavigationViewState extends State<NavigationView> {
),
),
),
PrimaryScrollController(
controller: scrollController,
PaneScrollConfiguration(
child: () {
if (openedWithoutOverlay) {
return Mica(
Expand All @@ -363,7 +359,6 @@ class NavigationViewState extends State<NavigationView> {
pane: pane,
paneKey: _panelKey,
listKey: _listKey,
scrollbarKey: _scrollbarKey,
onToggle: toggleCompactOpenMode,
onItemSelected: toggleCompactOpenMode,
),
Expand All @@ -389,7 +384,6 @@ class NavigationViewState extends State<NavigationView> {
pane: pane,
paneKey: _panelKey,
listKey: _listKey,
scrollbarKey: _scrollbarKey,
onToggle: toggleCompactOpenMode,
onItemSelected: toggleCompactOpenMode,
),
Expand All @@ -405,7 +399,6 @@ class NavigationViewState extends State<NavigationView> {
pane: pane,
paneKey: _panelKey,
listKey: _listKey,
scrollbarKey: _scrollbarKey,
onToggle: toggleCompactOpenMode,
),
),
Expand All @@ -421,14 +414,12 @@ class NavigationViewState extends State<NavigationView> {
appBar,
Expanded(
child: Row(children: [
PrimaryScrollController(
controller: scrollController,
PaneScrollConfiguration(
child: _OpenNavigationPane(
theme: theme,
pane: pane,
paneKey: _panelKey,
listKey: _listKey,
scrollbarKey: _scrollbarKey,
),
),
Expanded(child: content),
Expand Down Expand Up @@ -466,8 +457,7 @@ class NavigationViewState extends State<NavigationView> {
start: _minimalPaneOpen ? 0.0 : -_kOpenNavigationPanelWidth,
width: _kOpenNavigationPanelWidth,
height: MediaQuery.of(context).size.height,
child: PrimaryScrollController(
controller: scrollController,
child: PaneScrollConfiguration(
child: Mica(
backgroundColor: _overlayBackgroundColor(),
elevation: 10.0,
Expand All @@ -486,7 +476,6 @@ class NavigationViewState extends State<NavigationView> {
pane: pane,
paneKey: _panelKey,
listKey: _listKey,
scrollbarKey: _scrollbarKey,
onItemSelected: () {
setState(() => _minimalPaneOpen = false);
},
Expand Down Expand Up @@ -523,6 +512,17 @@ class NavigationViewState extends State<NavigationView> {
);
});
}

// ignore: non_constant_identifier_names
Widget PaneScrollConfiguration({required Widget child}) {
return PrimaryScrollController(
controller: scrollController,
child: ScrollConfiguration(
behavior: const _NavigationViewScrollBehavior(),
child: child,
),
);
}
}

/// The bar displayed at the top of the app. It can adapt itself to
Expand Down Expand Up @@ -745,3 +745,21 @@ class _NavigationAppBar extends StatelessWidget {
);
}
}

class _NavigationViewScrollBehavior extends ScrollBehavior {
const _NavigationViewScrollBehavior({
this.scrollbarKey,
});

final Key? scrollbarKey;

@override
Widget buildScrollbar(context, child, details) {
return Scrollbar(
key: scrollbarKey,
controller: PrimaryScrollController.of(context),
isAlwaysShown: false,
child: child,
);
}
}
13 changes: 13 additions & 0 deletions lib/src/controls/navigation/tab_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ class _TabViewState extends State<TabView> {
if (widget.bodies.isNotEmpty)
Expanded(child: widget.bodies[widget.currentIndex]),
]);
tabBar = ScrollConfiguration(
behavior: const _TabViewScrollBehavior(),
child: tabBar,
);
if (widget.shortcutsEnabled) {
void _onClosePressed() {
widget.tabs[widget.currentIndex].onClosed?.call();
Expand Down Expand Up @@ -793,3 +797,12 @@ class _TabPainter extends CustomPainter {
@override
bool shouldRebuildSemantics(_TabPainter oldDelegate) => false;
}

class _TabViewScrollBehavior extends ScrollBehavior {
const _TabViewScrollBehavior();

@override
Widget buildScrollbar(context, child, details) {
return child;
}
}