Skip to content

Commit

Permalink
(#0) Tweak page order to display considerations first
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangl committed Oct 31, 2021
1 parent f8af683 commit 4fc29a3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ package com.adriangl.pict2cam.onboarding

import android.os.Build
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.*
import androidx.compose.material.Card
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Text
Expand Down Expand Up @@ -52,8 +49,8 @@ fun OnboardingCreditsCard(title: String,

Card(
modifier = Modifier
.padding(vertical = 8.dp)
.clickable {
.padding(vertical = 8.dp)
.clickable {
url?.let {
context.openWebsite(it)
}
Expand All @@ -73,6 +70,7 @@ fun OnboardingCreditsCard(title: String,
fun OnboardingScreen(onExitClick: () -> Unit = {}) {
Pict2CamTheme {
OnboardingPager(
modifier = Modifier.fillMaxSize(),
onboardingPages =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// We'll display an incompatibility screen for Android 11+
Expand All @@ -94,6 +92,13 @@ fun OnboardingScreen(onExitClick: () -> Unit = {}) {
backgroundColor = colorResource(id = R.color.onboarding_welcome_background_color),
image = painterResource(id = R.drawable.ic_onboarding_app_logo),
),
OnboardingPageInfo(
title = stringResource(id = R.string.onboarding_instant_messaging_apps_title),
description = stringResource(id = R.string.onboarding_instant_messaging_apps_description),
backgroundColor =
colorResource(id = R.color.onboarding_instant_messaging_apps_background_color),
image = painterResource(id = R.drawable.ic_onboarding_messaging_apps)
),
OnboardingPageInfo(
title = stringResource(id = R.string.onboarding_pick_intent_title),
description = stringResource(id = R.string.onboarding_pick_intent_description),
Expand All @@ -106,13 +111,6 @@ fun OnboardingScreen(onExitClick: () -> Unit = {}) {
backgroundColor = colorResource(id = R.color.onboarding_crop_image_background_color),
image = painterResource(id = R.drawable.ic_onboarding_crop_image),
),
OnboardingPageInfo(
title = stringResource(id = R.string.onboarding_instant_messaging_apps_title),
description = stringResource(id = R.string.onboarding_instant_messaging_apps_description),
backgroundColor =
colorResource(id = R.color.onboarding_instant_messaging_apps_background_color),
image = painterResource(id = R.drawable.ic_onboarding_messaging_apps)
),
OnboardingPageInfo(
title = stringResource(id = R.string.onboarding_credits_title),
backgroundColor = colorResource(id = R.color.onboarding_credits_background_color),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ data class OnboardingPageInfo(val title: AnnotatedString,
fun OnboardingPage(onboardingPageInfo: OnboardingPageInfo) {
Column(
modifier = Modifier
.fillMaxSize()
.background(color = onboardingPageInfo.backgroundColor)
.padding(16.dp)
.fillMaxSize()
.background(color = onboardingPageInfo.backgroundColor)
.padding(16.dp)
) {
Column(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
.weight(2f),
.fillMaxWidth()
.fillMaxHeight()
.weight(2f),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Expand All @@ -108,17 +108,17 @@ fun OnboardingPage(onboardingPageInfo: OnboardingPageInfo) {
} else if (onboardingPageInfo.content != null) {
onboardingPageInfo.content?.invoke(
Modifier
.fillMaxWidth()
.fillMaxHeight()
.weight(5f)
.fillMaxWidth()
.fillMaxHeight()
.weight(5f)
)
}

Column(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
.weight(3f),
.fillMaxWidth()
.fillMaxHeight()
.weight(3f),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Expand All @@ -137,14 +137,15 @@ fun OnboardingPage(onboardingPageInfo: OnboardingPageInfo) {
@Composable
@OptIn(ExperimentalPagerApi::class)
@Suppress("UndocumentedPublicFunction")
fun OnboardingPager(onboardingPages: List<OnboardingPageInfo>,
fun OnboardingPager(modifier: Modifier = Modifier,
onboardingPages: List<OnboardingPageInfo>,
onExitClick: () -> Unit = {}) {
val pagerState = rememberPagerState(0)
val coroutineScope = rememberCoroutineScope()

fun isLastPage() = pagerState.currentPage == onboardingPages.size - 1

Box(modifier = Modifier.fillMaxSize()) {
Box(modifier = modifier) {
HorizontalPager(state = pagerState, count = onboardingPages.size) { page ->
OnboardingPage(onboardingPages[page])
}
Expand All @@ -162,18 +163,18 @@ fun OnboardingPager(onboardingPages: List<OnboardingPageInfo>,

Column(
modifier = Modifier
.padding(bottom = 16.dp, end = 16.dp)
.clip(CircleShape)
.background(Color.Black.copy(alpha = 0.3f))
.align(Alignment.BottomEnd)
.clickable {
.padding(bottom = 16.dp, end = 16.dp)
.clip(CircleShape)
.background(Color.Black.copy(alpha = 0.3f))
.align(Alignment.BottomEnd)
.clickable {
if (isLastPage()) {
onExitClick()
} else {
coroutineScope.launch {
onExitClick()
} else {
coroutineScope.launch {
pagerState.scrollToPage(pagerState.currentPage + 1)
}
}
}
},
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
Expand Down

0 comments on commit 4fc29a3

Please sign in to comment.