Created
August 1, 2023 14:37
-
-
Save hieuwu/8c9e98e37eef33148284bb8d87799d1c 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
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class) | |
@Composable | |
fun SignInScreen( | |
modifier: Modifier = Modifier, | |
navController: NavController, | |
viewModel: SignInViewModel = 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 = "Login", | |
color = MaterialTheme.colorScheme.onPrimary, | |
) | |
}, | |
) | |
} | |
) { paddingValues -> | |
Column( | |
modifier = modifier | |
.padding(paddingValues) | |
.padding(20.dp) | |
) { | |
val email = viewModel.email.collectAsState(initial = "") | |
val password = viewModel.password.collectAsState() | |
androidx.compose.material.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) | |
}, | |
) | |
androidx.compose.material.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.onGoogleSignIn() | |
}) { | |
Text("Sign in with Google") | |
} | |
Button(modifier = modifier | |
.fillMaxWidth() | |
.padding(top = 12.dp), | |
onClick = { | |
localSoftwareKeyboardController?.hide() | |
viewModel.onSignIn() | |
coroutineScope.launch { | |
snackBarHostState.showSnackbar( | |
message = "Sign in successfully !", | |
duration = SnackbarDuration.Long | |
) | |
} | |
}) { | |
Text("Sign in") | |
} | |
OutlinedButton(modifier = modifier | |
.fillMaxWidth() | |
.padding(top = 12.dp), onClick = { | |
navController.navigate(SignUpDestination.route) | |
}) { | |
Text("Sign up") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment