diff --git a/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs b/src/Controls/src/Core/Platform/GestureManager/GestureManager.cs index 5271d2273e04..4bef131dd64c 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; + bool _didHaveWindow; public bool IsConnected => GesturePlatformManager != null; public GesturePlatformManager? GesturePlatformManager { get; private set; } @@ -48,6 +49,7 @@ void DisconnectGestures() GesturePlatformManager?.Dispose(); GesturePlatformManager = null; _handler = null; + _didHaveWindow = false; _containerView = null; _platformView = null; } @@ -55,17 +57,16 @@ void DisconnectGestures() void SetupGestureManager() { var handler = _view.Handler; - var window = _view.Window; - - if (handler == null || - window == null) + + if (handler == null || + (_didHaveWindow && _view.Window == null)) { DisconnectGestures(); return; } - if (_containerView != handler.ContainerView || - _platformView != handler.PlatformView || + if (_containerView != handler.ContainerView || + _platformView != handler.PlatformView || _handler != handler) { DisconnectGestures(); @@ -79,6 +80,7 @@ void SetupGestureManager() _handler = handler; _containerView = handler.ContainerView; _platformView = handler.PlatformView; + _didHaveWindow = _view.Window != null; } } } diff --git a/src/Controls/tests/Core.UnitTests/Gestures/GestureManagerTests.cs b/src/Controls/tests/Core.UnitTests/Gestures/GestureManagerTests.cs index 7aa28b31ddb2..094278a2e64a 100644 --- a/src/Controls/tests/Core.UnitTests/Gestures/GestureManagerTests.cs +++ b/src/Controls/tests/Core.UnitTests/Gestures/GestureManagerTests.cs @@ -33,7 +33,7 @@ public void DoesntConnectWithOnlyWindowSet() } [Fact] - public void DoesntConnectWithOnlyHandlerSet() + public void ConnectsWithOnlyHandlerSet() { var handler = Substitute.For(); var view = Substitute.For(); @@ -41,7 +41,7 @@ public void DoesntConnectWithOnlyHandlerSet() view.Handler.Returns(handler); GestureManager gestureManager = new GestureManager(view); - Assert.False(gestureManager.IsConnected); + Assert.True(gestureManager.IsConnected); } [Fact]