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

Improve login form #953

Merged
merged 11 commits into from
Jul 8, 2023
50 changes: 30 additions & 20 deletions app/src/main/java/com/jerboa/ui/components/login/Login.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ArrowBack
Expand All @@ -29,6 +31,7 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.PopupProperties
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.jerboa.DEFAULT_LEMMY_INSTANCES
Expand Down Expand Up @@ -130,7 +133,9 @@ fun LoginForm(
},
) {
OutlinedTextField(
modifier = Modifier.menuAnchor(),
modifier = Modifier
.menuAnchor()
.width(OutlinedTextFieldDefaults.MinWidth),
label = { Text(stringResource(R.string.login_instance)) },
placeholder = { Text(stringResource(R.string.login_instance_placeholder)) },
value = instance,
Expand All @@ -141,30 +146,33 @@ fun LoginForm(
},
keyboardOptions = KeyboardOptions(autoCorrect = false, keyboardType = KeyboardType.Uri),
)
ExposedDropdownMenu(
expanded = expanded,
onDismissRequest = {
expanded = false
},
) {
instanceOptions.forEach { selectionOption ->
DropdownMenuItem(
modifier = Modifier.exposedDropdownSize(),
text = {
Text(text = selectionOption)
},
onClick = {
instance = selectionOption
expanded = false
},
contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding,
)
val filteringOptions = instanceOptions.filter { it.contains(instance, ignoreCase = true) }
MV-GH marked this conversation as resolved.
Show resolved Hide resolved
if (filteringOptions.isNotEmpty()) {
DropdownMenu(
expanded = expanded,
onDismissRequest = {},
properties = PopupProperties(focusable = false),
modifier = Modifier.exposedDropdownSize(true),
) {
filteringOptions.forEach { selectionOption ->
DropdownMenuItem(
modifier = Modifier.exposedDropdownSize(),
text = {
Text(text = selectionOption)
},
onClick = {
instance = selectionOption
expanded = false
},
)
}
}
}
}

MyTextField(
modifier = Modifier
.width(OutlinedTextFieldDefaults.MinWidth)
.background(if (wasAutofilled) MaterialTheme.colorScheme.surfaceVariant else Color.Transparent)
.onAutofill(AutofillType.Username, AutofillType.EmailAddress) {
username = it
Expand All @@ -176,6 +184,7 @@ fun LoginForm(
)
PasswordField(
modifier = Modifier
.width(OutlinedTextFieldDefaults.MinWidth)
.background(if (wasAutofilled) MaterialTheme.colorScheme.surfaceVariant else Color.Transparent)
.onAutofill(AutofillType.Password) {
password = it
Expand All @@ -186,6 +195,7 @@ fun LoginForm(
)
MyTextField(
modifier = Modifier
.width(OutlinedTextFieldDefaults.MinWidth)
.background(if (wasAutofilled) MaterialTheme.colorScheme.surfaceVariant else Color.Transparent)
.onAutofill(AutofillType.SmsOtpCode) {
totp = it
Expand All @@ -201,7 +211,7 @@ fun LoginForm(
modifier = Modifier.padding(top = 10.dp),
) {
if (loading) {
CircularProgressIndicator()
CircularProgressIndicator(modifier = Modifier.size(LocalTextStyle.current.fontSize.value.dp))
} else {
Text(stringResource(R.string.login_login))
}
Expand Down