From a4266f9c3d4952074d6a6e1b65ab579dea0ddb20 Mon Sep 17 00:00:00 2001 From: TimDenyer Date: Fri, 13 Dec 2024 11:28:30 +0000 Subject: [PATCH 1/2] Only request focus of page title on current page --- .../uk/govuk/app/onboarding/ui/OnboardingScreen.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 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..0ea67f9c 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,7 +151,8 @@ private fun OnboardingScreen( @Composable private fun Page( page: OnboardingPage, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, + isCurrentPage: Boolean ) { val focusRequester = remember { FocusRequester() } val windowSizeClass = currentWindowAdaptiveInfo().windowSizeClass @@ -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() } From 0ce3f6f0859875fdd744a1c68fa829db59ae2a04 Mon Sep 17 00:00:00 2001 From: TimDenyer Date: Fri, 13 Dec 2024 12:32:53 +0000 Subject: [PATCH 2/2] Declare default param last --- .../kotlin/uk/govuk/app/onboarding/ui/OnboardingScreen.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 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 0ea67f9c..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 @@ -151,8 +151,8 @@ private fun OnboardingScreen( @Composable private fun Page( page: OnboardingPage, - modifier: Modifier = Modifier, - isCurrentPage: Boolean + isCurrentPage: Boolean, + modifier: Modifier = Modifier ) { val focusRequester = remember { FocusRequester() } val windowSizeClass = currentWindowAdaptiveInfo().windowSizeClass