Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Networking Sign Up Pane (Native): Add back auto-focus #8557

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
3 changes: 0 additions & 3 deletions financial-connections/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
<ID>MagicNumber:ConsentLogoHeader.kt$3</ID>
<ID>MagicNumber:ConsentLogoHeader.kt$4</ID>
<ID>MagicNumber:ConsentLogoHeader.kt$5</ID>
<ID>MagicNumber:ConsumerSessionExtensions.kt$10</ID>
<ID>MagicNumber:ConsumerSessionExtensions.kt$5</ID>
<ID>MagicNumber:ConsumerSessionExtensions.kt$7</ID>
<ID>MagicNumber:InstitutionPickerScreen.kt$0.5f</ID>
<ID>MagicNumber:InstitutionPickerScreen.kt$0.75f</ID>
<ID>MagicNumber:InstitutionPickerScreen.kt$10</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,24 @@ private fun NetworkingLinkSignupLoaded(
) {
val scrollState = rememberScrollState()
val phoneNumberFocusRequester = remember { FocusRequester() }
val emailFocusRequester = remember { FocusRequester() }

// When pane loads, focus on email field if it's empty
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I don’t think we need these comments, as the code already explains it :)

LaunchedEffect(true) {
if (payload.emailController.fieldValue.value.isEmpty()) {
emailFocusRequester.requestFocus()
}
}
// Everytime full form is shown, scroll to bottom and focus on phone number field (if not empty)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

