Skip to content

Commit

Permalink
Merge pull request #1 from ZHIN/fix_navigation_pane_size
Browse files Browse the repository at this point in the history
fix NavigationPaneSize #867
  • Loading branch information
ZHIN authored Jun 23, 2023
2 parents 4ee40a5 + c5316eb commit 483723d
Showing 1 changed file with 20 additions and 42 deletions.
62 changes: 20 additions & 42 deletions lib/src/controls/navigation/navigation_view/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class NavigationView extends StatefulWidget {
this.transitionBuilder,
this.paneBodyBuilder,
}) : assert(
(pane != null && content == null) ||
(pane == null && content != null),
(pane != null && content == null) || (pane == null && content != null),
'Either pane or content must be provided',
);

Expand Down Expand Up @@ -226,32 +225,25 @@ class NavigationViewState extends State<NavigationView> {
void didUpdateWidget(NavigationView oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.pane?.scrollController != paneScrollController) {
paneScrollController =
widget.pane?.scrollController ?? paneScrollController;
paneScrollController = widget.pane?.scrollController ?? paneScrollController;
}

if (oldWidget.pane?.selected != widget.pane?.selected) {
_oldIndex = oldWidget.pane?.selected ?? -1;

final item = widget.pane?.selected == null
? null
: widget.pane?.selectedItem.itemKey.currentContext;
final item = widget.pane?.selected == null ? null : widget.pane?.selectedItem.itemKey.currentContext;

if (item != null) {
final atEnd =
(widget.pane!.effectiveItems.length / 2) < widget.pane!.selected!;
final atEnd = (widget.pane!.effectiveItems.length / 2) < widget.pane!.selected!;

Scrollable.ensureVisible(
item,
alignmentPolicy: atEnd
? ScrollPositionAlignmentPolicy.keepVisibleAtEnd
: ScrollPositionAlignmentPolicy.keepVisibleAtStart,
alignmentPolicy: atEnd ? ScrollPositionAlignmentPolicy.keepVisibleAtEnd : ScrollPositionAlignmentPolicy.keepVisibleAtStart,
);
}
}

if (oldWidget.pane?.effectiveItems.length !=
widget.pane?.effectiveItems.length) {
if (oldWidget.pane?.effectiveItems.length != widget.pane?.effectiveItems.length) {
if (widget.pane?.effectiveItems.length != null) {
_generateKeys();
}
Expand Down Expand Up @@ -330,9 +322,7 @@ class NavigationViewState extends State<NavigationView> {
Widget? paneNavigationButton() {
final minimalLeading = PaneItem(
title: Text(
!minimalPaneOpen
? localizations.openNavigationTooltip
: localizations.closeNavigationTooltip,
!minimalPaneOpen ? localizations.openNavigationTooltip : localizations.closeNavigationTooltip,
),
icon: const Icon(FluentIcons.global_nav_button),
body: const SizedBox.shrink(),
Expand Down Expand Up @@ -384,9 +374,7 @@ class NavigationViewState extends State<NavigationView> {
appBar: widget.appBar!,
additionalLeading: () {
if (widget.pane != null) {
return displayMode == PaneDisplayMode.minimal
? paneNavigationButton()
: null;
return displayMode == PaneDisplayMode.minimal ? paneNavigationButton() : null;
}
}(),
);
Expand Down Expand Up @@ -428,8 +416,7 @@ class NavigationViewState extends State<NavigationView> {
final contentShape = widget.contentShape ??
RoundedRectangleBorder(
side: BorderSide(
color:
FluentTheme.of(context).resources.cardStrokeColorDefault,
color: FluentTheme.of(context).resources.cardStrokeColorDefault,
),
borderRadius: displayMode == PaneDisplayMode.top
? BorderRadius.zero
Expand Down Expand Up @@ -484,12 +471,10 @@ class NavigationViewState extends State<NavigationView> {
) as bool? ??
_compactOverlayOpen;

var openSize =
pane.size?.openPaneWidth ?? kOpenNavigationPaneWidth;
var openSize = pane.size?.openPaneWidth ?? kOpenNavigationPaneWidth;

final noOverlayRequired = consts.maxWidth / 2.5 > openSize;
final openedWithoutOverlay =
_compactOverlayOpen && consts.maxWidth / 2.5 > openSize;
final openedWithoutOverlay = _compactOverlayOpen && consts.maxWidth / 2.5 > openSize;

// print(
// 'open: $_compactOverlayOpen - without overlay:$openedWithoutOverlay - storage: ${PageStorage.of(context)?.readState(
Expand All @@ -509,8 +494,7 @@ class NavigationViewState extends State<NavigationView> {
key: _overlayKey,
backgroundColor: theme.backgroundColor,
child: Container(
margin:
const EdgeInsets.symmetric(vertical: 1.0),
margin: const EdgeInsets.symmetric(vertical: 1.0),
child: _OpenNavigationPane(
theme: theme,
pane: pane,
Expand Down Expand Up @@ -544,8 +528,7 @@ class NavigationViewState extends State<NavigationView> {
Padding(
padding: EdgeInsetsDirectional.only(
top: appBarPadding.resolve(direction).top,
start: pane.size?.compactWidth ??
kCompactNavigationPaneWidth,
start: pane.size?.compactWidth ?? kCompactNavigationPaneWidth,
),
child: content,
),
Expand Down Expand Up @@ -642,6 +625,8 @@ class NavigationViewState extends State<NavigationView> {
]);
break;
case PaneDisplayMode.minimal:
var openSize = pane.size?.openPaneWidth ?? kOpenNavigationPaneWidth;

paneResult = Stack(children: [
PositionedDirectional(
top: widget.appBar?.finalHeight(context) ?? 0.0,
Expand All @@ -666,8 +651,8 @@ class NavigationViewState extends State<NavigationView> {
key: _overlayKey,
duration: theme.animationDuration ?? Duration.zero,
curve: theme.animationCurve ?? Curves.linear,
start: minimalPaneOpen ? 0.0 : -kOpenNavigationPaneWidth,
width: kOpenNavigationPaneWidth,
start: minimalPaneOpen ? 0.0 : -openSize,
width: openSize,
height: mediaQuery.size.height,
child: PaneScrollConfiguration(
child: ColoredBox(
Expand Down Expand Up @@ -730,8 +715,7 @@ class NavigationViewState extends State<NavigationView> {
return PrimaryScrollController(
controller: paneScrollController,
child: ScrollConfiguration(
behavior: widget.pane?.scrollBehavior ??
const NavigationViewScrollBehavior(),
behavior: widget.pane?.scrollBehavior ?? const NavigationViewScrollBehavior(),
child: child,
),
);
Expand Down Expand Up @@ -879,8 +863,7 @@ class _NavigationAppBar extends StatelessWidget {

final mediaQuery = MediaQuery.of(context);

final displayMode = InheritedNavigationView.maybeOf(context)?.displayMode ??
PaneDisplayMode.top;
final displayMode = InheritedNavigationView.maybeOf(context)?.displayMode ?? PaneDisplayMode.top;
final leading = appBar._buildLeading(displayMode != PaneDisplayMode.top);
final title = () {
if (appBar.title != null) {
Expand All @@ -907,12 +890,7 @@ class _NavigationAppBar extends StatelessWidget {
late Widget result;
switch (displayMode) {
case PaneDisplayMode.top:
result = Row(children: [
leading,
if (additionalLeading != null) additionalLeading!,
title,
if (appBar.actions != null) Expanded(child: appBar.actions!)
]);
result = Row(children: [leading, if (additionalLeading != null) additionalLeading!, title, if (appBar.actions != null) Expanded(child: appBar.actions!)]);
break;
case PaneDisplayMode.minimal:
case PaneDisplayMode.open:
Expand Down

0 comments on commit 483723d

Please sign in to comment.