feat: Implement instant keyboard hiding functionality in SearchScreen and ChatDetailScreen

This commit is contained in:
k1ngsterr1
2026-01-14 01:50:26 +05:00
parent 0f59db917e
commit 43ef9ac87f
2 changed files with 30 additions and 4 deletions

View File

@@ -299,9 +299,12 @@ fun ChatDetailScreen(
} }
} }
// 🔥 Закрытие экрана // 🔥 Закрытие экрана - мгновенно прячем клавиатуру через InputMethodManager
val hideKeyboardAndBack: () -> Unit = { val hideKeyboardAndBack: () -> Unit = {
keyboardController?.hide() // Используем нативный InputMethodManager для МГНОВЕННОГО закрытия
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(view.windowToken, 0)
focusManager.clearFocus()
onBack() onBack()
} }

View File

@@ -18,6 +18,11 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalView
import android.content.Context
import android.view.inputmethod.InputMethodManager
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@@ -45,6 +50,18 @@ fun SearchScreen(
onBackClick: () -> Unit, onBackClick: () -> Unit,
onUserSelect: (SearchUser) -> Unit onUserSelect: (SearchUser) -> Unit
) { ) {
// Context и View для мгновенного закрытия клавиатуры
val context = LocalContext.current
val view = LocalView.current
val focusManager = LocalFocusManager.current
// 🔥 Функция мгновенного закрытия клавиатуры
val hideKeyboardInstantly: () -> Unit = {
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(view.windowToken, 0)
focusManager.clearFocus()
}
// Цвета ТОЧНО как в ChatsListScreen // Цвета ТОЧНО как в ChatsListScreen
val backgroundColor = if (isDarkTheme) Color(0xFF1A1A1A) else Color(0xFFFFFFFF) val backgroundColor = if (isDarkTheme) Color(0xFF1A1A1A) else Color(0xFFFFFFFF)
val textColor = if (isDarkTheme) Color.White else Color(0xFF1a1a1a) val textColor = if (isDarkTheme) Color.White else Color(0xFF1a1a1a)
@@ -101,8 +118,11 @@ fun SearchScreen(
.padding(horizontal = 4.dp), .padding(horizontal = 4.dp),
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
// Кнопка назад // Кнопка назад - с мгновенным закрытием клавиатуры
IconButton(onClick = onBackClick) { IconButton(onClick = {
hideKeyboardInstantly()
onBackClick()
}) {
Icon( Icon(
Icons.Default.ArrowBack, Icons.Default.ArrowBack,
contentDescription = "Back", contentDescription = "Back",
@@ -221,6 +241,7 @@ fun SearchScreen(
textColor = textColor, textColor = textColor,
secondaryTextColor = secondaryTextColor, secondaryTextColor = secondaryTextColor,
onClick = { onClick = {
hideKeyboardInstantly()
RecentSearchesManager.addUser(user) RecentSearchesManager.addUser(user)
onUserSelect(user) onUserSelect(user)
}, },
@@ -239,6 +260,8 @@ fun SearchScreen(
isDarkTheme = isDarkTheme, isDarkTheme = isDarkTheme,
preloadedComposition = searchLottieComposition, preloadedComposition = searchLottieComposition,
onUserClick = { user -> onUserClick = { user ->
// Мгновенно закрываем клавиатуру
hideKeyboardInstantly()
// Сохраняем пользователя в историю // Сохраняем пользователя в историю
RecentSearchesManager.addUser(user) RecentSearchesManager.addUser(user)
onUserSelect(user) onUserSelect(user)