LaunchedEffect(showFullForm) {
if (showFullForm) {
if (showFullForm && payload.phoneController.fieldValue.value.isEmpty()) {
scrollState.animateScrollToBottom()
phoneNumberFocusRequester.requestFocus()
}
}

Layout(
applyImePadding = false,
scrollState = scrollState,
body = {
Title(payload.content.title)
Expand All @@ -158,6 +167,7 @@ private fun NetworkingLinkSignupLoaded(

EmailSection(
showFullForm = showFullForm,
focusRequester = emailFocusRequester,
loading = lookupAccountSync is Loading,
emailController = payload.emailController,
enabled = true,
Expand Down Expand Up @@ -272,7 +282,8 @@ internal fun EmailSection(
enabled: Boolean,
emailController: TextFieldController,
showFullForm: Boolean,
loading: Boolean
loading: Boolean,
focusRequester: FocusRequester = remember { FocusRequester() }
) {
var focused by remember { mutableStateOf(false) }
StripeThemeForConnections {
Expand All @@ -284,6 +295,7 @@ internal fun EmailSection(
) {
TextFieldSection(
modifier = Modifier.onFocusChanged { focused = it.isFocused },
focusRequester = focusRequester,
isSelected = focused,
textFieldController = emailController,
imeAction = if (showFullForm) ImeAction.Next else ImeAction.Done,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.activity.SystemBarStyle
import androidx.activity.addCallback
import androidx.activity.compose.BackHandler
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material.ModalBottomSheetValue
Expand All @@ -19,6 +21,8 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.lifecycle.DefaultLifecycleObserver
Expand Down Expand Up @@ -93,6 +97,10 @@ internal class FinancialConnectionsSheetNativeActivity : AppCompatActivity() {

viewModel.activityRetainedComponent.inject(this)

enableEdgeToEdge(
statusBarStyle = SystemBarStyle.dark(Color.Transparent.toArgb()),
navigationBarStyle = SystemBarStyle.dark(Color.Transparent.toArgb())
)
observeBackPress()
observeBackgroundEvents()
observeViewEffects()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.stripe.android.financialconnections.ui

import androidx.compose.ui.Modifier

/**
* Conditionally applies the given [Modifier] functions based on the [condition].
*/
internal inline fun Modifier.conditional(
condition: Boolean,
ifTrue: Modifier.() -> Modifier,
ifFalse: Modifier.() -> Modifier = { this },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We don’t seem to use ifFalse. Should we rename this to fun Modifier.ifTrue(condition, action)?

): Modifier = if (condition) {
then(ifTrue(Modifier))
} else {
then(ifFalse(Modifier))
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListScope
Expand All @@ -36,6 +37,7 @@ import com.stripe.android.financialconnections.ui.components.DragHandle
import com.stripe.android.financialconnections.ui.components.FinancialConnectionsButton
import com.stripe.android.financialconnections.ui.components.FinancialConnectionsScaffold
import com.stripe.android.financialconnections.ui.components.FinancialConnectionsTopAppBar
import com.stripe.android.financialconnections.ui.conditional
import com.stripe.android.financialconnections.ui.theme.FinancialConnectionsTheme.typography

/**
Expand All @@ -47,6 +49,7 @@ import com.stripe.android.financialconnections.ui.theme.FinancialConnectionsThem
* @param inModal whether the layout is being used in a modal or not. If true, the [body] won't expand to fill the
* available content.
* @param showFooterShadowWhenScrollable whether to show a shadow at the top of the footer when the body is scrollable.
* @param applyImePadding whether to apply IME padding. When false, footer will be covered by the keyboard.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Should we rename this to keepFooterAboveKeyboard or something more concrete than applyImePadding?

* @param scrollState the [ScrollState] to use for the scrollable body.
*/
@Composable
Expand All @@ -56,6 +59,7 @@ internal fun Layout(
inModal: Boolean = false,
loading: Boolean = false,
showPillOnSlowLoad: Boolean = false,
applyImePadding: Boolean = true,
verticalArrangement: Arrangement.Vertical = Arrangement.Top,
showFooterShadowWhenScrollable: Boolean = true,
scrollState: ScrollState = rememberScrollState(),
Expand All @@ -66,6 +70,7 @@ internal fun Layout(
canScrollForward = scrollState.canScrollForward,
canScrollBackward = scrollState.canScrollBackward,
inModal = inModal,
applyImePadding = applyImePadding,
loading = loading,
showPillOnSlowLoad = showPillOnSlowLoad,
showFooterShadowWhenScrollable = showFooterShadowWhenScrollable,
Expand Down Expand Up @@ -101,6 +106,7 @@ internal fun Layout(
internal fun LazyLayout(
modifier: Modifier = Modifier,
bodyPadding: PaddingValues = PaddingValues(horizontal = 24.dp),
applyImePadding: Boolean = true,
inModal: Boolean = false,
loading: Boolean = false,
showPillOnSlowLoad: Boolean = false,
Expand All @@ -115,6 +121,7 @@ internal fun LazyLayout(
canScrollBackward = lazyListState.canScrollBackward,
inModal = inModal,
loading = loading,
applyImePadding = applyImePadding,
showPillOnSlowLoad = showPillOnSlowLoad,
showFooterShadowWhenScrollable = showFooterShadowWhenScrollable,
modifier = modifier,
Expand All @@ -137,6 +144,7 @@ private fun LayoutScaffold(
showPillOnSlowLoad: Boolean,
inModal: Boolean,
showFooterShadowWhenScrollable: Boolean,
applyImePadding: Boolean,
modifier: Modifier = Modifier,
footer: (@Composable () -> Unit)?,
body: @Composable () -> Unit,
Expand All @@ -148,8 +156,15 @@ private fun LayoutScaffold(
}

Column(
modifier
.also { if (inModal.not()) it.fillMaxSize() }
modifier = modifier
.conditional(
condition = inModal.not(),
ifTrue = { fillMaxSize() }
)
.conditional(
condition = applyImePadding,
ifTrue = { imePadding() }
)
) {
if (inModal) {
DragHandle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.stripe.android.common.ui
import android.os.Build
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.imePadding
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ModalBottomSheetValue.Expanded
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -56,7 +57,8 @@ internal fun ElementsBottomSheetLayout(
StripeBottomSheetLayout(
state = state,
layoutInfo = layoutInfo,
modifier = modifier,
modifier = modifier
.imePadding(),
Comment on lines +60 to +61
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hoisted imePadding a bit up so that users can customize it, and adds it for the Elements bottom sheet to keep current behavior.

onDismissed = onDismissed,
sheetContent = content,
)
Expand Down
2 changes: 1 addition & 1 deletion stripe-ui-core/api/stripe-ui-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public final class com/stripe/android/uicore/elements/TextFieldStateConstants$Va
public final class com/stripe/android/uicore/elements/TextFieldUIKt {
public static final fun AnimatedIcons (Ljava/util/List;ZLandroidx/compose/runtime/Composer;I)V
public static final fun TextField-qRf7idA (Lcom/stripe/android/uicore/elements/TextFieldController;ZILandroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;IILandroidx/compose/ui/focus/FocusRequester;Landroidx/compose/runtime/Composer;II)V
public static final fun TextFieldSection-vbMXUkU (Landroidx/compose/ui/Modifier;Lcom/stripe/android/uicore/elements/TextFieldController;IZZLjava/lang/Integer;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)V
public static final fun TextFieldSection-B9MLdtY (Landroidx/compose/ui/Modifier;Landroidx/compose/ui/focus/FocusRequester;Lcom/stripe/android/uicore/elements/TextFieldController;IZZLjava/lang/Integer;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)V
}

public final class com/stripe/android/uicore/elements/bottomsheet/ComposableSingletons$StripeBottomSheetLayoutKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private fun defaultAutofillEventReporter(): (String) -> Unit {
@Composable
fun TextFieldSection(
modifier: Modifier = Modifier,
focusRequester: FocusRequester = remember { FocusRequester() },
textFieldController: TextFieldController,
imeAction: ImeAction,
enabled: Boolean,
Expand All @@ -109,6 +110,7 @@ fun TextFieldSection(
Section(title = sectionTitle, error = sectionErrorString, isSelected = isSelected) {
TextField(
textFieldController = textFieldController,
focusRequester = focusRequester,
enabled = enabled,
imeAction = imeAction,
modifier = modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.stripe.android.uicore.elements.bottomsheet

import androidx.annotation.RestrictTo
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ModalBottomSheetLayout
Expand Down Expand Up @@ -47,8 +47,8 @@ fun StripeBottomSheetLayout(

ModalBottomSheetLayout(
modifier = modifier
.statusBarsPadding()
.imePadding(),
.navigationBarsPadding()
.statusBarsPadding(),
scrimColor = layoutInfo.scrimColor,
sheetBackgroundColor = layoutInfo.sheetBackgroundColor,
sheetElevation = 0.dp,
Expand Down
Loading