Skip to content
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
103 changes: 103 additions & 0 deletions docs/design/ToolbarDrawerToggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Toolbar drawer toggle contract

`Microsoft.Maui.IToolbarDrawerToggleVisible.DrawerToggleVisible` tells a platform backend whether the
toolbar should render the drawer (flyout / "hamburger") affordance in its navigation slot.

## Why a separate interface

The member is **not** on `IToolbar`. `IToolbar` is a shipped public interface, and adding a member to it
would source-break every existing external implementer on `netstandard2.0`, where default interface
members are not supported and the member would therefore be abstract (`CS0535`).

`IToolbarDrawerToggleVisible` is an optional capability interface instead, so it is purely additive on
every target framework. This mirrors `ISwipeItemMenuItemIconColor`, which was added alongside
`ISwipeItemMenuItem` for the same reason.

Consume it by pattern matching:

```csharp
bool drawerToggleVisible = toolbar is IToolbarDrawerToggleVisible { DrawerToggleVisible: true };
```

A toolbar that does not implement the interface has no drawer toggle.

## Ownership

The value is **computed and owned by the cross-platform layer**, which is why the contract is read-only:

| Toolbar | How the value is computed |
| ------- | ------------------------- |
| `ShellToolbar` | `FlyoutBehavior == Flyout` and either the navigation stack has a single page or the back button is suppressed by a `BackButtonBehavior`. On Windows only `FlyoutBehavior == Flyout` is considered. |
| `NavigationPageToolbar` | The toolbar's parent is a `FlyoutPage`, `FlyoutPage.ShouldShowToolbarButton()` is `true`, and (outside Windows) no page has been pushed. |

Platform backends **render** this value; they must not compute or overwrite it.
`Microsoft.Maui.Controls.Toolbar` still exposes a settable `DrawerToggleVisible` property because it is
shipped public API, but the framework owns the value for the Shell and `NavigationPage` toolbars.

## Back button precedence — not mutual exclusion

`BackButtonVisible` and `DrawerToggleVisible` are **not** mutually exclusive. On Windows, `ShellToolbar`
sets the drawer toggle purely from `FlyoutBehavior`, so both values can be `true` at the same time.

What is guaranteed is **precedence**: the two share a single navigation slot, and the back button wins.
A backend should check the back button first and only fall through to the drawer toggle, exactly as the
built-in `ToolbarExtensions.UpdateBackButton` implementations do on Android and Tizen.

Ordering is also guaranteed: the drawer toggle backing value is updated *before* `BackButtonVisible`
notifies, and the `DrawerToggleVisible` notification is raised *after* it. So a backend rendering the
shared slot from either mapper always observes a settled pair rather than a half-applied transition.
For the same reason, code that forwards toolbar state between instances must assign `BackButtonVisible`
before `DrawerToggleVisible` (see `ShellToolbarTracker.ApplyToolbarChanges`).
Comment on lines +46 to +50

## Change notification

Changes raise a handler update keyed on `"DrawerToggleVisible"`, exactly like any other toolbar property:

```csharp
public class MyToolbarHandler : ElementHandler<IToolbar, MyPlatformToolbar>
{
public static readonly IPropertyMapper<IToolbar, MyToolbarHandler> Mapper =
new PropertyMapper<IToolbar, MyToolbarHandler>(ElementMapper)
{
[nameof(IToolbar.Title)] = MapTitle,
[nameof(IToolbar.BackButtonVisible)] = MapNavigationSlot,
[nameof(IToolbarDrawerToggleVisible.DrawerToggleVisible)] = MapNavigationSlot,
};

public MyToolbarHandler() : base(Mapper) { }

protected override MyPlatformToolbar CreatePlatformElement() => new();

static void MapTitle(MyToolbarHandler handler, IToolbar toolbar) =>
handler.PlatformView.Title = toolbar.Title;

static void MapNavigationSlot(MyToolbarHandler handler, IToolbar toolbar)
{
if (toolbar.BackButtonVisible) // back wins
handler.PlatformView.ShowBackButton();
else if (toolbar is IToolbarDrawerToggleVisible { DrawerToggleVisible: true })
handler.PlatformView.ShowDrawerToggle();
else
handler.PlatformView.ClearNavigationSlot();
}
}
```

Pointing both keys at one method is the recommended shape, since the two properties render into the same
slot.

