Created
December 31, 2023 09:45
-
-
Save muhammedesadcomert/ca45b93db483e42af6120dae73d48cac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.compose.foundation.clickable | |
import androidx.compose.foundation.layout.fillMaxWidth | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.foundation.text.KeyboardOptions | |
import androidx.compose.material3.Icon | |
import androidx.compose.material3.Text | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.getValue | |
import androidx.compose.runtime.mutableStateOf | |
import androidx.compose.runtime.remember | |
import androidx.compose.runtime.setValue | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.res.painterResource | |
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.text.input.VisualTransformation | |
import androidx.compose.ui.unit.dp | |
import com.generousstudio.waterwave.R | |
@Composable | |
fun PasswordOutlinedTextField(state: PasswordState) { | |
BaseOutlinedTextField( | |
modifier = Modifier | |
.fillMaxWidth() | |
.padding(bottom = 16.dp), | |
value = state.password, | |
onValueChange = { | |
state.password = it | |
}, | |
label = { | |
Text(text = stringResource(R.string.password)) | |
}, | |
trailingIcon = { | |
if (state.passwordVisibility) { | |
Icon( | |
modifier = Modifier.clickable { | |
state.passwordVisibility = false | |
}, | |
painter = painterResource(id = R.drawable.visibility_on), | |
contentDescription = stringResource(R.string.hide_password) | |
) | |
} else { | |
Icon( | |
modifier = Modifier.clickable { | |
state.passwordVisibility = true | |
}, | |
painter = painterResource(id = R.drawable.visibility_off), | |
contentDescription = stringResource(R.string.show_password) | |
) | |
} | |
}, | |
keyboardOptions = KeyboardOptions.Default.copy( | |
keyboardType = KeyboardType.Password, | |
imeAction = ImeAction.Done | |
), | |
visualTransformation = if (state.passwordVisibility) { | |
VisualTransformation.None | |
} else { | |
PasswordVisualTransformation() | |
}, | |
singleLine = true | |
) | |
} | |
@Composable | |
fun rememberPasswordState() = remember { PasswordState() } | |
class PasswordState { | |
var password by mutableStateOf("") | |
var passwordVisibility by mutableStateOf(false) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment