I am new in jetpack compos. Can anyone tell me It's Right to Create Common Composeble Function? Common Function
@Composable
fun commonTextFiled(
hint: String,
icon: ImageVector,
keyboardType: KeyboardType = KeyboardType.Text,
imeAction: ImeAction = ImeAction.Done,
trailingIcon: Boolean = false
): String {
var textOfEditText by rememberSaveable { mutableStateOf("") }
var toggleClick by rememberSaveable { mutableStateOf(false) }
TextField(
value = textOfEditText,
onValueChange = { textOfEditText = it },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 20.dp),
keyboardOptions = KeyboardOptions(
KeyboardCapitalization.Characters,
autoCorrect = false,
keyboardType = keyboardType, imeAction
),
placeholder = { Text(text = hint) },
visualTransformation = if (toggleClick) VisualTransformation.None else PasswordVisualTransformation()
,leadingIcon = { Icon(icon, contentDescription = null) },
trailingIcon = {
if (trailingIcon) {
val image: Int = if (toggleClick) {
R.drawable.visibil
} else {
R.drawable.visibility_off
}
IconButton(onClick = { toggleClick =!toggleClick }) {
Icon(painter = painterResource(id = image), contentDescription = null)
}
}
},
singleLine = true
)
return textOfEditText
}
Calling Common Functions --------------------
var email by rememberSaveable { mutableStateOf("") }
var password by rememberSaveable { mutableStateOf("") }
Spacer(modifier = modifier.padding(vertical = 10.dp))
email = commonTextFiled(hint = "Enter Your Email", icon = Icons.Filled.Email)
Spacer(modifier = modifier.padding(vertical = 10.dp))
password = commonTextFiled("password", Icons.Filled.Lock, trailingIcon = true)
I am very confused about it is rigth or wrong way to create and call compose function like this. and thanks in advance.