Skip to content

Commit

Permalink
focus on search field when search is opened, and back on message inpu…
Browse files Browse the repository at this point in the history
…t field when search is closed
  • Loading branch information
zoff99 committed Apr 23, 2024
1 parent 7113ecf commit 7a5b892
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,9 @@ fun App()
}
ChatAppWithScaffold(focusRequester = focusRequester, contactList = contacts, ui_scale = ui_scale)
LaunchedEffect(contacts.selectedContactPubkey) {
// HINT: focus on the message input field
focusRequester.requestFocus()
Log.i(TAG, "FFFFFF1111111111111: focus on the message input field")
contactstore.messageresetFilter()
}
}
Expand Down Expand Up @@ -1251,7 +1253,9 @@ fun App()
}
GroupAppWithScaffold(focusRequester = groupfocusRequester, groupList = groups, ui_scale = ui_scale)
LaunchedEffect(groups.selectedGroupId) {
// HINT: focus on the group message input field
groupfocusRequester.requestFocus()
Log.i(TAG, "FFFFgg1111111111111: focus on the group message input field")
groupstore.groupmessageresetFilter()
}
}
Expand Down
34 changes: 32 additions & 2 deletions src/main/kotlin/com/zoffcc/applications/trifa2/ChatApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.filled.Videocam
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -46,6 +47,7 @@ import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.ExternalDragValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.onExternalDrag
Expand Down Expand Up @@ -129,11 +131,12 @@ fun ChatAppWithScaffold(focusRequester: FocusRequester, displayTextField: Boolea
Theme {
Column(modifier = Modifier.fillMaxWidth())
{
val focusRequester2 = remember { FocusRequester() }
if (contactList.messageFilterActive)
{
var message_filter_str by remember { mutableStateOf(contactList.messageFilterString) }
TextField(enabled = true, singleLine = true,
modifier = Modifier.fillMaxWidth(),
modifier = Modifier.fillMaxWidth().focusRequester(focusRequester2),
textStyle = TextStyle(fontSize = 16.sp),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color(ChatColorsConfig.LIGHT__TEXTFIELD_BGCOLOR)),
keyboardOptions = KeyboardOptions(
Expand All @@ -148,6 +151,19 @@ fun ChatAppWithScaffold(focusRequester: FocusRequester, displayTextField: Boolea
message_filter_str = it
contactstore.messagefilterString(message_filter_str)
})
LaunchedEffect(contactList.messageFilterActive) {
// HINT: focus on the search input field when search input field is opened
focusRequester2.requestFocus()
Log.i(TAG, "FFFFFF2222222222222: focus on the search input field when search input field is opened")
}
}
else
{
LaunchedEffect(contactList.messageFilterActive) {
// HINT: focus on the message input field, when search input field is closed
focusRequester.requestFocus()
Log.i(TAG, "FFFFFF3333333333333: focus on the message input field, when search input field is closed")
}
}
Scaffold(topBar = {
TopAppBar(
Expand Down Expand Up @@ -237,11 +253,12 @@ fun GroupAppWithScaffold(focusRequester: FocusRequester, displayTextField: Boole
Theme {
Column(modifier = Modifier.fillMaxWidth())
{
val focusRequester2 = remember { FocusRequester() }
if (groupList.groupmessageFilterActive)
{
var message_filter_str by remember { mutableStateOf(groupList.groupmessageFilterString) }
TextField(enabled = true, singleLine = true,
modifier = Modifier.fillMaxWidth(),
modifier = Modifier.fillMaxWidth().focusRequester(focusRequester2),
textStyle = TextStyle(fontSize = 16.sp),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color(ChatColorsConfig.LIGHT__TEXTFIELD_BGCOLOR)),
keyboardOptions = KeyboardOptions(
Expand All @@ -256,6 +273,19 @@ fun GroupAppWithScaffold(focusRequester: FocusRequester, displayTextField: Boole
message_filter_str = it
groupstore.groupmessagefilterString(message_filter_str)
})
LaunchedEffect(groupList.groupmessageFilterActive) {
// HINT: focus on the search input field when search input field is opened
focusRequester2.requestFocus()
Log.i(TAG, "FFFFgg2222222222222: focus on the search input field when search input field is opened")
}
}
else
{
LaunchedEffect(groupList.groupmessageFilterActive) {
// HINT: focus on the message input field, when search input field is closed
focusRequester.requestFocus()
Log.i(TAG, "FFFFgg3333333333333: focus on the group message input field, when search input field is closed")
}
}
Scaffold(topBar = {
TopAppBar(
Expand Down

0 comments on commit 7a5b892

Please sign in to comment.