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
20 changes: 17 additions & 3 deletions src/Core/src/Handlers/View/ViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ public static void MapIsEnabled(IViewHandler handler, IView view)
}
#endif

#if IOS || MACCATALYST
MapInputTransparentToContainer(handler, view);

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 new container-sync call only fires for handlers that use the base ViewHandler.MapIsEnabled. Several iOS handlers fully override MapIsEnabled and never call this (or the base method), so their WrapperView container is never re-synced when IsEnabled alone changes: SearchBarHandler.iOS.cs (MapIsEnabled only calls handler.PlatformView?.UpdateIsEnabled(...)), EditorHandler.iOS.cs (same pattern — and EditorHandler unconditionally needs a container pre-iOS 17, see its NeedsContainer override), and CarouselViewHandler(2).iOS.cs. Concrete repro for Editor (iOS < 17, wrapped): (1) toggle InputTransparent while IsEnabled is false — MapInputTransparentToContainer correctly sets the wrapper's UserInteractionEnabled = false; (2) later set IsEnabled = true — EditorHandler.MapIsEnabled fires but never re-invokes the container sync, so the wrapper stays stuck at UserInteractionEnabled = false forever, permanently blocking touches to the Editor even though it is now enabled and non-transparent. This reproduces the exact class of symptom from #36059 for a control this PR didn't update.

#endif
((PlatformView?)handler.PlatformView)?.UpdateIsEnabled(view);
}

Expand Down Expand Up @@ -529,6 +532,10 @@ public static void MapContainerView(IViewHandler handler, IView view)
else
handler.HasContainer = view.NeedsContainer();

#if IOS || MACCATALYST
MapInputTransparentToContainer(handler, view);
#endif

if (hasContainerOldValue != handler.HasContainer)
{
handler.UpdateValue(nameof(IView.Visibility));
Expand Down Expand Up @@ -610,15 +617,22 @@ public static void MapInputTransparent(IViewHandler handler, IView view)

#if IOS || MACCATALYST
// Containers on iOS/Mac Catalyst may be hit testable, so we need to
// propagate the the view's values to its container view.
if (handler.ContainerView is WrapperView wrapper)
wrapper.UpdateInputTransparent(handler, view);
// propagate the view's values to its container view.
MapInputTransparentToContainer(handler, view);
#endif

((PlatformView?)handler.PlatformView)?.UpdateInputTransparent(handler, view);
#endif
}

#if IOS || MACCATALYST
static void MapInputTransparentToContainer(IViewHandler handler, IView view)
{
if (handler.ContainerView is WrapperView wrapper)
wrapper.UpdateInputTransparent(handler, view);
}
#endif

/// <summary>
/// Maps the abstract <see cref="IView.Unfocus"/> method to the platform-specific implementations.
/// </summary>
Expand Down
6 changes: 4 additions & 2 deletions src/Core/src/Platform/iOS/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static void UpdateIsEnabled(this UIView platformView, IView view)
else
{
// Non-UIControl views (like UICollectionView) only get interaction disable
platformView.UserInteractionEnabled = view.IsEnabled;
platformView.UserInteractionEnabled = view.IsEnabled && !view.InputTransparent;

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 — This makes wrapper UserInteractionEnabled depend on IsEnabled, but ViewHandler.MapIsEnabled only remaps PlatformView, while MapInputTransparent remaps both the iOS WrapperView container and PlatformView. Concrete failing sequence: a wrapped view with InputTransparent=false is disabled, MapInputTransparent sets the wrapper non-interactive (IsEnabled && !InputTransparent); when the view is later re-enabled, MapIsEnabled updates only the platform view, leaving the wrapper stale and hit-testing still blocked. Please synchronize the iOS/MacCatalyst container whenever IsEnabled changes (and when a container is created), e.g. by centralizing wrapper interaction mapping and calling it from MapIsEnabled, MapInputTransparent, and MapContainerView.

}
}

Expand Down Expand Up @@ -626,7 +626,9 @@ public static void UpdateInputTransparent(this UIView platformView, IViewHandler
return;
}

