Skip to content

Commit

Permalink
GOVUKAPP-1009 Onboarding screens missed when using swipe to navigate (#…
Browse files Browse the repository at this point in the history
…152)

* Only request focus of page title on current page
  • Loading branch information
TimGJD authored Dec 13, 2024
1 parent 947bbf4 commit 04297e5
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -84,7 +83,6 @@ internal fun OnboardingRoute(
)
}

@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun OnboardingScreen(
pages: List<OnboardingPage>,
Expand All @@ -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()
Expand Down Expand Up @@ -150,6 +151,7 @@ private fun OnboardingScreen(
@Composable
private fun Page(
page: OnboardingPage,
isCurrentPage: Boolean,
modifier: Modifier = Modifier
) {
val focusRequester = remember { FocusRequester() }
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 04297e5

Please sign in to comment.