Skip to content

Instantly share code, notes, and snippets.

@hieuwu
Created August 1, 2023 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hieuwu/94b5eeee2563c490cb310050cec4da51 to your computer and use it in GitHub Desktop.
Save hieuwu/94b5eeee2563c490cb310050cec4da51 to your computer and use it in GitHub Desktop.
@Composable
fun SignUpScreen(
modifier: Modifier = Modifier,
navController: NavController,
viewModel: SignUpViewModel = hiltViewModel()
) {
val snackBarHostState = remember { SnackbarHostState() }
val coroutineScope = rememberCoroutineScope()
Scaffold(
snackbarHost = { androidx.compose.material.SnackbarHost(snackBarHostState) },
topBar = {
TopAppBar(
navigationIcon = {
IconButton(onClick = {
navController.navigateUp()
}) {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = null,
tint = MaterialTheme.colorScheme.onPrimary
)
}
},
backgroundColor = MaterialTheme.colorScheme.primary,
title = {
Text(
text = "Sign Up",
color = MaterialTheme.colorScheme.onPrimary,
)
},
)
}
) { paddingValues ->
Column(
modifier = modifier
.padding(paddingValues)
.padding(20.dp)
) {
val email = viewModel.email.collectAsState(initial = "")
val password = viewModel.password.collectAsState()
OutlinedTextField(
label = {
Text(
text = "Email",
color = MaterialTheme.colorScheme.primary,
style = MaterialTheme.typography.titleMedium
)
},
maxLines = 1,
shape = RoundedCornerShape(32),
modifier = modifier.fillMaxWidth(),
value = email.value,
onValueChange = {
viewModel.onEmailChange(it)
},
)
OutlinedTextField(
label = {
Text(
text = "Password",
color = MaterialTheme.colorScheme.primary,
style = MaterialTheme.typography.titleMedium
)
},
maxLines = 1,
shape = RoundedCornerShape(32),
modifier = modifier
.fillMaxWidth()
.padding(top = 12.dp),
value = password.value,
onValueChange = {
viewModel.onPasswordChange(it)
},
)
val localSoftwareKeyboardController = LocalSoftwareKeyboardController.current
Button(modifier = modifier
.fillMaxWidth()
.padding(top = 12.dp),
onClick = {
localSoftwareKeyboardController?.hide()
viewModel.onSignUp()
coroutineScope.launch {
snackBarHostState.showSnackbar(
message = "Create account successfully. Sign in now!",
duration = SnackbarDuration.Long
)
}
}) {
Text("Sign up")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment