Created
August 1, 2023 14:35
-
-
Save hieuwu/94b5eeee2563c490cb310050cec4da51 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
@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