From fad54ceea0d093132e40891e47ebff7ba2e6385f Mon Sep 17 00:00:00 2001 From: Artem Valieiev Date: Tue, 21 Nov 2023 19:59:18 +0100 Subject: [PATCH 1/4] Allow GesturePlatformManager to be created for views with null window property (Embedding case) --- .../Platform/GestureManager/GestureManager.cs | 14 ++++++--- .../Gestures/GestureManagerTests.cs | 31 ++++++++++++------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs b/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs index 5271d2273e04..e4a3323f026c 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs @@ -16,6 +16,7 @@ internal class GestureManager object? _containerView; object? _platformView; object? _handler; + object? _window; public bool IsConnected => GesturePlatformManager != null; public GesturePlatformManager? GesturePlatformManager { get; private set; } @@ -56,17 +57,19 @@ void SetupGestureManager() { var handler = _view.Handler; var window = _view.Window; - - if (handler == null || - window == null) + + if (handler == null || + // Window disconnected + (_window != null && window == null)) { DisconnectGestures(); return; } if (_containerView != handler.ContainerView || - _platformView != handler.PlatformView || - _handler != handler) + _platformView != handler.PlatformView || + _handler != handler || + _window != window) { DisconnectGestures(); } @@ -79,6 +82,7 @@ void SetupGestureManager() _handler = handler; _containerView = handler.ContainerView; _platformView = handler.PlatformView; + _window = window; } } } diff --git a/src/Controls/tests/Core.UnitTests/Gestures/GestureManagerTests.cs b/src/Controls/tests/Core.UnitTests/Gestures/GestureManagerTests.cs index 7aa28b31ddb2..b95095dc51cf 100644 --- a/src/Controls/tests/Core.UnitTests/Gestures/GestureManagerTests.cs +++ b/src/Controls/tests/Core.UnitTests/Gestures/GestureManagerTests.cs @@ -32,18 +32,6 @@ public void DoesntConnectWithOnlyWindowSet() Assert.True(gestureManager.IsConnected); } - [Fact] - public void DoesntConnectWithOnlyHandlerSet() - { - var handler = Substitute.For(); - var view = Substitute.For(); - - view.Handler.Returns(handler); - - GestureManager gestureManager = new GestureManager(view); - Assert.False(gestureManager.IsConnected); - } - [Fact] public void DisconnectsWhenWindowIsRemoved() { @@ -108,5 +96,24 @@ public void PlatformManagerChangesWhenContainerViewChanged() Assert.NotEqual(gestureManager.GesturePlatformManager, platformManagerForHandler1); } + + [Fact] + public void PlatformManagerChangesWhenWindowChanged() + { + var view = Substitute.For(); + var handler = Substitute.For(); + + handler.ContainerView.Returns(null); + view.Window.Returns(new Window()); + view.Handler.Returns(handler); + + GestureManager gestureManager = new GestureManager(view); + var platformManagerForHandler1 = gestureManager.GesturePlatformManager; + + view.Window.Returns(new Window()); + view.WindowChanged += Raise.Event(view, EventArgs.Empty); + + Assert.NotEqual(gestureManager.GesturePlatformManager, platformManagerForHandler1); + } } } From bce80d8f4a3d1d31f718deef4f830a9689c86c2a Mon Sep 17 00:00:00 2001 From: Artem Valieiev Date: Tue, 21 Nov 2023 21:10:50 +0100 Subject: [PATCH 2/4] Set _window field to null in DisconnectGestures() of GestureManager --- src/Controls/src/Core/Platform/GestureManager/GestureManager.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs b/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs index e4a3323f026c..c7192c264305 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs @@ -49,6 +49,7 @@ void DisconnectGestures() GesturePlatformManager?.Dispose(); GesturePlatformManager = null; _handler = null; + _window = null; _containerView = null; _platformView = null; } From ce3401a5dbb164915398257c52f2b30a286f5c26 Mon Sep 17 00:00:00 2001 From: Artem Valieiev Date: Fri, 8 Dec 2023 18:46:50 +0100 Subject: [PATCH 3/4] Replace _window reference with boolean _didHaveWindow --- .../Core/Platform/GestureManager/GestureManager.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs b/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs index c7192c264305..8085320807b6 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs @@ -16,7 +16,7 @@ internal class GestureManager object? _containerView; object? _platformView; object? _handler; - object? _window; + bool _didHaveWindow; public bool IsConnected => GesturePlatformManager != null; public GesturePlatformManager? GesturePlatformManager { get; private set; } @@ -49,7 +49,7 @@ void DisconnectGestures() GesturePlatformManager?.Dispose(); GesturePlatformManager = null; _handler = null; - _window = null; + _didHaveWindow = false; _containerView = null; _platformView = null; } @@ -57,11 +57,9 @@ void DisconnectGestures() void SetupGestureManager() { var handler = _view.Handler; - var window = _view.Window; if (handler == null || - // Window disconnected - (_window != null && window == null)) + (_didHaveWindow && _view.Window == null)) { DisconnectGestures(); return; @@ -69,8 +67,7 @@ void SetupGestureManager() if (_containerView != handler.ContainerView || _platformView != handler.PlatformView || - _handler != handler || - _window != window) + _handler != handler) { DisconnectGestures(); } @@ -83,7 +80,7 @@ void SetupGestureManager() _handler = handler; _containerView = handler.ContainerView; _platformView = handler.PlatformView; - _window = window; + _didHaveWindow = _view.Window != null; } } } From 18183793452a372dffb809332c77f2a0c151925f Mon Sep 17 00:00:00 2001 From: Artem Valieiev Date: Fri, 8 Dec 2023 18:49:18 +0100 Subject: [PATCH 4/4] Remove invalid unit test --- .../Platform/GestureManager/GestureManager.cs | 6 ++-- .../Gestures/GestureManagerTests.cs | 31 +++++++------------ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs b/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs index 8085320807b6..4bef131dd64c 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs @@ -65,9 +65,9 @@ void SetupGestureManager() return; } - if (_containerView != handler.ContainerView || - _platformView != handler.PlatformView || - _handler != handler) + if (_containerView != handler.ContainerView || + _platformView != handler.PlatformView || + _handler != handler) { DisconnectGestures(); } diff --git a/src/Controls/tests/Core.UnitTests/Gestures/GestureManagerTests.cs b/src/Controls/tests/Core.UnitTests/Gestures/GestureManagerTests.cs index b95095dc51cf..094278a2e64a 100644 --- a/src/Controls/tests/Core.UnitTests/Gestures/GestureManagerTests.cs +++ b/src/Controls/tests/Core.UnitTests/Gestures/GestureManagerTests.cs @@ -32,6 +32,18 @@ public void DoesntConnectWithOnlyWindowSet() Assert.True(gestureManager.IsConnected); } + [Fact] + public void ConnectsWithOnlyHandlerSet() + { + var handler = Substitute.For(); + var view = Substitute.For(); + + view.Handler.Returns(handler); + + GestureManager gestureManager = new GestureManager(view); + Assert.True(gestureManager.IsConnected); + } + [Fact] public void DisconnectsWhenWindowIsRemoved() { @@ -96,24 +108,5 @@ public void PlatformManagerChangesWhenContainerViewChanged() Assert.NotEqual(gestureManager.GesturePlatformManager, platformManagerForHandler1); } - - [Fact] - public void PlatformManagerChangesWhenWindowChanged() - { - var view = Substitute.For(); - var handler = Substitute.For(); - - handler.ContainerView.Returns(null); - view.Window.Returns(new Window()); - view.Handler.Returns(handler); - - GestureManager gestureManager = new GestureManager(view); - var platformManagerForHandler1 = gestureManager.GesturePlatformManager; - - view.Window.Returns(new Window()); - view.WindowChanged += Raise.Event(view, EventArgs.Empty); - - Assert.NotEqual(gestureManager.GesturePlatformManager, platformManagerForHandler1); - } } }