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

fix: app crash when clicking next on create account screen #2183

Merged
merged 5 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.autofill.AutofillType
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
Expand All @@ -35,9 +34,8 @@ import androidx.compose.ui.text.input.TextFieldValue
import com.wire.android.R
import com.wire.android.ui.common.ShakeAnimation
import com.wire.android.ui.common.error.CoreFailureErrorDialog
import com.wire.android.ui.common.textfield.AutoFillTextField
import com.wire.android.ui.common.textfield.WireTextField
import com.wire.android.ui.common.textfield.WireTextFieldState
import com.wire.android.ui.common.textfield.clearAutofillTree
import com.wire.android.ui.theme.wireDimensions

@OptIn(ExperimentalComposeUiApi::class)
Expand All @@ -50,7 +48,6 @@ fun UsernameTextField(
onUsernameChange: (TextFieldValue) -> Unit,
onUsernameErrorAnimated: () -> Unit
) {
clearAutofillTree()
if (errorState is HandleUpdateErrorState.DialogError.GenericError) {
CoreFailureErrorDialog(errorState.coreFailure, onErrorDismiss)
}
Expand All @@ -61,8 +58,7 @@ fun UsernameTextField(
animate()
onUsernameErrorAnimated()
}
AutoFillTextField(
autofillTypes = listOf(AutofillType.Username),
WireTextField(
value = username,
onValueChange = onUsernameChange,
placeholderText = stringResource(R.string.create_account_username_placeholder),
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -42,7 +41,6 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.autofill.AutofillType
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.LocalContext
Expand All @@ -69,9 +67,8 @@ import com.wire.android.ui.common.button.WireButtonState
import com.wire.android.ui.common.button.WirePrimaryButton
import com.wire.android.ui.common.button.WireSecondaryButton
import com.wire.android.ui.common.error.CoreFailureErrorDialog
import com.wire.android.ui.common.textfield.AutoFillTextField
import com.wire.android.ui.common.textfield.WireTextField
import com.wire.android.ui.common.textfield.WireTextFieldState
import com.wire.android.ui.common.textfield.clearAutofillTree
import com.wire.android.ui.common.topappbar.WireCenterAlignedTopAppBar
import com.wire.android.ui.theme.wireColorScheme
import com.wire.android.ui.theme.wireDimensions
Expand All @@ -95,7 +92,7 @@ fun CreateAccountEmailScreen(viewModel: CreateAccountEmailViewModel, serverConfi
)
}

@OptIn(ExperimentalComposeUiApi::class, ExperimentalLayoutApi::class)
@OptIn(ExperimentalComposeUiApi::class)
@Composable
private fun EmailContent(
state: CreateAccountEmailViewState,
Expand All @@ -109,7 +106,6 @@ private fun EmailContent(
tosUrl: String,
serverConfig: ServerConfig.Links
) {
clearAutofillTree()
val focusRequester = remember { FocusRequester() }

Scaffold(topBar = {
Expand Down Expand Up @@ -144,8 +140,7 @@ private fun EmailContent(
)
.testTag("createTeamText")
)
AutoFillTextField(
autofillTypes = listOf(AutofillType.EmailAddress),
WireTextField(
value = state.email,
onValueChange = onEmailChange,
placeholderText = stringResource(R.string.create_account_email_placeholder),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ private fun PasswordTextField(state: RegisterDeviceState, onPasswordChange: (Tex
keyboardActions = KeyboardActions(onDone = { keyboardController?.hide() }),
modifier = Modifier
.padding(horizontal = MaterialTheme.wireDimensions.spacing16x)
.testTag("password field")
.testTag("password field"),
autofill = true
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ fun RemoveDeviceDialog(
modifier = Modifier
.focusRequester(focusRequester)
.padding(bottom = MaterialTheme.wireDimensions.spacing8x)
.testTag("remove device password field")
.testTag("remove device password field"),
autofill = true
)
LaunchedEffect(Unit) { // executed only once when showing the dialog
focusRequester.requestFocus()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ private fun PasswordInput(modifier: Modifier, password: TextFieldValue, onPasswo
onValueChange = onPasswordChange,
imeAction = ImeAction.Done,
keyboardActions = KeyboardActions(onDone = { keyboardController?.hide() }),
modifier = modifier.testTag("passwordField")
modifier = modifier.testTag("passwordField"),
autofill = true
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private fun ProxyPasswordInput(modifier: Modifier, proxyPassword: TextFieldValue
labelText = stringResource(R.string.label_proxy_password),
keyboardActions = KeyboardActions(onDone = { keyboardController?.hide() }),
modifier = modifier.testTag("passwordField"),
autofillTypes = listOf()
autofill = false
)
}

Expand Down
8 changes: 6 additions & 2 deletions app/src/main/kotlin/com/wire/android/ui/common/WireDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ fun PreviewWireDialog() {
) {
WirePasswordTextField(
value = password,
onValueChange = { password = it })
onValueChange = { password = it },
autofill = false
)
}
}
}
Expand Down Expand Up @@ -320,7 +322,9 @@ fun PreviewWireDialogWith2OptionButtons() {
) {
WirePasswordTextField(
value = password,
onValueChange = { password = it })
onValueChange = { password = it },
autofill = true
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.autofill.Autofill
import androidx.compose.ui.autofill.AutofillNode
import androidx.compose.ui.autofill.AutofillType
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.layout.boundsInWindow
import androidx.compose.ui.layout.onGloballyPositioned
Expand Down Expand Up @@ -70,7 +72,8 @@ internal fun AutoFillTextField(
inputMinHeight: Dp = MaterialTheme.wireDimensions.textFieldMinHeight,
shape: Shape = RoundedCornerShape(MaterialTheme.wireDimensions.textFieldCornerSize),
colors: WireTextFieldColors = wireTextFieldColors(),
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
onTap: (Offset) -> Unit = { },
) {
val autofillNode = AutofillNode(
autofillTypes = autofillTypes,
Expand Down Expand Up @@ -103,19 +106,27 @@ internal fun AutoFillTextField(
shape = shape,
colors = colors,
modifier = modifier
.onGloballyPositioned { autofillNode.boundingBox = it.boundsInWindow() }
.onFocusChanged { focusState ->
autofill?.run {
if (focusState.isFocused) {
requestAutofillForNode(autofillNode)
} else {
cancelAutofillForNode(autofillNode)
}
}
}
.fillBounds(autofillNode)
.defaultOnFocusAutoFill(autofill, autofillNode),
onTap = onTap
)
}

@OptIn(ExperimentalComposeUiApi::class)
fun Modifier.fillBounds(autofillNode: AutofillNode) = this.then(
Modifier.onGloballyPositioned { autofillNode.boundingBox = it.boundsInWindow() }
)

@OptIn(ExperimentalComposeUiApi::class)
fun Modifier.defaultOnFocusAutoFill(autofill: Autofill?, autofillNode: AutofillNode): Modifier =
then(Modifier.onFocusChanged { focusState ->
if (focusState.isFocused) {
autofill?.requestAutofillForNode(autofillNode)
} else {
autofill?.cancelAutofillForNode(autofillNode)
}
})

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun clearAutofillTree() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.autofill.AutofillType
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -76,57 +77,99 @@ fun WirePasswordTextField(
shape: Shape = RoundedCornerShape(16.dp),
colors: WireTextFieldColors = wireTextFieldColors(),
modifier: Modifier = Modifier,
autofillTypes: List<AutofillType>? = null
autofill: Boolean,
onTap: (Offset) -> Unit = { },
) {
var passwordVisibility by remember { mutableStateOf(false) }
AutoFillTextField(
autofillTypes = autofillTypes ?: listOf(AutofillType.Password),
value = value,
onValueChange = onValueChange,
readOnly = readOnly,
singleLine = true,
maxLines = 1,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password, autoCorrect = false, imeAction = imeAction),
keyboardActions = keyboardActions,
placeholderText = placeholderText,
labelText = labelText,
labelMandatoryIcon = labelMandatoryIcon,
descriptionText = descriptionText,
state = state,
interactionSource = interactionSource,
textStyle = textStyle,
placeholderTextStyle = placeHolderTextStyle,
inputMinHeight = inputMinHeight,
shape = shape,
colors = colors,
modifier = modifier,
visualTransformation = if (passwordVisibility) VisualTransformation.None else PasswordVisualTransformation(),
trailingIcon = {
val image = if (passwordVisibility) Icons.Filled.Visibility else Icons.Filled.VisibilityOff
IconButton(onClick = { passwordVisibility = !passwordVisibility }) {
Icon(
imageVector = image,
contentDescription = stringResource(
if (!passwordVisibility) R.string.content_description_reveal_password
else R.string.content_description_hide_password
),
modifier = Modifier
.size(20.dp)
.testTag("hidePassword")
)
}
},
)
}

val keyBoardOption = remember {
KeyboardOptions(keyboardType = KeyboardType.Password, autoCorrect = false, imeAction = imeAction)
}

val visualTransformation = remember(passwordVisibility) {
if (passwordVisibility) VisualTransformation.None else PasswordVisualTransformation()
}

val icon = remember(passwordVisibility) {
if (passwordVisibility) Icons.Filled.Visibility else Icons.Filled.VisibilityOff
}

val iconButton = @Composable {
IconButton(onClick = { passwordVisibility = !passwordVisibility }) {
Icon(
imageVector = icon,
contentDescription = stringResource(
if (!passwordVisibility) R.string.content_description_reveal_password
else R.string.content_description_hide_password
),
modifier = Modifier
.size(20.dp)
.testTag("hidePassword")
)
}
}

if (autofill) {
AutoFillTextField(
value = value,
onValueChange = onValueChange,
readOnly = readOnly,
singleLine = true,
maxLines = 1,
keyboardOptions = keyBoardOption,
keyboardActions = keyboardActions,
placeholderText = placeholderText,
labelText = labelText,
labelMandatoryIcon = labelMandatoryIcon,
descriptionText = descriptionText,
state = state,
interactionSource = interactionSource,
textStyle = textStyle,
placeholderTextStyle = placeHolderTextStyle,
inputMinHeight = inputMinHeight,
shape = shape,
colors = colors,
modifier = modifier,
visualTransformation = visualTransformation,
trailingIcon = iconButton,
autofillTypes = listOf(AutofillType.Password),
onTap = onTap
)
} else {
WireTextField(
value = value,
onValueChange = onValueChange,
readOnly = readOnly,
singleLine = true,
maxLines = 1,
keyboardOptions = keyBoardOption,
keyboardActions = keyboardActions,
placeholderText = placeholderText,
labelText = labelText,
labelMandatoryIcon = labelMandatoryIcon,
descriptionText = descriptionText,
state = state,
interactionSource = interactionSource,
textStyle = textStyle,
placeholderTextStyle = placeHolderTextStyle,
inputMinHeight = inputMinHeight,
shape = shape,
colors = colors,
modifier = modifier,
visualTransformation = visualTransformation,
trailingIcon = iconButton,
onTap = onTap
)
}
}

@OptIn(ExperimentalComposeUiApi::class)
@Preview(name = "Default WirePasswordTextField")
@Composable
fun PreviewWirePasswordTextField() {
WirePasswordTextField(
value = TextFieldValue(""),
onValueChange = {},
modifier = Modifier.padding(16.dp)
modifier = Modifier.padding(16.dp),
autofill = false
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.TextFieldValue
Expand All @@ -52,7 +51,6 @@ import com.wire.android.util.permission.rememberCreateFileFlow
import java.util.Locale
import kotlin.math.roundToInt

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun SetBackupPasswordDialog(
isBackupPasswordValid: Boolean,
Expand Down Expand Up @@ -85,7 +83,8 @@ fun SetBackupPasswordDialog(
onValueChange = {
backupPassword = it
onBackupPasswordChanged(it)
}
},
autofill = false
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ fun EnterRestorePasswordDialog(
) {
WirePasswordTextField(
value = restorePassword,
onValueChange = { restorePassword = it }
onValueChange = { restorePassword = it },
autofill = false
)
}
} else {
Expand Down
Loading