Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jetchat - Add KeyboardActions Support for Message Dispatch #1318

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -54,6 +54,7 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
Expand Down Expand Up @@ -172,6 +173,13 @@ fun UserInput(
}
textFieldFocusState = focused
},
onMessageSent = {
onMessageSent(textState.text)
// Reset text field and close keyboard
textState = TextFieldValue()
// Move scroll to bottom
resetScroll()
},
focusState = textFieldFocusState
)
UserInputSelector(
Expand Down Expand Up @@ -402,6 +410,7 @@ private fun UserInputText(
textFieldValue: TextFieldValue,
keyboardShown: Boolean,
onTextFieldFocused: (Boolean) -> Unit,
onMessageSent: (String) -> Unit,
focusState: Boolean
) {
val swipeOffset = remember { mutableStateOf(0f) }
Expand Down Expand Up @@ -430,6 +439,7 @@ private fun UserInputText(
onTextFieldFocused,
keyboardType,
focusState,
onMessageSent,
Modifier.semantics {
contentDescription = a11ylabel
keyboardShownProperty = keyboardShown
Expand Down Expand Up @@ -466,6 +476,7 @@ private fun BoxScope.UserInputTextField(
onTextFieldFocused: (Boolean) -> Unit,
keyboardType: KeyboardType,
focusState: Boolean,
onMessageSent: (String) -> Unit,
modifier: Modifier = Modifier
) {
var lastFocusState by remember { mutableStateOf(false) }
Expand All @@ -485,6 +496,9 @@ private fun BoxScope.UserInputTextField(
keyboardType = keyboardType,
imeAction = ImeAction.Send
),
keyboardActions = KeyboardActions {
if (textFieldValue.text.isNotBlank()) onMessageSent(textFieldValue.text)
},
maxLines = 1,
cursorBrush = SolidColor(LocalContentColor.current),
textStyle = LocalTextStyle.current.copy(color = LocalContentColor.current)
Expand Down