1

我在撰写屏幕中有一个TextField和一个ModalDrawer。当用户打开抽屉时,我想关闭软键盘,但我无法弄清楚如何。在afaik中没有onOpened触发生命周期事件。ModalDrawer

4

1 回答 1

2

您可以使用 rememberDrawerState() 中的 confirmStateChange 参数,并在 drawerValue 变为 DrawerValue.open 时调用 keyboardController.hide() ,如下所示:

val keyboardController = LocalSoftwareKeyboardController.current
val state = rememberDrawerState(
  initialValue = DrawerValue.Closed,
    confirmStateChange = {
       if (it == DrawerValue.Open) {
           keyboardController?.hide()
       }
       true
    }
)

ModalDrawer(
   drawerState = state,
   ...
) {
  ...
}
于 2021-12-21T22:31:54.013 回答