-
Notifications
You must be signed in to change notification settings - Fork 663
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a25a089
commit bf11f9a
Showing
13 changed files
with
234 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ import com.stripe.android.ui.core.R as StripeUiCoreR | |
internal fun LinkAppBar( | ||
state: LinkAppBarState, | ||
onBackPressed: () -> Unit, | ||
onLogout: () -> Unit, | ||
showBottomSheetContent: (BottomSheetContent?) -> Unit | ||
) { | ||
Row( | ||
|
@@ -65,6 +66,7 @@ internal fun LinkAppBar( | |
|
||
LinkAppBarAction( | ||
showOverflowMenu = state.showOverflowMenu, | ||
onLogout = onLogout, | ||
showBottomSheetContent = showBottomSheetContent | ||
) | ||
} | ||
|
@@ -113,6 +115,7 @@ private fun RowScope.LinkAppBarTitle( | |
@Composable | ||
private fun LinkAppBarAction( | ||
showOverflowMenu: Boolean, | ||
onLogout: () -> Unit, | ||
showBottomSheetContent: (BottomSheetContent?) -> Unit | ||
) { | ||
val overflowIconAlpha by animateFloatAsState( | ||
|
@@ -122,7 +125,17 @@ private fun LinkAppBarAction( | |
|
||
IconButton( | ||
onClick = { | ||
showBottomSheetContent {} | ||
showBottomSheetContent { | ||
LinkLogoutSheet( | ||
onLogoutClick = { | ||
showBottomSheetContent(null) | ||
onLogout() | ||
}, | ||
onCancelClick = { | ||
showBottomSheetContent(null) | ||
} | ||
) | ||
} | ||
}, | ||
enabled = showOverflowMenu, | ||
modifier = Modifier | ||
|
@@ -150,6 +163,7 @@ private fun LinkAppBarPreview() { | |
email = "[email protected]", | ||
), | ||
onBackPressed = {}, | ||
onLogout = {}, | ||
showBottomSheetContent = {} | ||
) | ||
} | ||
|
@@ -169,6 +183,7 @@ private fun LinkAppBarNoEmail() { | |
email = null, | ||
), | ||
onBackPressed = {}, | ||
onLogout = {}, | ||
showBottomSheetContent = {} | ||
) | ||
} | ||
|
@@ -188,6 +203,7 @@ private fun LinkAppBarChildScreen() { | |
email = "[email protected]", | ||
), | ||
onBackPressed = {}, | ||
onLogout = {}, | ||
showBottomSheetContent = {} | ||
) | ||
} | ||
|
@@ -207,6 +223,7 @@ private fun LinkAppBarChildScreenNoEmail() { | |
email = null, | ||
), | ||
onBackPressed = {}, | ||
onLogout = {}, | ||
showBottomSheetContent = {} | ||
) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
paymentsheet/src/main/java/com/stripe/android/link/ui/LinkLogoutSheet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.stripe.android.link.ui | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.stripe.android.link.ui.menus.LinkMenu | ||
import com.stripe.android.link.ui.menus.LinkMenuItem | ||
import com.stripe.android.paymentsheet.R | ||
import com.stripe.android.R as StripeR | ||
|
||
internal sealed class LinkLogoutMenuItem( | ||
override val textResId: Int, | ||
override val isDestructive: Boolean = false | ||
) : LinkMenuItem { | ||
data object Logout : LinkLogoutMenuItem(textResId = R.string.stripe_log_out, isDestructive = true) | ||
data object Cancel : LinkLogoutMenuItem(textResId = StripeR.string.stripe_cancel) | ||
} | ||
|
||
@Composable | ||
internal fun LinkLogoutSheet( | ||
onLogoutClick: () -> Unit, | ||
onCancelClick: () -> Unit | ||
) { | ||
val items = listOf( | ||
LinkLogoutMenuItem.Logout, | ||
LinkLogoutMenuItem.Cancel | ||
) | ||
|
||
LinkMenu( | ||
items = items, | ||
onItemPress = { item -> | ||
when (item) { | ||
LinkLogoutMenuItem.Logout -> onLogoutClick() | ||
LinkLogoutMenuItem.Cancel -> onCancelClick() | ||
} | ||
} | ||
) | ||
} |
80 changes: 80 additions & 0 deletions
80
paymentsheet/src/main/java/com/stripe/android/link/ui/menus/LinkMenu.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.stripe.android.link.ui.menus | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import com.stripe.android.link.theme.HorizontalPadding | ||
import com.stripe.android.link.theme.MinimumTouchTargetSize | ||
import com.stripe.android.link.theme.linkColors | ||
|
||
/** | ||
* An item to be displayed in a [LinkMenu]. | ||
* | ||
* @property textResId The resource ID of the text of the item | ||
* @property isDestructive Whether this item should be rendered with the error text color | ||
*/ | ||
internal interface LinkMenuItem { | ||
val textResId: Int | ||
val isDestructive: Boolean | ||
} | ||
|
||
/** | ||
* Displays a generic bottom sheet with the provided [items]. | ||
* | ||
* @param items The list of items that implement [LinkMenuItem] | ||
* @param onItemPress Called when an item in the list is pressed | ||
*/ | ||
@Composable | ||
internal fun <T : LinkMenuItem> LinkMenu( | ||
items: List<T>, | ||
onItemPress: (T) -> Unit | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(vertical = 10.dp) | ||
) { | ||
for (item in items) { | ||
LinkBottomSheetRow( | ||
item = item, | ||
modifier = Modifier.clickable { | ||
onItemPress(item) | ||
} | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun <T : LinkMenuItem> LinkBottomSheetRow( | ||
item: T, | ||
modifier: Modifier = Modifier | ||
) { | ||
Row( | ||
verticalAlignment = Alignment.CenterVertically, | ||
modifier = modifier | ||
.height(MinimumTouchTargetSize) | ||
.fillMaxWidth() | ||
) { | ||
Text( | ||
text = stringResource(item.textResId), | ||
color = if (item.isDestructive) { | ||
MaterialTheme.linkColors.errorText | ||
} else { | ||
Color.Unspecified | ||
}, | ||
modifier = Modifier.padding(horizontal = HorizontalPadding) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
paymentsheet/src/test/java/com/stripe/android/link/ui/LinkLogoutSheetScreenshotTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.stripe.android.link.ui | ||
|
||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import com.stripe.android.screenshottesting.FontSize | ||
import com.stripe.android.screenshottesting.Locale | ||
import com.stripe.android.screenshottesting.PaparazziRule | ||
import com.stripe.android.screenshottesting.SystemAppearance | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
internal class LinkLogoutSheetScreenshotTest { | ||
@get:Rule | ||
val paparazziRule = PaparazziRule( | ||
SystemAppearance.entries, | ||
FontSize.entries, | ||
boxModifier = Modifier | ||
.padding(0.dp) | ||
.fillMaxWidth(), | ||
) | ||
|
||
@get:Rule | ||
val localesPaparazziRule = PaparazziRule( | ||
SystemAppearance.entries, | ||
FontSize.entries, | ||
Locale.entries, | ||
boxModifier = Modifier | ||
.padding(0.dp) | ||
.fillMaxWidth(), | ||
) | ||
|
||
@Test | ||
fun testSheet() { | ||
paparazziRule.snapshot { | ||
LinkLogoutSheet( | ||
onCancelClick = {}, | ||
onLogoutClick = {} | ||
) | ||
} | ||
} | ||
} |
Binary file added
BIN
+8.53 KB
...roid.link.ui_LinkLogoutSheetScreenshotTest_testSheet[DarkTheme,DefaultFont].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.1 KB
...ndroid.link.ui_LinkLogoutSheetScreenshotTest_testSheet[DarkTheme,LargeFont].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.76 KB
...oid.link.ui_LinkLogoutSheetScreenshotTest_testSheet[LightTheme,DefaultFont].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.3 KB
...droid.link.ui_LinkLogoutSheetScreenshotTest_testSheet[LightTheme,LargeFont].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.