@@ -20,16 +20,20 @@ import androidx.compose.foundation.layout.Box
20
20
import androidx.compose.runtime.Composable
21
21
import androidx.compose.runtime.DisposableEffect
22
22
import androidx.compose.runtime.LaunchedEffect
23
+ import androidx.compose.runtime.State
23
24
import androidx.compose.runtime.getValue
24
25
import androidx.compose.runtime.mutableStateOf
25
26
import androidx.compose.runtime.remember
26
27
import androidx.compose.runtime.rememberCoroutineScope
28
+ import androidx.compose.runtime.rememberUpdatedState
27
29
import androidx.compose.runtime.saveable.LocalSaveableStateRegistry
28
30
import androidx.compose.runtime.setValue
29
31
import androidx.compose.ui.Modifier
30
32
import androidx.compose.ui.layout.onSizeChanged
31
33
import androidx.compose.ui.platform.LocalDensity
32
34
import androidx.compose.ui.platform.LocalLayoutDirection
35
+ import androidx.compose.ui.platform.LocalSoftwareKeyboardController
36
+ import androidx.compose.ui.platform.SoftwareKeyboardController
33
37
import androidx.compose.ui.unit.LayoutDirection
34
38
import app.cash.redwood.compose.RedwoodComposition
35
39
import app.cash.redwood.ui.Density
@@ -74,6 +78,9 @@ public fun RedwoodContent(
74
78
val onBackPressedDispatcher = platformOnBackPressedDispatcher()
75
79
val saveableStateRegistry = LocalSaveableStateRegistry .current
76
80
81
+ val softwareKeyboardController = LocalSoftwareKeyboardController .current
82
+ val softwareKeyboardControllerState = rememberUpdatedState(softwareKeyboardController)
83
+
77
84
// For simplicity, a new provider or content lambda gets an entirely new composition and children.
78
85
val children = remember(widgetSystem, content) { ComposeWidgetChildren () }
79
86
DisposableEffect (widgetSystem, content) {
@@ -82,7 +89,7 @@ public fun RedwoodContent(
82
89
widgetSystem = widgetSystem,
83
90
container = children,
84
91
onBackPressedDispatcher = onBackPressedDispatcher,
85
- focusDirector = RedwoodContentFocusDirector (),
92
+ focusDirector = RedwoodContentFocusDirector (softwareKeyboardControllerState ),
86
93
saveableStateRegistry = saveableStateRegistry,
87
94
uiConfigurations = uiConfigurations,
88
95
)
@@ -107,9 +114,11 @@ public fun RedwoodContent(
107
114
@Composable
108
115
internal expect fun platformOnBackPressedDispatcher (): OnBackPressedDispatcher
109
116
110
- internal class RedwoodContentFocusDirector : FocusDirector {
117
+ internal class RedwoodContentFocusDirector (
118
+ private val softwareKeyboardController : State <SoftwareKeyboardController ?>,
119
+ ) : FocusDirector {
111
120
override fun hideSoftwareKeyboard () {
112
- // TODO: complete this.
121
+ softwareKeyboardController.value?.hide()
113
122
}
114
123
115
124
override fun newFocusRequester (): FocusRequester {
0 commit comments