Each window owns its own toolbar instance, so drawer toggle state and its notifications are tracked per
window with no additional work from the backend.

## Built-in platform consumption

| Platform | Consumes `DrawerToggleVisible`? | Where |
| -------- | ------------------------------- | ----- |
| Android | Yes | `Controls.Platform.ToolbarExtensions.UpdateBackButton` selects a `DrawerArrowDrawable` with `Progress = 0` when the back button is hidden and the drawer toggle is visible. Shell additionally drives an `ActionBarDrawerToggle` from `ShellToolbarTracker`. |
| Tizen | Yes | `Controls.Platform.ToolbarExtensions.UpdateBackButton` installs a menu button, and `UpdateTitleIcon` avoids clearing the icon while the drawer toggle is visible. |
| Windows | No | The flyout toggle is rendered by `NavigationView`, not by the toolbar. |
| iOS / MacCatalyst | No | The flyout toggle is owned by the flyout/navigation controller, not by the toolbar. |

The `DrawerToggleVisible` property mapping is therefore registered only for Android and Tizen. Because
that mapping and the `BackButtonVisible` mapping both call `UpdateBackButton`, a change that flips both
values runs it twice; this is intentional and idempotent.
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,7 @@ internal static void ApplyToolbarChanges(Toolbar shellToolbar, Toolbar destinati
destination.Title = shellToolbar.Title;
destination.TitleView = shellToolbar.TitleView;
destination.DynamicOverflowEnabled = shellToolbar.DynamicOverflowEnabled;
destination.DrawerToggleVisible = shellToolbar.DrawerToggleVisible;
destination.BackButtonVisible = shellToolbar.BackButtonVisible;
shellToolbar.ForwardNavigationIconStateTo(destination);
destination.BackButtonEnabled = shellToolbar.BackButtonEnabled;
destination.IsVisible = shellToolbar.IsVisible;
}
Expand Down
9 changes: 5 additions & 4 deletions src/Controls/src/Core/Handlers/Shell/Tizen/ShellView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void SetElement(Shell shell, IMauiContext context)
{
if (e.PropertyName == "BackButtonVisible")
{
UpdateDrawerToggleVisible();
RefreshNavigationSlot();
}
};

Expand All @@ -119,7 +119,7 @@ public void SetElement(Shell shell, IMauiContext context)
public void UpdateFlyoutBehavior(FlyoutBehavior flyoutBehavior)
{
_navigationDrawer.DrawerBehavior = flyoutBehavior.ToPlatform();
UpdateDrawerToggleVisible();
RefreshNavigationSlot();

if (_navigationDrawer.DrawerBehavior == TDrawerBehavior.Drawer)
_ = _navigationDrawer.CloseAsync(false);
Expand Down Expand Up @@ -441,9 +441,10 @@ void OnIconPressed(object? sender, EventArgs e)
IsOpened = true;
}

void UpdateDrawerToggleVisible()
// DrawerToggleVisible is computed and owned by ShellToolbar, which already accounts for
// FlyoutBehavior and the back button, so this only re-renders the navigation slot.
void RefreshNavigationSlot()
{
Element!.Toolbar.DrawerToggleVisible = ((Element!.Toolbar.DrawerToggleVisible) && (Element.FlyoutBehavior == FlyoutBehavior.Flyout));
_toolbar?.UpdateBackButton(Element!.Toolbar);
}

Expand Down
15 changes: 10 additions & 5 deletions src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ void UpdateBackButton()

// Set this before BackButtonVisible triggers an update to the handler
// This way all useful information is present
if (Parent is FlyoutPage flyout && flyout.ShouldShowToolbarButton()
var drawerToggleVisible = Parent is FlyoutPage flyout && flyout.ShouldShowToolbarButton()
#if !WINDOWS // TODO NET 10 : Move this logic to ShouldShowToolbarButton
&& !anyPagesPushed.Value
#endif
)
_drawerToggleVisible = true;
else
_drawerToggleVisible = false;
;

var drawerToggleVisibleChanged = _drawerToggleVisible != drawerToggleVisible;
_drawerToggleVisible = drawerToggleVisible;

// Once we have better logic inside core to handle backbutton visiblity this
// code should all go away.
Expand Down Expand Up @@ -219,6 +219,11 @@ void UpdateBackButton()

_userChanged = false;
}

