Skip to content

Instantly share code, notes, and snippets.

@ch8n
Created November 20, 2021 08:58
Show Gist options
  • Save ch8n/4337beda53e15d807090f82429ee56b9 to your computer and use it in GitHub Desktop.
Save ch8n/4337beda53e15d807090f82429ee56b9 to your computer and use it in GitHub Desktop.
@Composable
fun OtpCell(
modifier: Modifier,
value: String,
isCursorVisible: Boolean = false
) {
val scope = rememberCoroutineScope()
val (cursorSymbol, setCursorSymbol) = remember { mutableStateOf("")
// Cursor blinking logic
LaunchedEffect(key1 = cursorSymbol,isCursorVisible) {
if (isCursorVisible){
scope.launch {
delay(350)
setCursorSymbol(if (cursorSymbol.isEmpty()) "|" else "")
}
}
}
// UI for OTP Character
Box(
modifier = modifier
) {
Text(
text = if (isCursorVisible) cursorSymbol else value,
style = MaterialTheme.typography.body1,
modifier = Modifier.align(Alignment.Center)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment