From 04297e5bb4cde6b0723574207a12899a726e4dec Mon Sep 17 00:00:00 2001 From: Tim Denyer <30877434+TimGJD@users.noreply.github.com> Date: Fri, 13 Dec 2024 16:40:50 +0000 Subject: [PATCH] GOVUKAPP-1009 Onboarding screens missed when using swipe to navigate (#152) * Only request focus of page title on current page --- .../uk/govuk/app/onboarding/ui/OnboardingScreen.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/feature/onboarding/src/main/kotlin/uk/govuk/app/onboarding/ui/OnboardingScreen.kt b/feature/onboarding/src/main/kotlin/uk/govuk/app/onboarding/ui/OnboardingScreen.kt index b67affd0..00b70916 100644 --- a/feature/onboarding/src/main/kotlin/uk/govuk/app/onboarding/ui/OnboardingScreen.kt +++ b/feature/onboarding/src/main/kotlin/uk/govuk/app/onboarding/ui/OnboardingScreen.kt @@ -1,6 +1,5 @@ package uk.govuk.app.onboarding.ui -import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.border @@ -84,7 +83,6 @@ internal fun OnboardingRoute( ) } -@OptIn(ExperimentalFoundationApi::class) @Composable private fun OnboardingScreen( pages: List, @@ -111,7 +109,10 @@ private fun OnboardingScreen( .weight(1f), verticalAlignment = Alignment.Top ) { pageIndex -> - Page(pages[pageIndex]) + Page( + page = pages[pageIndex], + isCurrentPage = pagerState.currentPage == pageIndex + ) } ListDivider() @@ -150,6 +151,7 @@ private fun OnboardingScreen( @Composable private fun Page( page: OnboardingPage, + isCurrentPage: Boolean, modifier: Modifier = Modifier ) { val focusRequester = remember { FocusRequester() } @@ -189,8 +191,10 @@ private fun Page( .padding(horizontal = GovUkTheme.spacing.extraLarge), textAlign = TextAlign.Center ) + } - LaunchedEffect(page.title) { + LaunchedEffect(page.title) { + if (isCurrentPage) { delay(200) focusRequester.requestFocus() }