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
Refactor ComposeScene
#908
Conversation
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/ComposeSceneAccessible.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/ComposeBridge.desktop.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/ComposeBridge.desktop.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/ComposeBridge.desktop.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/ComposeBridge.desktop.kt
Show resolved
Hide resolved
FocusDirection.Next -> { | ||
val toFocus = component.focusCycleRootAncestor?.let { root -> | ||
val policy = root.focusTraversalPolicy | ||
policy.getComponentAfter(root, component) | ||
?: policy.getDefaultComponent(root) | ||
} | ||
val hasFocus = toFocus?.hasFocus() == true | ||
!hasFocus && toFocus?.requestFocusInWindow(FocusEvent.Cause.TRAVERSAL_FORWARD) == true | ||
} | ||
|
||
override val textInputService = PlatformInput(platformComponent) | ||
FocusDirection.Previous -> { | ||
val toFocus = component.focusCycleRootAncestor?.let { root -> | ||
val policy = root.focusTraversalPolicy | ||
policy.getComponentBefore(root, component) | ||
?: policy.getDefaultComponent(root) | ||
} | ||
val hasFocus = toFocus?.hasFocus() == true | ||
!hasFocus && toFocus?.requestFocusInWindow(FocusEvent.Cause.TRAVERSAL_BACKWARD) == true | ||
} |
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.
Was this copy/pasted from somewhere else? Can we simplify it? Maybe
override fun moveFocus(focusDirection: FocusDirection): Boolean {
val (componentGetter, cause) = when(focusDirection) {
FocusDirection.Next ->
FocusTraversalPolicy::getComponentAfter to FocusEvent.Cause.TRAVERSAL_FORWARD
FocusDirection.Previous ->
FocusTraversalPolicy::getComponentAfter to FocusEvent.Cause.TRAVERSAL_BACKWARD
else -> return false
}
val toFocus = component.focusCycleRootAncestor?.let { root ->
val policy = root.focusTraversalPolicy
componentGetter(policy, root, component)
?: policy.getDefaultComponent(root)
} ?: return false
return !toFocus.hasFocus() && toFocus.requestFocusInWindow(cause)
}
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.
Was this copy/pasted from somewhere else?
Yes, it's just moved from another line without change.
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/scene/ComposeScene.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/scene/ComposeScene.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/scene/SimpleComposeScene.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/scene/CombinedComposeScene.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/skikoTest/kotlin/androidx/compose/ui/node/DepthSortedSetTest.kt
Show resolved
Hide resolved
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/platform/PlatformRootForTest.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/scene/ComposeScene.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/ComposeScene.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/scene/ComposeScene.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/scene/ComposeScene.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/node/RootNodeOwner.kt
Outdated
Show resolved
Hide resolved
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.
Overall LGTM with the old/new naming approach. Great job 🎉.
## Proposed Changes - Fixes regression after #908 - Repeated call of `setContent` recreates recomposition that breaks the state. ## Testing ```kt fun main() = singleWindowApplication { var text by remember { mutableStateOf("") } Dialog( onDismissRequest = { }, ) { Box(modifier = Modifier.background(Color.White).size(400.dp, 300.dp)) { OutlinedTextField( value = text, onValueChange = { text = it }, modifier = Modifier.padding(32.dp) ) } } } ```
## Proposed Changes It's the evolution of #891 Compose scene: - Deprecate the existing API and introduce an internal interface instead - Remove key listeners from `setContent` - `constraints` -> `size` - Add `lastKnownPointerPosition` to public interface - `CombinedComposeScene` as a compatible version of scene - Remove recently added `semanticsOwner` - `ComposeScene.Pointer` -> `ComposeScenePointer` Other changes: - Rename `SkiaBasedOwner` to `RootNodeOwner`. Also, it uses aggregation instead of implementing a few interfaces. - `SkikoComposeUiTest` overrides `PlatformContext.RootForTestListener` now. It solves TODOs about `WindowInfo` in tests. - `SkiaRootForTest` is renamed to `PlatformRootForTest` - `onRootCreatedCallback`/`onRootDisposedCallback` is now part of `PlatformContext` - `PlatformRootForTest` exposes real `visibleBounds` instead of just window size information. - `PlatformRootForTest` exposes send pointer input methods instead of `scene` reference. - `InternalComposeUiApi` is opted in inside the same module. - `Platform` -> `PlatfromContext` - `dialogScrimBlendMode` -> `isWindowTransparent` - `AccessibilityController`: Remove interface from `skikoMain` source set - `AccessibilityController`: `syncLoop` triggered right from desktop-only part - Replaced `Platform.accessibilityController(SemanticsOwner)` to `semanticsOwnerListener` - Fixes an invalid test case: out of screen Popup cannot receive input now - Removed unnecessary expect/actual `createSkiaLayer` - Moves "Deprecated" `DefaultViewConfiguration` to test where there is a single usage of it. ## API Changes See `compose/ui/ui/api/desktop/ui.api` file ## Testing Test: run existing tests.
## Proposed Changes - Fixes regression after #908 - Repeated call of `setContent` recreates recomposition that breaks the state. ## Testing ```kt fun main() = singleWindowApplication { var text by remember { mutableStateOf("") } Dialog( onDismissRequest = { }, ) { Box(modifier = Modifier.background(Color.White).size(400.dp, 300.dp)) { OutlinedTextField( value = text, onValueChange = { text = it }, modifier = Modifier.padding(32.dp) ) } } } ```
Proposed Changes
It's the evolution of #891
Compose scene:
setContent
constraints
->size
lastKnownPointerPosition
to public interfaceCombinedComposeScene
as a compatible version of scenesemanticsOwner
ComposeScene.Pointer
->ComposeScenePointer
Other changes:
SkiaBasedOwner
toRootNodeOwner
. Also, it uses aggregation instead of implementing a few interfaces.SkikoComposeUiTest
overridesPlatformContext.RootForTestListener
now. It solves TODOs aboutWindowInfo
in tests.SkiaRootForTest
is renamed toPlatformRootForTest
onRootCreatedCallback
/onRootDisposedCallback
is now part ofPlatformContext
PlatformRootForTest
exposes realvisibleBounds
instead of just window size information.PlatformRootForTest
exposes send pointer input methods instead ofscene
reference.InternalComposeUiApi
is opted in inside the same module.Platform
->PlatfromContext
dialogScrimBlendMode
->isWindowTransparent
AccessibilityController
: Remove interface fromskikoMain
source setAccessibilityController
:syncLoop
triggered right from desktop-only partPlatform.accessibilityController(SemanticsOwner)
tosemanticsOwnerListener
createSkiaLayer
DefaultViewConfiguration
to test where there is a single usage of it.API Changes
See
compose/ui/ui/api/desktop/ui.api
fileTesting
Test: run existing tests.