diff --git a/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/platform/PlatformTextField.android.kt b/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/platform/PlatformTextField.android.kt index ce4bada6e1..0b17a3aadf 100644 --- a/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/platform/PlatformTextField.android.kt +++ b/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/platform/PlatformTextField.android.kt @@ -36,11 +36,12 @@ import chat.simplex.common.model.ChatController.appPrefs import chat.simplex.common.model.ChatModel import chat.simplex.common.ui.theme.CurrentColors import chat.simplex.common.views.chat.* -import chat.simplex.common.views.helpers.SharedContent -import chat.simplex.common.views.helpers.generalGetString +import chat.simplex.common.views.helpers.* import chat.simplex.res.MR import dev.icerock.moko.resources.StringResource import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.filter import java.lang.reflect.Field import java.net.URI @@ -84,6 +85,13 @@ actual fun PlatformTextField( freeFocus = true } } + LaunchedEffect(Unit) { + snapshotFlow { ModalManager.start.modalCount.value } + .filter { it > 0 } + .collect { + freeFocus = true + } + } val isRtl = LocalLayoutDirection.current == LayoutDirection.Rtl AndroidView(modifier = Modifier, factory = { diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/SearchTextField.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/SearchTextField.kt index 896d929480..c6d5d6ad16 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/SearchTextField.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/SearchTextField.kt @@ -10,7 +10,6 @@ import androidx.compose.material.TextFieldDefaults.indicatorLine import androidx.compose.material.TextFieldDefaults.textFieldWithLabelPadding import androidx.compose.runtime.* import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester @@ -25,10 +24,12 @@ import androidx.compose.ui.text.input.* import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import chat.simplex.common.platform.* import chat.simplex.res.MR import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.filter +import kotlinx.coroutines.launch -@OptIn(ExperimentalComposeUiApi::class) @Composable fun SearchTextField( modifier: Modifier, @@ -50,6 +51,25 @@ fun SearchTextField( keyboard?.show() } } + if (appPlatform.isAndroid) { + LaunchedEffect(Unit) { + val modalCountOnOpen = ModalManager.start.modalCount.value + launch { + snapshotFlow { ModalManager.start.modalCount.value } + .filter { it > modalCountOnOpen } + .collect { + keyboard?.hide() + } + } + } + KeyChangeEffect(chatModel.chatId.value) { + if (chatModel.chatId.value != null) { + // Delay is needed here because when ChatView is being opened and keyboard is hiding, bottom sheet (to choose attachment) is visible on a screen + delay(300) + keyboard?.hide() + } + } + } DisposableEffect(Unit) { onDispose { diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/SettingsView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/SettingsView.kt index 68315aec2c..02716fa17e 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/SettingsView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/SettingsView.kt @@ -100,10 +100,14 @@ fun SettingsLayout( ) { val scope = rememberCoroutineScope() val closeSettings: () -> Unit = { scope.launch { drawerState.close() } } + val view = LocalMultiplatformView() if (drawerState.isOpen) { BackHandler { closeSettings() } + LaunchedEffect(Unit) { + hideKeyboard(view) + } } val theme = CurrentColors.collectAsState() val uriHandler = LocalUriHandler.current