platformView.UserInteractionEnabled = !view.InputTransparent;
platformView.UserInteractionEnabled = platformView is UIControl

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] Logic and Correctness / iOS-MacCatalyst Platform Specifics — This new ternary correctly folds IsEnabled into the container's hit-test state, but the ITextInput-non-IEditor early-return a few lines above (used for Entry/SearchBar) still computes UserInteractionEnabled purely from IsReadOnly/InputTransparent and ignores IsEnabled entirely. Since MapIsEnabled/MapContainerView now route through MapInputTransparentToContainer -> wrapper.UpdateInputTransparent(handler, view) for every view type, a clipped/shadowed Entry with IsEnabled=false, InputTransparent=false, IsReadOnly=false will have its WrapperView left UserInteractionEnabled=true, inconsistent with the intent of this fix (the container computation should also be view.IsEnabled && !view.InputTransparent for these types, not just for the generic branch).

? !view.InputTransparent
: view.IsEnabled && !view.InputTransparent;
}

public static void UpdateInputTransparent(this UIView platformView, bool isReadOnly, bool inputTransparent)
Expand Down
79 changes: 77 additions & 2 deletions src/Core/tests/DeviceTests/Handlers/View/ViewHandlerTests.iOS.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,84 @@
using Microsoft.Maui.Handlers;
using UIKit;
using System.Threading.Tasks;
using Microsoft.Maui.DeviceTests.Stubs;
using Microsoft.Maui.Handlers;
using Xunit;

namespace Microsoft.Maui.DeviceTests
{
public partial class ViewHandlerTests
{
[Fact]
public async Task NonUIControlDisablesUserInteractionWhenIsEnabledFalse()
{
var view = new StubBase();
var handler = await CreateHandlerAsync(view);

await InvokeOnMainThreadAsync(() =>
{
Assert.True(handler.PlatformView.UserInteractionEnabled);

view.IsEnabled = false;
handler.UpdateValue(nameof(IView.IsEnabled));

Assert.False(handler.PlatformView.UserInteractionEnabled);

view.IsEnabled = true;
handler.UpdateValue(nameof(IView.IsEnabled));

Assert.True(handler.PlatformView.UserInteractionEnabled);
});
}

[Fact]
public async Task NonUIControlKeepsInputTransparentAfterIsEnabledToggles()
{
var view = new StubBase { InputTransparent = true };
var handler = await CreateHandlerAsync(view);

await InvokeOnMainThreadAsync(() =>
{
Assert.False(handler.PlatformView.UserInteractionEnabled);

view.IsEnabled = false;
handler.UpdateValue(nameof(IView.IsEnabled));

Assert.False(handler.PlatformView.UserInteractionEnabled);

view.IsEnabled = true;
handler.UpdateValue(nameof(IView.IsEnabled));

Assert.False(handler.PlatformView.UserInteractionEnabled);
});
}

[Theory]
[InlineData(false, true)]
[InlineData(true, false)]
public async Task ContainerUserInteractionTracksIsEnabledAndInputTransparent(bool inputTransparent, bool expectedWhenEnabled)

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] Regression Prevention and Test Coverage — All three new tests use StubBase, which goes through the base ViewHandler.MapIsEnabled/generic non-ITextInput path only. There is no regression test for an ITextInput view (Entry/SearchBar) wrapped in a WrapperView, nor for a handler that overrides MapIsEnabled on iOS (SearchBarHandler, EditorHandler, CarouselViewHandler/CarouselViewHandler2). These are exactly the paths where the container-sync gaps described above live, so this fix for #36059 ships without coverage proving those controls behave correctly after IsEnabled toggles.

{
var view = new StubBase
{
Clip = new PathShapeStub(),
InputTransparent = inputTransparent
};
var handler = await CreateHandlerAsync(view);

await InvokeOnMainThreadAsync(() =>
{
var containerView = Assert.IsType<WrapperView>(handler.ContainerView);

Assert.Equal(expectedWhenEnabled, containerView.UserInteractionEnabled);

view.IsEnabled = false;
handler.UpdateValue(nameof(IView.IsEnabled));

Assert.False(containerView.UserInteractionEnabled);

view.IsEnabled = true;
handler.UpdateValue(nameof(IView.IsEnabled));

Assert.Equal(expectedWhenEnabled, containerView.UserInteractionEnabled);
});
}
}
}
Loading