Skip to content

Commit 0f88c22

Browse files
authored
Revert "Fix back gesture after modal popup appearance (#2004)" (#2037)
Revert due to https://youtrack.jetbrains.com/issue/CMP-8019/iOS-Back-handler.-Doesnt-work-in-landscape-mode ## Release Notes N/A
1 parent 8f64717 commit 0f88c22

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

Diff for: compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/backhandler/UIKitBackGestureDispatcher.kt

+11-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import platform.UIKit.UIRectEdgeLeft
4141
import platform.UIKit.UIRectEdgeRight
4242
import platform.UIKit.UIScreenEdgePanGestureRecognizer
4343
import platform.UIKit.UIView
44+
import platform.UIKit.UIWindow
4445
import platform.darwin.NSObject
4546

4647
private const val BACK_GESTURE_SCREEN_SIZE = 0.3
@@ -90,10 +91,17 @@ internal class UIKitBackGestureDispatcher(
9091
leftEdgePanGestureRecognizer.state in activeGestureStates ||
9192
rightEdgePanGestureRecognizer.state in activeGestureStates
9293

93-
fun attachToView(view: UIView?) {
94+
fun onDidMoveToWindow(window: UIWindow?, composeRootView: UIView) {
9495
if (enableBackGesture) {
95-
removeGestureListeners()
96-
if (view != null) {
96+
if (window == null) {
97+
removeGestureListeners()
98+
} else {
99+
var view: UIView = composeRootView
100+
while (view.superview != window) {
101+
view = requireNotNull(view.superview) {
102+
"Window is not null, but superview is null for ${view.debugDescription}"
103+
}
104+
}
97105
addGestureListeners(view)
98106
}
99107
}

Diff for: compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/scene/ComposeHostingViewController.uikit.kt

+1-7
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ internal class ComposeHostingViewController(
206206
}
207207

208208
private fun onDidMoveToWindow(window: UIWindow?) {
209-
if (mediator != null) {
210-
backGestureDispatcher.attachToView(window)
211-
}
209+
backGestureDispatcher.onDidMoveToWindow(window, rootView)
212210
val windowContainer = window ?: return
213211

214212
updateInterfaceOrientationState()
@@ -274,8 +272,6 @@ internal class ComposeHostingViewController(
274272
override fun viewControllerDidEnterWindowHierarchy() {
275273
super.viewControllerDidEnterWindowHierarchy()
276274

277-
backGestureDispatcher.attachToView(view.window)
278-
279275
val metalView = MetalView(
280276
retrieveInteropTransaction = {
281277
mediator?.retrieveInteropTransaction() ?: object : UIKitInteropTransaction {
@@ -326,8 +322,6 @@ internal class ComposeHostingViewController(
326322
override fun viewControllerDidLeaveWindowHierarchy() {
327323
super.viewControllerDidLeaveWindowHierarchy()
328324

329-
backGestureDispatcher.attachToView(null)
330-
331325
// Store the current state in the next SaveableStateRegistry instance. It is used to
332326
// provide the saved state to the next compose scene when the view controller re-enters
333327
// the window hierarchy.

Diff for: compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/scene/UIKitComposeSceneLayer.uikit.kt

+7-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import androidx.compose.ui.window.MetalView
4545
import kotlin.coroutines.CoroutineContext
4646
import kotlinx.cinterop.CValue
4747
import platform.CoreGraphics.CGPoint
48+
import platform.UIKit.UIWindow
4849

4950
internal class UIKitComposeSceneLayer(
5051
private val onClosed: (UIKitComposeSceneLayer) -> Unit,
@@ -71,6 +72,7 @@ internal class UIKitComposeSceneLayer(
7172
}
7273

7374
val view = UIKitComposeSceneLayerView(
75+
::onDidMoveToWindow,
7476
::isInsideInteractionBounds,
7577
isInterceptingOutsideEvents = { focusable }
7678
)
@@ -81,9 +83,7 @@ internal class UIKitComposeSceneLayer(
8183
enableBackGesture = enableBackGesture,
8284
density = view.density,
8385
getTopLeftOffsetInWindow = { boundsInWindow.topLeft }
84-
).also {
85-
it.attachToView(view)
86-
}
86+
)
8787

8888
private val mediator = ComposeSceneMediator(
8989
parentView = view,
@@ -136,6 +136,10 @@ internal class UIKitComposeSceneLayer(
136136

137137
private val scrimPaint = Paint()
138138

139+
private fun onDidMoveToWindow(window: UIWindow?) {
140+
backGestureDispatcher.onDidMoveToWindow(window, view)
141+
}
142+
139143
fun render(canvas: Canvas, nanoTime: Long) {
140144
if (scrimColor != null) {
141145
val rect = metalView.bounds.asDpRect().toRect(density)
@@ -161,7 +165,6 @@ internal class UIKitComposeSceneLayer(
161165
view.removeFromSuperview()
162166
view.dispose()
163167
interopContainerView.removeFromSuperview()
164-
backGestureDispatcher.attachToView(null)
165168
}
166169

167170
@Composable

Diff for: compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/scene/UIKitComposeSceneLayerView.kt

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import platform.UIKit.UIEvent
2727
import platform.UIKit.UIEventTypeTouches
2828
import platform.UIKit.UITouch
2929
import platform.UIKit.UIView
30+
import platform.UIKit.UIWindow
3031

3132
/**
3233
* A backing ComposeSceneLayer view for each Compose scene layer. Its task is to
@@ -38,6 +39,7 @@ import platform.UIKit.UIView
3839
* events that start outside the bounds of the layer content or should let them pass through.
3940
*/
4041
internal class UIKitComposeSceneLayerView(
42+
private var onDidMoveToWindow: (UIWindow?) -> Unit,
4143
private var isInsideInteractionBounds: (point: CValue<CGPoint>) -> Boolean,
4244
private var isInterceptingOutsideEvents: () -> Boolean
4345
): UIView(frame = CGRectZero.readValue()) {
@@ -119,10 +121,16 @@ internal class UIKitComposeSceneLayerView(
119121
}
120122

121123
fun dispose() {
124+
onDidMoveToWindow = {}
122125
isInsideInteractionBounds = { false }
123126
isInterceptingOutsideEvents = { false }
124127
onOutsidePointerEvent = {}
125128
}
129+
130+
override fun didMoveToWindow() {
131+
super.didMoveToWindow()
132+
onDidMoveToWindow(window)
133+
}
126134
}
127135

128136
/**

0 commit comments

Comments
 (0)