// Notified last so that BackButtonVisible (which takes precedence in the navigation slot)
// is already up to date when platform backends react to the drawer toggle change.
if (drawerToggleVisibleChanged)
NotifyPropertyChanged(nameof(DrawerToggleVisible));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 AI-Generated Review (multi-model)

[moderate] Handler Mapper and Property Patterns / Regression Prevention — This notification re-introduces a handler-driven navigation-icon write on exactly the transition that the #if ANDROID branch a few lines above (_backButtonVisible = GetBackButtonVisible();, assigned deliberately without SetProperty so no handler update is pushed) was written to leave alone. On non-Windows, drawerToggleVisible is ... && !anyPagesPushed.Value, so it flips on the same first-push / last-pop where _backButtonVisible flips. With the new #if ANDROID || TIZEN mapping in Toolbar.Mapper.cs, NotifyPropertyChanged(nameof(DrawerToggleVisible)) now routes to MapDrawerToggleVisible → AToolbar.UpdateBackButton(toolbar), which reads the already-updated BackButtonVisible and hard-sets nativeToolbar.NavigationIcon plus DrawerArrowDrawable.Progress = 1 (or = 0). That is the platform icon write the Android branch avoids. If the suppression is no longer needed, the #if ANDROID special case should be removed in the same change; if it is still needed, this notification should be gated so it does not fire on the push/pop transition. Neither option is exercised by the added tests — no test drives a real ToolbarHandler on Android.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 AI-Generated Review (multi-model)

[major] Handler Mapper and Property Patterns / Regression Prevention — This notification re-introduces a handler-driven navigation-icon write on exactly the transition that the #if ANDROID branch a few lines above deliberately suppresses. In the !_userChanged path Android assigns _backButtonVisible = GetBackButtonVisible(); directly (no SetProperty, so no Handler.UpdateValue), because ToolbarHandler.Android wires the navigation icon through NavigationUI.SetupWithNavController(...)/AppBarConfiguration.SetOpenableLayout(_drawerLayout) and animates the hamburger↔arrow via the NavController destination change.

Concrete scenario (Android, FlyoutPage whose Detail is a NavigationPage, flyout behavior Flyout): pushing the second page makes anyPagesPushed true, so drawerToggleVisible goes true -> false, drawerToggleVisibleChanged is true, and this line fires Handler.UpdateValue("DrawerToggleVisible"). With the new #if ANDROID || TIZEN mapping in Toolbar.Mapper.cs that reaches Toolbar.MapDrawerToggleVisible -> AToolbar.UpdateBackButton(toolbar), which reads toolbar.BackButtonVisible (already updated to true by the untracked field assignment) and immediately sets iconDrawable.Progress = 1 on the shared DrawerArrowDrawable. That is the same write the Android branch was written to avoid, so the drawer→arrow morph is snapped to its end state instead of being animated by the navigation transition. The reverse pop-to-root case snaps Progress = 0.

Suggest scoping the new notification so Android keeps its animation-owned path — e.g. #if !ANDROID around the notification when the untracked _backButtonVisible assignment was taken, or route the drawer-only change through a mapper that does not touch DrawerArrowDrawable.Progress. Whatever is chosen, please add an Android device/UI regression test for FlyoutPage+NavigationPage push/pop, since no test in this PR covers it.

}

