Skip to content

Commit

Permalink
Add markers
Browse files Browse the repository at this point in the history
  • Loading branch information
elijah-semyonov committed Apr 18, 2024
1 parent d48a7e4 commit e978ce9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.SideEffect
import platform.posix.free
import platform.posix.malloc

private var modalsOpen = 0

@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterialApi::class)
val ModalMemoryLeak = Screen.Example("ModalMemoryLeak") {
MaterialTheme {
Expand All @@ -56,13 +59,9 @@ val ModalMemoryLeak = Screen.Example("ModalMemoryLeak") {
},
sheetState = sheetState,
) {
DisposableEffect(Unit) {
val a = malloc((20_000 * 1024).toULong())

onDispose {
println("Disposed")
free(a)
}
SideEffect {
modalsOpen++
println("Modal opened: $modalsOpen")
}
Text("ModalBottomSheet3", Modifier.height(500.dp))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import androidx.compose.ui.window.UITouchesEventPhase
import kotlin.coroutines.CoroutineContext
import kotlin.math.roundToInt
import kotlinx.cinterop.CValue
import kotlinx.cinterop.ExportObjCClass
import kotlinx.cinterop.readValue
import kotlinx.cinterop.useContents
import org.jetbrains.skia.Canvas
Expand All @@ -98,6 +99,7 @@ import platform.UIKit.UITouchPhase
import platform.UIKit.UIView
import platform.UIKit.UIViewControllerTransitionCoordinatorProtocol
import platform.UIKit.UIWindow
import platform.darwin.NSObject

/**
* Layout of sceneView on the screen
Expand All @@ -109,6 +111,10 @@ internal sealed interface SceneLayout {
class Bounds(val renderBounds: IntRect, val interactionBounds: IntRect) : SceneLayout
}

@ExportObjCClass
class ComposeSceneMediatorMarker: NSObject() {

}
/**
* iOS specific-implementation of [PlatformContext.SemanticsOwnerListener] used to track changes in [SemanticsOwner].
*
Expand Down Expand Up @@ -215,6 +221,7 @@ internal class ComposeSceneMediator(
coroutineContext: CoroutineContext
) -> ComposeScene
) {
private val marker = ComposeSceneMediatorMarker()
private val keyboardOverlapHeightState: MutableState<Dp> = mutableStateOf(0.dp)
private var _layout: SceneLayout = SceneLayout.Undefined
private var constraints: List<NSLayoutConstraint> = emptyList()
Expand Down Expand Up @@ -499,6 +506,8 @@ internal class ComposeSceneMediator(
)

fun dispose() {
println("Disposed")

uiKitTextInputService.stopInput()
applicationStateListener.dispose()
focusStack?.popUntilNext(renderingView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import androidx.compose.ui.window.RenderingUIView
import kotlin.coroutines.CoroutineContext
import kotlin.math.max
import kotlinx.cinterop.CValue
import kotlinx.cinterop.ExportObjCClass
import kotlinx.cinterop.readValue
import kotlinx.cinterop.useContents
import org.jetbrains.skiko.SkikoRenderDelegate
Expand All @@ -54,6 +55,12 @@ import platform.UIKit.UIEvent
import platform.UIKit.UITouch
import platform.UIKit.UIView
import platform.UIKit.UIViewControllerTransitionCoordinatorProtocol
import platform.darwin.NSObject

@ExportObjCClass
class SceneLayerMarker: NSObject() {

}

internal class UIViewComposeSceneLayer(
private val composeContainer: ComposeContainer,
Expand All @@ -64,7 +71,7 @@ internal class UIViewComposeSceneLayer(
windowContext: PlatformWindowContext,
compositionContext: CompositionContext,
) : ComposeSceneLayer {

private val marker = SceneLayerMarker()
override var focusable: Boolean = focusStack != null
private var onOutsidePointerEvent: ((eventType: PointerEventType) -> Unit)? = null
private val rootView = composeContainer.view.window ?: composeContainer.view
Expand Down

0 comments on commit e978ce9

Please sign in to comment.