Skip to content

Commit 857a060

Browse files
authored
Fill in some focus TODOs (#2774)
1 parent 3646b6a commit 857a060

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

redwood-composeui/src/commonMain/kotlin/app/cash/redwood/composeui/RedwoodContent.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@ import androidx.compose.foundation.layout.Box
2020
import androidx.compose.runtime.Composable
2121
import androidx.compose.runtime.DisposableEffect
2222
import androidx.compose.runtime.LaunchedEffect
23+
import androidx.compose.runtime.State
2324
import androidx.compose.runtime.getValue
2425
import androidx.compose.runtime.mutableStateOf
2526
import androidx.compose.runtime.remember
2627
import androidx.compose.runtime.rememberCoroutineScope
28+
import androidx.compose.runtime.rememberUpdatedState
2729
import androidx.compose.runtime.saveable.LocalSaveableStateRegistry
2830
import androidx.compose.runtime.setValue
2931
import androidx.compose.ui.Modifier
3032
import androidx.compose.ui.layout.onSizeChanged
3133
import androidx.compose.ui.platform.LocalDensity
3234
import androidx.compose.ui.platform.LocalLayoutDirection
35+
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
36+
import androidx.compose.ui.platform.SoftwareKeyboardController
3337
import androidx.compose.ui.unit.LayoutDirection
3438
import app.cash.redwood.compose.RedwoodComposition
3539
import app.cash.redwood.ui.Density
@@ -74,6 +78,9 @@ public fun RedwoodContent(
7478
val onBackPressedDispatcher = platformOnBackPressedDispatcher()
7579
val saveableStateRegistry = LocalSaveableStateRegistry.current
7680

81+
val softwareKeyboardController = LocalSoftwareKeyboardController.current
82+
val softwareKeyboardControllerState = rememberUpdatedState(softwareKeyboardController)
83+
7784
// For simplicity, a new provider or content lambda gets an entirely new composition and children.
7885
val children = remember(widgetSystem, content) { ComposeWidgetChildren() }
7986
DisposableEffect(widgetSystem, content) {
@@ -82,7 +89,7 @@ public fun RedwoodContent(
8289
widgetSystem = widgetSystem,
8390
container = children,
8491
onBackPressedDispatcher = onBackPressedDispatcher,
85-
focusDirector = RedwoodContentFocusDirector(),
92+
focusDirector = RedwoodContentFocusDirector(softwareKeyboardControllerState),
8693
saveableStateRegistry = saveableStateRegistry,
8794
uiConfigurations = uiConfigurations,
8895
)
@@ -107,9 +114,11 @@ public fun RedwoodContent(
107114
@Composable
108115
internal expect fun platformOnBackPressedDispatcher(): OnBackPressedDispatcher
109116

110-
internal class RedwoodContentFocusDirector : FocusDirector {
117+
internal class RedwoodContentFocusDirector(
118+
private val softwareKeyboardController: State<SoftwareKeyboardController?>,
119+
) : FocusDirector {
111120
override fun hideSoftwareKeyboard() {
112-
// TODO: complete this.
121+
softwareKeyboardController.value?.hide()
113122
}
114123

115124
override fun newFocusRequester(): FocusRequester {

redwood-widget/src/jsMain/kotlin/app/cash/redwood/widget/RedwoodHTMLElementView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private class RedwoodHTMLElementView(
8787
}
8888

8989
override fun requestFocus(widget: Widget<HTMLElement>) {
90-
// TODO: complete this.
90+
widget.value.focus()
9191
}
9292

9393
private fun observePixelRatioChange() {

0 commit comments

Comments
 (0)