-
Notifications
You must be signed in to change notification settings - Fork 80
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
Revamp interop API to align it with Android and make it reusable #1489
Conversation
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/SwingPanel.desktop.kt
Outdated
Show resolved
Hide resolved
.../ui/src/desktopMain/kotlin/androidx/compose/ui/viewinterop/SwingInteropViewHolder.desktop.kt
Show resolved
Hide resolved
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.unit.Density | ||
|
||
private val NoOp: Any.() -> Unit = {} |
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.
Why is it explicitly scoped to Any.
?
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.
Just copied this:
private val STUB_CALLBACK_WITH_RECEIVER: Any.() -> Unit = {}
Is there a better way?
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/viewinterop/InteropView.skiko.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/viewinterop/InteropView.skiko.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/viewinterop/InteropView.uikit.kt
Show resolved
Hide resolved
...se/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/viewinterop/UIKitInteropContainer.uikit.kt
Outdated
Show resolved
Hide resolved
...se/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/viewinterop/UIKitInteropContainer.uikit.kt
Outdated
Show resolved
Hide resolved
...i/ui/src/uikitMain/kotlin/androidx/compose/ui/viewinterop/UIKitInteropElementHolder.uikit.kt
Show resolved
Hide resolved
compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/InteractionUIView.uikit.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/viewinterop/InteropViewHolder.skiko.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/SwingPanel.desktop.kt
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/SwingPanel.desktop.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/SwingPanel.desktop.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/SwingPanel.desktop.kt
Outdated
Show resolved
Hide resolved
...i/ui/src/desktopMain/kotlin/androidx/compose/ui/viewinterop/SwingInteropContainer.desktop.kt
Show resolved
Hide resolved
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/viewinterop/InteropViewHolder.skiko.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/interop/UIKitView.uikit.kt
Show resolved
Hide resolved
compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/scene/ComposeSceneMediator.uikit.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/viewinterop/InteropView.uikit.kt
Show resolved
Hide resolved
compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/viewinterop/InteropView.uikit.kt
Outdated
Show resolved
Hide resolved
87a1a45
to
ff72fe1
Compare
0da8553
to
a06a6a1
Compare
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/scene/ComposeSceneMediator.desktop.kt
Outdated
Show resolved
Hide resolved
The scheduling code LGTM 👍 |
Waiting for CI then |
CI is green. |
...i/ui/src/desktopMain/kotlin/androidx/compose/ui/viewinterop/SwingInteropContainer.desktop.kt
Outdated
Show resolved
Hide resolved
|
||
body() | ||
} finally { | ||
synchronized(lock) { |
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.
mutex for bool seems as overkill. Can it be just atomic?
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.
No, access to both needsRequestRedrawOnUpdateScheduled
, scheduled
is the same critical section.
* Callback to be invoked when the layout of the interop view changes to notify the system | ||
* that something has changed. | ||
*/ | ||
fun onInteropViewLayoutChange(holder: InteropViewHolder) |
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.
Looking at a way how scheduleUpdate
is written on Desktop, having this separate method is questionable again. I doubt that this method is required even on Android. Do you know if implementation of scheduleUpdate
will be enough for Android?
Since it's no-op for all platforms, let's comment it out with TODO (please restore TODO about Owner and merge with it)
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.
Looking at a way how scheduleUpdate is written on Desktop, having this separate method is questionable again. I doubt that this method is required even on Android. Do you know if implementation of scheduleUpdate will be enough for Android?
Yes, I think so. If it's not enough, we will iterate on it.
Since it's no-op for all platforms, let's comment it out with TODO (please restore TODO about Owner and merge with it)
Done.
internal fun Modifier.interopViewSemantics(enabled: Boolean, interopViewHolder: InteropViewHolder) = | ||
if (enabled) { | ||
this.semantics { interopView = interopViewHolder.group as UIKitInteropViewGroup } | ||
internal fun Modifier.nativeAccessibility(isEnabled: Boolean, interopWrappingView: InteropWrappingView) = |
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.
TODO: align "platform" vs "native" naming
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.
Done
Refactor interop API on iOS and Desktop to make it aligned with `AndroidView` - Make an `InteropViewHolder` a type responsible for configuring and emitting a `LayoutNode` associated with interop view. - Introduce a `TypedInteropViewHolder` that allows type-bound user-provided callbacks to run and be correctly updated in the scope of `InteropViewHolder`. - Introduce an `InteropView` composable function as an entry point for all interop implementations. - Merge `SwingInteropViewHolder` and `SwingInteropViewHolder2` and wire them with `TypedInteropViewHolder`. - Delete `InteropViewUpdater` and use interop container resident `SnapshotObserver` to track updates read by `InteropViewHolder`. - Change Swing update scheduling mechanics to batch them and then synchronously execute along with rendering sequence. - Rewire iOS implementation to use of `InteropView` with `UIKitInteropViewControllerHolder`, `UIKitInteropViewHolder`, and `UIKitInteropElementHolder` containing common parts of former two. - Tie `UIViewController` containment calls with `place`/`unplace`. ## Release notes ### iOS - Breaking changes - Actual of expected `InteropView` on iOS is `UIResponder` now instead of `UIView`. It's the first common ancestor for `UIViewController` and `UIView`, both of which can be integrated using iOS interop APIs. --------- Co-authored-by: Ivan Matkov <ivan.matkov@jetbrains.com>
Refactor interop API on iOS and Desktop to make it aligned with
AndroidView
InteropViewHolder
a type responsible for configuring and emitting aLayoutNode
associated with interop view.TypedInteropViewHolder
that allows type-bound user-provided callbacks to run and be correctly updated in the scope ofInteropViewHolder
.InteropView
composable function as an entry point for all interop implementations.SwingInteropViewHolder
andSwingInteropViewHolder2
and wire them withTypedInteropViewHolder
.InteropViewUpdater
and use interop container residentSnapshotObserver
to track updates read byInteropViewHolder
.InteropView
withUIKitInteropViewControllerHolder
,UIKitInteropViewHolder
, andUIKitInteropElementHolder
containing common parts of former two.UIViewController
containment calls withplace
/unplace
.Release notes
iOS - Breaking changes
InteropView
on iOS isUIResponder
now instead ofUIView
. It's the first common ancestor forUIViewController
andUIView
, both of which can be integrated using iOS interop APIs.