From 16c0332cd5a7bf495e4823d84f7e09a68bd7a445 Mon Sep 17 00:00:00 2001 From: CorvusYe Date: Wed, 29 May 2024 18:19:46 +0800 Subject: [PATCH 1/2] feat: Added `NavigationView.onItemPressed` callback, called when the item is on tap. --- CHANGELOG.md | 3 ++- .../screens/navigation/navigation_view.dart | 20 +++++++++++++++++++ .../navigation/navigation_view/pane.dart | 9 +++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a538f48..04a77144 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,13 @@ ## NEXT * fix: Scroll issue in `DatePicker`. ([#1054](https://github.com/bdlukaa/fluent_ui/issues/1054)) * feat: Add `NumberBox.textInputAction` and `NumberBox.onEditingComplete` ([#1063](https://github.com/bdlukaa/fluent_ui/pull/1063)) +* feat: Added `NavigationView.onItemPressed` callback, called when the item is on tap. ## 4.8.7 * fix: A child of `Button` has an unbound height constraint. ([#1039](https://github.com/bdlukaa/fluent_ui/issues/1039)) * feat: Added `DatePicker.fieldFlex` to control the width proportion of each field. ([#1053](https://github.com/bdlukaa/fluent_ui/pull/1053)) -* fix: `Slider` thumb is correct rendered when it's on the edges. ([#1046](https://github.com/bdlukaa/fluent_ui/pull/1046) +* fix: `Slider` thumb is correct rendered when it's on the edges. ([#1046](https://github.com/bdlukaa/fluent_ui/pull/1046)) * feat: Added `TabView.addIconBuilder` ([#1047](https://github.com/bdlukaa/fluent_ui/pull/1047)) ## 4.8.6 diff --git a/example/lib/screens/navigation/navigation_view.dart b/example/lib/screens/navigation/navigation_view.dart index 00a4485c..8693c80a 100644 --- a/example/lib/screens/navigation/navigation_view.dart +++ b/example/lib/screens/navigation/navigation_view.dart @@ -287,6 +287,16 @@ NavigationView( ), pane: NavigationPane( selected: topIndex, + onItemPressed: (index) { + // Do anything you want to do, such as: + if (index == topIndex) { + if (displayMode == PaneDisplayMode.open) { + setState(() => this.displayMode = PaneDisplayMode.compact); + } else if (displayMode == PaneDisplayMode.compact) { + setState(() => this.displayMode = PaneDisplayMode.open); + } + } + }, onChanged: (index) => setState(() => topIndex = index), displayMode: displayMode, items: items, @@ -329,6 +339,16 @@ NavigationView( }, pane: NavigationPane( selected: topIndex, + onItemPressed: (index) { + // Do anything you want to do, such as: + if (index == topIndex) { + if (displayMode == PaneDisplayMode.open) { + setState(() => this.displayMode = PaneDisplayMode.compact); + } else if (displayMode == PaneDisplayMode.compact) { + setState(() => this.displayMode = PaneDisplayMode.open); + } + } + }, onChanged: (index) => setState(() => topIndex = index), displayMode: displayMode, indicator: indicators[indicator], diff --git a/lib/src/controls/navigation/navigation_view/pane.dart b/lib/src/controls/navigation/navigation_view/pane.dart index 09ccfba3..8d26f48e 100644 --- a/lib/src/controls/navigation/navigation_view/pane.dart +++ b/lib/src/controls/navigation/navigation_view/pane.dart @@ -78,6 +78,7 @@ class NavigationPane with Diagnosticable { this.key, this.selected, this.onChanged, + this.onItemPressed, this.size, this.header, this.items = const [], @@ -183,6 +184,9 @@ class NavigationPane with Diagnosticable { /// Called when the current index changes. final ValueChanged? onChanged; + /// Called when the item is clicked. + final ValueChanged? onItemPressed; + /// The scroll controller used by the pane when [displayMode] is /// [PaneDisplayMode.compact] and [PaneDisplayMode.open]. /// @@ -223,6 +227,8 @@ class NavigationPane with Diagnosticable { )) ..add(IntProperty('selected', selected, ifNull: 'none')) ..add(ObjectFlagProperty('onChanged', onChanged, ifNull: 'disabled')) + ..add(ObjectFlagProperty('onItemPressed', onItemPressed, + ifNull: 'disabled')) ..add(DiagnosticsProperty( 'scrollController', scrollController)) ..add(DiagnosticsProperty('size', size)) @@ -232,6 +238,7 @@ class NavigationPane with Diagnosticable { /// Changes the selected item to [item]. void changeTo(NavigationPaneItem item) { final index = effectiveIndexOf(item); + if (!index.isNegative) onItemPressed?.call(index); if (selected != index && !index.isNegative) onChanged?.call(index); } @@ -333,6 +340,7 @@ class NavigationPane with Diagnosticable { other.autoSuggestBoxReplacement == autoSuggestBoxReplacement && other.selected == selected && other.onChanged == onChanged && + other.onItemPressed == onItemPressed && other.scrollController == scrollController && other.indicator == indicator; } @@ -351,6 +359,7 @@ class NavigationPane with Diagnosticable { autoSuggestBoxReplacement.hashCode ^ selected.hashCode ^ onChanged.hashCode ^ + onItemPressed.hashCode ^ scrollController.hashCode ^ indicator.hashCode; } From d6234ec1ee14d89f12c8fd61722aa150561487cc Mon Sep 17 00:00:00 2001 From: Bruno D'Luka <45696119+bdlukaa@users.noreply.github.com> Date: Fri, 31 May 2024 14:21:25 -0300 Subject: [PATCH 2/2] chore: Improve documentation --- CHANGELOG.md | 2 +- lib/src/controls/navigation/navigation_view/pane.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04a77144..696d802e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## NEXT * fix: Scroll issue in `DatePicker`. ([#1054](https://github.com/bdlukaa/fluent_ui/issues/1054)) * feat: Add `NumberBox.textInputAction` and `NumberBox.onEditingComplete` ([#1063](https://github.com/bdlukaa/fluent_ui/pull/1063)) -* feat: Added `NavigationView.onItemPressed` callback, called when the item is on tap. +* feat: Added `NavigationView.onItemPressed` callback, called when the item is on tap ([#1067](https://github.com/bdlukaa/fluent_ui/pull/1067)) ## 4.8.7 diff --git a/lib/src/controls/navigation/navigation_view/pane.dart b/lib/src/controls/navigation/navigation_view/pane.dart index 8d26f48e..7cb53fa8 100644 --- a/lib/src/controls/navigation/navigation_view/pane.dart +++ b/lib/src/controls/navigation/navigation_view/pane.dart @@ -184,7 +184,7 @@ class NavigationPane with Diagnosticable { /// Called when the current index changes. final ValueChanged? onChanged; - /// Called when the item is clicked. + /// Called when an item is pressed. final ValueChanged? onItemPressed; /// The scroll controller used by the pane when [displayMode] is