Skip to content

Commit

Permalink
Merge pull request #28 from blackcandy-org/login-form-issue
Browse files Browse the repository at this point in the history
Enhance keyboard handling on login form
  • Loading branch information
aidewoode authored Apr 3, 2024
2 parents df856b2 + b80b493 commit 43af542
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Button
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -35,26 +39,47 @@ fun LoginAuthenticationForm(
),
modifier = modifier,
) {
val submitEnabled = email.isNotEmpty() && password.isNotEmpty()
val focusManager = LocalFocusManager.current

OutlinedTextField(
value = email,
label = { Text(text = stringResource(R.string.email)) },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Email),
keyboardOptions =
KeyboardOptions(
keyboardType = KeyboardType.Email,
imeAction = ImeAction.Next,
),
keyboardActions =
KeyboardActions(
onNext = { focusManager.moveFocus(FocusDirection.Down) },
),
onValueChange = onEmailChanged,
modifier = Modifier.fillMaxWidth(),
singleLine = true,
)

OutlinedTextField(
value = password,
label = { Text(text = stringResource(R.string.password)) },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
keyboardActions =
KeyboardActions(
onDone = {
if (submitEnabled) {
onLoginButtonClicked()
}
},
),
visualTransformation = PasswordVisualTransformation(),
onValueChange = onPasswordChanged,
modifier = Modifier.fillMaxWidth(),
singleLine = true,
)

Button(
modifier = Modifier.fillMaxWidth(),
enabled = email.isNotEmpty() && password.isNotEmpty(),
enabled = submitEnabled,
onClick = { onLoginButtonClicked() },
) {
Text(text = stringResource(R.string.login))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Button
import androidx.compose.material3.OutlinedTextField
Expand Down Expand Up @@ -48,7 +49,16 @@ fun LoginConnectionForm(
value = serverAddress,
label = { Text(text = stringResource(R.string.server_address)) },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Uri),
keyboardActions =
KeyboardActions(
onDone = {
if (serverAddress.isNotEmpty()) {
onConnectButtonClicked()
}
},
),
onValueChange = onServerAddressChanged,
singleLine = true,
modifier = Modifier.fillMaxWidth(),
)

Expand Down

0 comments on commit 43af542

Please sign in to comment.