void ApplyChanges(NavigationPage navigationPage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public static void UpdateIsVisible(this MauiToolbar platformToolbar, Toolbar too
}

public static void UpdateTitleIcon(this MauiToolbar platformToolbar, Toolbar toolbar)
{
platformToolbar.UpdateTitleIcon(toolbar, toolbar.BeginNavigationIconUpdate());
}

static void UpdateTitleIcon(this MauiToolbar platformToolbar, Toolbar toolbar, int generation)
{
_ = toolbar?.Handler?.MauiContext ?? throw new ArgumentNullException(nameof(toolbar.Handler.MauiContext));

Expand All @@ -50,7 +55,7 @@ public static void UpdateTitleIcon(this MauiToolbar platformToolbar, Toolbar too

source.LoadImage(toolbar.Handler.MauiContext, (result) =>
{
if (result?.Value != null)
if (result?.Value != null && toolbar.IsCurrentTitleIconUpdate(generation, source))
{
var image = new TImage
{
Expand All @@ -63,21 +68,23 @@ public static void UpdateTitleIcon(this MauiToolbar platformToolbar, Toolbar too

public static void UpdateBackButton(this MauiToolbar platformToolbar, Toolbar toolbar)
{
if (toolbar.BackButtonVisible)
var generation = toolbar.BeginNavigationIconUpdate();

if (toolbar.NavigationIconKind == ToolbarNavigationIconKind.BackButton)
{
var backButton = CreateBackButton(platformToolbar, toolbar);
backButton.Clicked += (s, e) => platformToolbar.SendIconPressed();
platformToolbar.Icon = backButton;
}
else if (toolbar.DrawerToggleVisible)
else if (toolbar.NavigationIconKind == ToolbarNavigationIconKind.DrawerToggle)
{
var menuButton = CreateMenuButton(platformToolbar, toolbar);
menuButton.Clicked += (s, e) => platformToolbar.SendIconPressed();
platformToolbar.Icon = menuButton;
}
else if (toolbar.TitleIcon == null)
else
{
platformToolbar.Icon = null;
platformToolbar.UpdateTitleIcon(toolbar, generation);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 AI-Generated Review (multi-model)

[moderate] Logic and Correctness / Null Safety — The rewritten else branch changes the no-navigation-icon case from a handler-free assignment into a call that unconditionally dereferences the handler. Previously this branch was else if (toolbar.TitleIcon == null) { platformToolbar.Icon = null; } and never touched toolbar.Handler. UpdateTitleIcon(toolbar, generation) begins with _ = toolbar?.Handler?.MauiContext ?? throw new ArgumentNullException(...), so UpdateBackButton now throws whenever it runs before the toolbar handler/MauiContext is available. Concrete path: ShellView subscribes Element.Toolbar.PropertyChanged in its constructor and UpdateFlyoutBehavior calls RefreshNavigationSlot() → _toolbar?.UpdateBackButton(Element!.Toolbar); both can fire on a Shell whose Toolbar.Handler is not yet connected, where the old code simply cleared the icon.

Second effect on the same line: when TitleIcon is non-null the old code intentionally did nothing (the icon was already installed by UpdateTitleIcon). Now every UpdateBackButton invocation — including the newly-registered MapDrawerToggleVisible, MapBackButtonVisible, and each RefreshNavigationSlot() — restarts an async source.LoadImage(...) and allocates a fresh TImage that replaces platformToolbar.Icon without disposing the previous NUI view. A Tizen page with a TitleIcon therefore re-decodes its toolbar icon on every unrelated navigation-slot update.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 AI-Generated Review (multi-model)

[major] Null Safety / Logic and Correctness — The rewritten else branch turns a handler-free assignment into a call that unconditionally dereferences the handler. Previously this branch was else if (toolbar.TitleIcon == null) { platformToolbar.Icon = null; } and never touched toolbar.Handler. UpdateTitleIcon(toolbar, generation) starts with _ = toolbar?.Handler?.MauiContext ?? throw new ArgumentNullException(...), which now runs before the source == null || source.IsEmpty early-out, so UpdateBackButton throws whenever the toolbar has no connected handler/MauiContext.

Concrete scenario: ShellView.RefreshNavigationSlot() (this PR's rename) calls _toolbar?.UpdateBackButton(Element!.Toolbar) from UpdateFlyoutBehavior(...) and from the PropertyChanged listener. Element.Toolbar is the Shell-owned ShellToolbar, whose Handler/MauiContext is not guaranteed to be set at those points (early Shell setup, or after the toolbar handler is disconnected on teardown) — previously that path was safe because the no-icon case never read the handler. Suggest moving the MauiContext guard below the source == null || source.IsEmpty early-out, or guarding the else branch with a toolbar.Handler?.MauiContext is not null check and clearing platformToolbar.Icon otherwise.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,6 @@ virtual Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutTemplatedConte
~static readonly Microsoft.Maui.Controls.TabbedPage.BadgeColorProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.TabbedPage.BadgeTextColorProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.TabbedPage.BadgeTextProperty -> Microsoft.Maui.Controls.BindableProperty
static Microsoft.Maui.Controls.Toolbar.MapDrawerToggleVisible(Microsoft.Maui.Handlers.IToolbarHandler! arg1, Microsoft.Maui.Controls.Toolbar! arg2) -> void
static Microsoft.Maui.Controls.Toolbar.MapDrawerToggleVisible(Microsoft.Maui.Handlers.ToolbarHandler! arg1, Microsoft.Maui.Controls.Toolbar! arg2) -> void
static Microsoft.Maui.Controls.Shell.ResolveFlyoutItemTemplate(Microsoft.Maui.Controls.Shell? shell, Microsoft.Maui.Controls.BindableObject! flyoutItem) -> Microsoft.Maui.Controls.DataTemplate?
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,6 @@ Microsoft.Maui.Controls.Label.~Label() -> void
~static readonly Microsoft.Maui.Controls.TabbedPage.BadgeColorProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.TabbedPage.BadgeTextColorProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.TabbedPage.BadgeTextProperty -> Microsoft.Maui.Controls.BindableProperty
static Microsoft.Maui.Controls.Toolbar.MapDrawerToggleVisible(Microsoft.Maui.Handlers.IToolbarHandler! handler, Microsoft.Maui.Controls.Toolbar! toolbar) -> void
static Microsoft.Maui.Controls.Toolbar.MapDrawerToggleVisible(Microsoft.Maui.Handlers.ToolbarHandler! handler, Microsoft.Maui.Controls.Toolbar! toolbar) -> void
static Microsoft.Maui.Controls.Shell.ResolveFlyoutItemTemplate(Microsoft.Maui.Controls.Shell? shell, Microsoft.Maui.Controls.BindableObject! flyoutItem) -> Microsoft.Maui.Controls.DataTemplate?
12 changes: 10 additions & 2 deletions src/Controls/src/Core/ShellToolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,23 @@ internal void ApplyChanges()

var flyoutBehavior = (_shell as IFlyoutView).FlyoutBehavior;
#if WINDOWS
_drawerToggleVisible = flyoutBehavior is FlyoutBehavior.Flyout;
var drawerToggleVisible = flyoutBehavior is FlyoutBehavior.Flyout;
#else
_drawerToggleVisible = flyoutBehavior is FlyoutBehavior.Flyout && (stack.Count <= 1 || !backButtonVisible);
var drawerToggleVisible = flyoutBehavior is FlyoutBehavior.Flyout && (stack.Count <= 1 || !backButtonVisible);
#endif
var drawerToggleVisibleChanged = _drawerToggleVisible != drawerToggleVisible;
_drawerToggleVisible = drawerToggleVisible;

BackButtonVisible = backButtonVisible && stack.Count > 1;
BackButtonEnabled = _backButtonBehavior?.IsEnabled ?? true;
BackButtonAccessibilityLabel = _backButtonBehavior?.AccessibilityLabel;
ToolbarItems = _toolbarTracker.ToolbarItems;

// Notified after BackButtonVisible (which takes precedence in the navigation slot) so that
// platform backends observe a fully consistent toolbar state.
if (drawerToggleVisibleChanged)
NotifyPropertyChanged(nameof(DrawerToggleVisible));

UpdateTitle();

Func<bool> getDefaultNavBarIsVisible = () =>
Expand Down
8 changes: 8 additions & 0 deletions src/Controls/src/Core/Toolbar/Toolbar.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ public static void MapBackButtonVisible(ToolbarHandler arg1, Toolbar arg2) =>
public static void MapIsVisible(ToolbarHandler arg1, Toolbar arg2) =>
MapIsVisible((IToolbarHandler)arg1, arg2);

public static void MapDrawerToggleVisible(ToolbarHandler arg1, Toolbar arg2) =>
MapDrawerToggleVisible((IToolbarHandler)arg1, arg2);



public static void MapBarTextColor(IToolbarHandler arg1, Toolbar arg2)
Expand Down Expand Up @@ -258,6 +261,11 @@ public static void MapIsVisible(IToolbarHandler arg1, Toolbar arg2)
arg1.PlatformView.UpdateIsVisible(arg2);
}

public static void MapDrawerToggleVisible(IToolbarHandler arg1, Toolbar arg2)
{
arg1.PlatformView.UpdateBackButton(arg2);
}




Expand Down
7 changes: 7 additions & 0 deletions src/Controls/src/Core/Toolbar/Toolbar.Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ internal static void RemapForControls()
ToolbarHandler.Mapper.ReplaceMapping<Toolbar, IToolbarHandler>(nameof(Toolbar.BarBackground), MapBarBackground);
ToolbarHandler.Mapper.ReplaceMapping<Toolbar, IToolbarHandler>(nameof(Toolbar.BarTextColor), MapBarTextColor);
#endif
#if ANDROID || TIZEN
// Android and Tizen are the only built-in platforms that render the drawer affordance from the
// toolbar itself, in the same navigation slot as the back button, so a drawer toggle change has
// to re-evaluate that slot. Windows, iOS and MacCatalyst render the flyout toggle from the
// flyout/navigation view instead and never read this property.
ToolbarHandler.Mapper.ReplaceMapping<Toolbar, IToolbarHandler>(nameof(IToolbarDrawerToggleVisible.DrawerToggleVisible), MapDrawerToggleVisible);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 AI-Generated Review (multi-model)

[major] Regression Prevention and Test Coverage — This registration is the actual fix (before it, Handler?.UpdateValue("DrawerToggleVisible") was a no-op because no mapping existed), yet nothing in the PR exercises it. It is compiled only under #if ANDROID || TIZEN, while Controls.Core.UnitTests builds for net only, so MapDrawerToggleVisible and this ReplaceMapping call are never executed by any added test. Every new test attaches a hand-written ExternalToolbarBackendHandler with its own mapper, which proves that DrawerToggleVisible raises a handler update but not that the shipped Android/Tizen mapping exists, is keyed correctly, or produces the correct native icon. The reported symptom (flyout/hamburger affordance not appearing or not clearing in the toolbar's navigation slot) has no device or UI regression test, so the exact scenario from the issue is not covered and a future removal of this line would not fail any test.

Separately, ReplaceMapping (rather than AppendToMapping/ModifyMapping) silently discards any DrawerToggleVisible mapping a consumer registered before Toolbar.RemapForControls() runs.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 AI-Generated Review (multi-model)

[major] Regression Prevention and Test Coverage — This registration is the actual behavioral fix: before it, Handler?.UpdateValue("DrawerToggleVisible") was a no-op because ToolbarHandler.Mapper had no entry for that key (Core's mapper only defines Title). Nothing in the PR exercises it. The line is compiled only under #if ANDROID || TIZEN, while Controls.Core.UnitTests builds net only, so neither MapDrawerToggleVisible nor the registration is reachable from ToolbarDrawerToggleTests. The added tests assert NotifyPropertyChanged fires and that a stub ElementHandler.UpdateValue records the key, which passes with or without this registration.

Also note the semantics differ from the interface doc: because the mapping is Android/Tizen-only, a change does not raise a platform update on iOS/MacCatalyst/Windows. Consider a device test under Controls.DeviceTests (Android) that asserts the platform AToolbar.NavigationIcon/DrawerArrowDrawable.Progress after a drawer-only transition — that is the only level at which this line is currently observable.

#endif
#if WINDOWS
ToolbarHandler.Mapper.ReplaceMapping<Toolbar, IToolbarHandler>(nameof(Toolbar.BackButtonEnabled), MapBackButtonEnabled);
ToolbarHandler.Mapper.ReplaceMapping<Toolbar, IToolbarHandler>(PlatformConfiguration.WindowsSpecific.Page.ToolbarPlacementProperty.PropertyName, MapToolbarPlacement);
Expand Down
8 changes: 8 additions & 0 deletions src/Controls/src/Core/Toolbar/Toolbar.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public static void MapBackButtonVisible(ToolbarHandler handler, Toolbar toolbar)
public static void MapIsVisible(ToolbarHandler handler, Toolbar toolbar) =>
MapIsVisible((IToolbarHandler)handler, toolbar);

public static void MapDrawerToggleVisible(ToolbarHandler handler, Toolbar toolbar) =>
MapDrawerToggleVisible((IToolbarHandler)handler, toolbar);

public static void MapBackButtonAccessibilityLabel(ToolbarHandler handler, Toolbar toolbar) =>
MapBackButtonAccessibilityLabel((IToolbarHandler)handler, toolbar);

Expand Down Expand Up @@ -94,6 +97,11 @@ public static void MapIsVisible(IToolbarHandler handler, Toolbar toolbar)
handler.PlatformView.UpdateIsVisible(toolbar);
}

public static void MapDrawerToggleVisible(IToolbarHandler handler, Toolbar toolbar)
{
handler.PlatformView.UpdateBackButton(toolbar);
}

public static void MapBarBackground(IToolbarHandler handler, Toolbar toolbar)
{
handler.PlatformView.UpdateBarBackgroundColor(toolbar);
Expand Down
Loading
Loading