-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PM-10242 PM-10243 PM-10244 PM-10245 PM-10246: Welcome carousel
- Loading branch information
1 parent
260b3bf
commit 74d261a
Showing
18 changed files
with
922 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeNavigation.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.x8bit.bitwarden.ui.auth.feature.welcome | ||
|
||
import androidx.navigation.NavController | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.NavOptions | ||
import com.x8bit.bitwarden.ui.platform.base.util.composableWithStayTransitions | ||
|
||
const val WELCOME_ROUTE: String = "welcome" | ||
|
||
/** | ||
* Navigate to the welcome screen. | ||
*/ | ||
fun NavController.navigateToWelcome(navOptions: NavOptions? = null) { | ||
this.navigate(WELCOME_ROUTE, navOptions) | ||
} | ||
|
||
/** | ||
* Add the Welcome screen to the nav graph. | ||
*/ | ||
fun NavGraphBuilder.welcomeDestination( | ||
onNavigateToCreateAccount: () -> Unit, | ||
onNavigateToLogin: () -> Unit, | ||
) { | ||
composableWithStayTransitions( | ||
route = WELCOME_ROUTE, | ||
) { | ||
WelcomeScreen( | ||
onNavigateToCreateAccount = onNavigateToCreateAccount, | ||
onNavigateToLogin = onNavigateToLogin, | ||
) | ||
} | ||
} |
216 changes: 216 additions & 0 deletions
216
app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeScreen.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
package com.x8bit.bitwarden.ui.auth.feature.welcome | ||
|
||
import androidx.compose.animation.animateColorAsState | ||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.lazy.LazyRow | ||
import androidx.compose.foundation.pager.HorizontalPager | ||
import androidx.compose.foundation.pager.PagerState | ||
import androidx.compose.foundation.pager.rememberPagerState | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.snapshotFlow | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import com.x8bit.bitwarden.R | ||
import com.x8bit.bitwarden.ui.platform.base.util.EventsEffect | ||
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenFilledButton | ||
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenTextButton | ||
import com.x8bit.bitwarden.ui.platform.components.scaffold.BitwardenScaffold | ||
import com.x8bit.bitwarden.ui.platform.components.util.rememberVectorPainter | ||
|
||
/** | ||
* Top level composable for the welcome screen. | ||
*/ | ||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class) | ||
@Composable | ||
fun WelcomeScreen( | ||
onNavigateToCreateAccount: () -> Unit, | ||
onNavigateToLogin: () -> Unit, | ||
viewModel: WelcomeViewModel = hiltViewModel(), | ||
) { | ||
val state by viewModel.stateFlow.collectAsStateWithLifecycle() | ||
val pagerState = rememberPagerState(pageCount = { state.pages.size }) | ||
|
||
EventsEffect(viewModel = viewModel) { event -> | ||
when (event) { | ||
is WelcomeEvent.UpdatePager -> { | ||
pagerState.animateScrollToPage(event.index) | ||
} | ||
|
||
WelcomeEvent.NavigateToCreateAccount -> onNavigateToCreateAccount() | ||
WelcomeEvent.NavigateToLogin -> onNavigateToLogin() | ||
} | ||
} | ||
|
||
BitwardenScaffold( | ||
modifier = Modifier.fillMaxSize(), | ||
) { innerPadding -> | ||
WelcomeScreenContent( | ||
state = state, | ||
pagerState = pagerState, | ||
onPagerSwipe = remember(viewModel) { | ||
{ viewModel.trySendAction(WelcomeAction.PagerSwipe(it)) } | ||
}, | ||
onDotClick = remember(viewModel) { | ||
{ viewModel.trySendAction(WelcomeAction.DotClick(it)) } | ||
}, | ||
onCreateAccountClick = remember(viewModel) { | ||
{ viewModel.trySendAction(WelcomeAction.CreateAccountClick) } | ||
}, | ||
onLoginClick = remember(viewModel) { | ||
{ viewModel.trySendAction(WelcomeAction.LoginClick) } | ||
}, | ||
modifier = Modifier | ||
.padding(innerPadding) | ||
.fillMaxSize(), | ||
) | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalFoundationApi::class) | ||
@Composable | ||
private fun WelcomeScreenContent( | ||
state: WelcomeState, | ||
pagerState: PagerState, | ||
onPagerSwipe: (Int) -> Unit, | ||
onDotClick: (Int) -> Unit, | ||
onCreateAccountClick: () -> Unit, | ||
onLoginClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
LaunchedEffect(pagerState) { | ||
snapshotFlow { pagerState.currentPage }.collect { onPagerSwipe(it) } | ||
} | ||
|
||
Column( | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
modifier = modifier, | ||
) { | ||
Spacer(modifier = Modifier.weight(1f)) | ||
|
||
HorizontalPager(state = pagerState) { index -> | ||
WelcomeCard( | ||
state = state.pages[index], | ||
modifier = Modifier.padding(horizontal = 16.dp), | ||
) | ||
} | ||
|
||
Spacer(modifier = Modifier.weight(1f)) | ||
|
||
IndicatorDots( | ||
selectedIndexProvider = { state.index }, | ||
totalCount = state.pages.size, | ||
onDotClick = onDotClick, | ||
modifier = Modifier | ||
.padding(bottom = 32.dp) | ||
.height(44.dp), | ||
) | ||
|
||
BitwardenFilledButton( | ||
label = stringResource(id = R.string.create_account), | ||
onClick = onCreateAccountClick, | ||
modifier = Modifier | ||
.padding(horizontal = 16.dp) | ||
.fillMaxWidth(), | ||
) | ||
|
||
BitwardenTextButton( | ||
label = stringResource(id = R.string.log_in), | ||
onClick = onLoginClick, | ||
modifier = Modifier | ||
.padding(horizontal = 16.dp) | ||
.padding(bottom = 32.dp), | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun WelcomeCard( | ||
state: WelcomeState.WelcomeCard, | ||
modifier: Modifier = Modifier, | ||
) { | ||
Column( | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
modifier = modifier, | ||
) { | ||
Image( | ||
painter = rememberVectorPainter(id = state.imageRes), | ||
contentDescription = null, | ||
modifier = Modifier | ||
.size(200.dp) | ||
.padding(bottom = 32.dp), | ||
) | ||
|
||
Text( | ||
text = stringResource(id = state.titleRes), | ||
textAlign = TextAlign.Center, | ||
style = MaterialTheme.typography.headlineMedium, | ||
color = MaterialTheme.colorScheme.onSurface, | ||
modifier = Modifier.padding(vertical = 16.dp), | ||
) | ||
|
||
Text( | ||
text = stringResource(id = state.messageRes), | ||
textAlign = TextAlign.Center, | ||
style = MaterialTheme.typography.bodyLarge, | ||
color = MaterialTheme.colorScheme.onSurface, | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun IndicatorDots( | ||
selectedIndexProvider: () -> Int, | ||
totalCount: Int, | ||
onDotClick: (Int) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
LazyRow( | ||
horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
verticalAlignment = Alignment.CenterVertically, | ||
modifier = modifier, | ||
) { | ||
items(totalCount) { index -> | ||
val color = animateColorAsState( | ||
targetValue = if (index == selectedIndexProvider()) { | ||
MaterialTheme.colorScheme.onSurface | ||
} else { | ||
MaterialTheme.colorScheme.onSurface.copy(alpha = 0.3f) | ||
}, | ||
label = "dotColor", | ||
) | ||
|
||
Box( | ||
modifier = Modifier | ||
.size(8.dp) | ||
.clip(CircleShape) | ||
.background(color.value) | ||
.clickable { onDotClick(index) }, | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.