Repository navigation
[iOS] Respect InputTransparent when updating UserInteractionEnabled #36305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
[major] Handler Mapper and Property Patterns — This makes wrapper |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -626,7 +626,9 @@ public static void UpdateInputTransparent(this UIView platformView, IViewHandler | |
| return; | ||
| } | ||
|
|
||
| platformView.UserInteractionEnabled = !view.InputTransparent; | ||
| platformView.UserInteractionEnabled = platformView is UIControl | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
[major] Logic and Correctness / iOS-MacCatalyst Platform Specifics — This new ternary correctly folds |
||
| ? !view.InputTransparent | ||
| : view.IsEnabled && !view.InputTransparent; | ||
| } | ||
|
|
||
| public static void UpdateInputTransparent(this UIView platformView, bool isReadOnly, bool inputTransparent) | ||
|
|
||
| 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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
[moderate] Regression Prevention and Test Coverage — All three new tests use |
||
| { | ||
| 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); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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 overrideMapIsEnabledand never call this (or the base method), so theirWrapperViewcontainer is never re-synced whenIsEnabledalone changes:SearchBarHandler.iOS.cs(MapIsEnabledonly callshandler.PlatformView?.UpdateIsEnabled(...)),EditorHandler.iOS.cs(same pattern — andEditorHandlerunconditionally needs a container pre-iOS 17, see itsNeedsContaineroverride), andCarouselViewHandler(2).iOS.cs. Concrete repro forEditor(iOS < 17, wrapped): (1) toggleInputTransparentwhileIsEnabledis false —MapInputTransparentToContainercorrectly sets the wrapper'sUserInteractionEnabled = false; (2) later setIsEnabled = true—EditorHandler.MapIsEnabledfires but never re-invokes the container sync, so the wrapper stays stuck atUserInteractionEnabled = falseforever, 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.