mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
Bug 1821715 - Update OnboardingPageState to include button actions
This commit is contained in:
parent
9311b828c3
commit
ee642929e5
@ -37,22 +37,26 @@ fun NotificationPermissionDialogScreen(
|
||||
id = R.string.onboarding_home_enable_notifications_description,
|
||||
formatArgs = arrayOf(stringResource(R.string.app_name)),
|
||||
),
|
||||
primaryButtonText = stringResource(id = R.string.onboarding_home_enable_notifications_positive_button),
|
||||
secondaryButtonText = stringResource(id = R.string.onboarding_home_enable_notifications_negative_button),
|
||||
primaryButton = Action(
|
||||
text = stringResource(id = R.string.onboarding_home_enable_notifications_positive_button),
|
||||
onClick = {
|
||||
grantNotificationPermission()
|
||||
Onboarding.notifPppPositiveBtnClick.record(NoExtras())
|
||||
},
|
||||
),
|
||||
secondaryButton = Action(
|
||||
text = stringResource(id = R.string.onboarding_home_enable_notifications_negative_button),
|
||||
onClick = {
|
||||
onDismiss()
|
||||
Onboarding.notifPppNegativeBtnClick.record(NoExtras())
|
||||
},
|
||||
),
|
||||
onRecordImpressionEvent = { Onboarding.notifPppImpression.record(NoExtras()) },
|
||||
),
|
||||
onDismiss = {
|
||||
onDismiss()
|
||||
Onboarding.notifPppCloseClick.record(NoExtras())
|
||||
},
|
||||
onPrimaryButtonClick = {
|
||||
grantNotificationPermission()
|
||||
Onboarding.notifPppPositiveBtnClick.record(NoExtras())
|
||||
},
|
||||
onSecondaryButtonClick = {
|
||||
onDismiss()
|
||||
Onboarding.notifPppNegativeBtnClick.record(NoExtras())
|
||||
},
|
||||
modifier = Modifier
|
||||
.statusBarsPadding()
|
||||
.navigationBarsPadding(),
|
||||
|
@ -43,22 +43,18 @@ private const val IMAGE_HEIGHT_RATIO = 0.4f
|
||||
*
|
||||
* @param pageState [OnboardingPageState] The page content that's displayed.
|
||||
* @param onDismiss Invoked when the user clicks the close button.
|
||||
* @param onPrimaryButtonClick Invoked when the user clicks the primary button.
|
||||
* @param onSecondaryButtonClick Invoked when the user clicks the secondary button.
|
||||
* @param modifier The modifier to be applied to the Composable.
|
||||
*/
|
||||
@Composable
|
||||
fun OnboardingPage(
|
||||
pageState: OnboardingPageState,
|
||||
onDismiss: () -> Unit,
|
||||
onPrimaryButtonClick: () -> Unit,
|
||||
onSecondaryButtonClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
BoxWithConstraints(
|
||||
modifier = Modifier
|
||||
.background(FirefoxTheme.colors.layer1)
|
||||
.padding(bottom = if (pageState.secondaryButtonText == null) 32.dp else 24.dp)
|
||||
.padding(bottom = if (pageState.secondaryButton == null) 32.dp else 24.dp)
|
||||
.then(modifier),
|
||||
) {
|
||||
val boxWithConstraintsScope = this
|
||||
@ -115,15 +111,15 @@ fun OnboardingPage(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
) {
|
||||
PrimaryButton(
|
||||
text = pageState.primaryButtonText,
|
||||
onClick = onPrimaryButtonClick,
|
||||
text = pageState.primaryButton.text,
|
||||
onClick = pageState.primaryButton.onClick,
|
||||
)
|
||||
|
||||
if (pageState.secondaryButtonText != null) {
|
||||
if (pageState.secondaryButton != null) {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
SecondaryButton(
|
||||
text = pageState.secondaryButtonText,
|
||||
onClick = onSecondaryButtonClick,
|
||||
text = pageState.secondaryButton.text,
|
||||
onClick = pageState.secondaryButton.onClick,
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -150,16 +146,18 @@ private fun OnboardingPagePreview() {
|
||||
id = R.string.onboarding_home_enable_notifications_description,
|
||||
formatArgs = arrayOf(stringResource(R.string.app_name)),
|
||||
),
|
||||
primaryButtonText = stringResource(
|
||||
id = R.string.onboarding_home_enable_notifications_positive_button,
|
||||
primaryButton = Action(
|
||||
text = stringResource(
|
||||
id = R.string.onboarding_home_enable_notifications_positive_button,
|
||||
),
|
||||
onClick = {},
|
||||
),
|
||||
secondaryButtonText = stringResource(
|
||||
id = R.string.onboarding_home_enable_notifications_negative_button,
|
||||
secondaryButton = Action(
|
||||
text = stringResource(id = R.string.onboarding_home_enable_notifications_negative_button),
|
||||
onClick = {},
|
||||
),
|
||||
onRecordImpressionEvent = {},
|
||||
),
|
||||
onPrimaryButtonClick = {},
|
||||
onSecondaryButtonClick = {},
|
||||
onDismiss = {},
|
||||
)
|
||||
}
|
||||
|
@ -12,15 +12,23 @@ import androidx.annotation.DrawableRes
|
||||
* @param image [DrawableRes] displayed on the page.
|
||||
* @param title [String] title of the page.
|
||||
* @param description [String] description of the page.
|
||||
* @param primaryButtonText [String] text for the primary button.
|
||||
* @param secondaryButtonText [String] text for the secondary button.
|
||||
* @param primaryButton [Action] action for the primary button.
|
||||
* @param secondaryButton [Action] action for the secondary button.
|
||||
* @param onRecordImpressionEvent Callback for recording impression event.
|
||||
*/
|
||||
data class OnboardingPageState(
|
||||
@DrawableRes val image: Int,
|
||||
val title: String,
|
||||
val description: String,
|
||||
val primaryButtonText: String,
|
||||
val secondaryButtonText: String? = null,
|
||||
val primaryButton: Action,
|
||||
val secondaryButton: Action? = null,
|
||||
val onRecordImpressionEvent: () -> Unit,
|
||||
)
|
||||
|
||||
/**
|
||||
* Model containing text and action for a button.
|
||||
*/
|
||||
data class Action(
|
||||
val text: String,
|
||||
val onClick: () -> Unit,
|
||||
)
|
||||
|
@ -91,7 +91,17 @@ private fun UpgradeOnboardingContent(
|
||||
image = R.drawable.ic_onboarding_welcome,
|
||||
title = stringResource(id = R.string.onboarding_home_welcome_title_2),
|
||||
description = stringResource(id = R.string.onboarding_home_welcome_description),
|
||||
primaryButtonText = stringResource(id = R.string.onboarding_home_get_started_button),
|
||||
primaryButton = Action(
|
||||
text = stringResource(id = R.string.onboarding_home_get_started_button),
|
||||
onClick = {
|
||||
OnboardingMetrics.welcomeGetStartedClicked.record(NoExtras())
|
||||
if (isSyncSignIn) {
|
||||
onDismiss()
|
||||
} else {
|
||||
onboardingState = UpgradeOnboardingState.SyncSignIn
|
||||
}
|
||||
},
|
||||
),
|
||||
onRecordImpressionEvent = {
|
||||
OnboardingMetrics.welcomeCardImpression.record(NoExtras())
|
||||
},
|
||||
@ -100,8 +110,20 @@ private fun UpgradeOnboardingContent(
|
||||
image = R.drawable.ic_onboarding_sync,
|
||||
title = stringResource(id = R.string.onboarding_home_sync_title_3),
|
||||
description = stringResource(id = R.string.onboarding_home_sync_description),
|
||||
primaryButtonText = stringResource(id = R.string.onboarding_home_sign_in_button),
|
||||
secondaryButtonText = stringResource(id = R.string.onboarding_home_skip_button),
|
||||
primaryButton = Action(
|
||||
text = stringResource(id = R.string.onboarding_home_sign_in_button),
|
||||
onClick = {
|
||||
OnboardingMetrics.syncSignInClicked.record(NoExtras())
|
||||
onSignInButtonClick()
|
||||
},
|
||||
),
|
||||
secondaryButton = Action(
|
||||
text = stringResource(id = R.string.onboarding_home_skip_button),
|
||||
onClick = {
|
||||
OnboardingMetrics.syncSkipClicked.record(NoExtras())
|
||||
onDismiss()
|
||||
},
|
||||
),
|
||||
onRecordImpressionEvent = {
|
||||
OnboardingMetrics.syncCardImpression.record(NoExtras())
|
||||
},
|
||||
@ -114,33 +136,6 @@ private fun UpgradeOnboardingContent(
|
||||
}
|
||||
onDismiss()
|
||||
},
|
||||
onPrimaryButtonClick = {
|
||||
when (onboardingState) {
|
||||
UpgradeOnboardingState.Welcome -> {
|
||||
OnboardingMetrics.welcomeGetStartedClicked.record(NoExtras())
|
||||
if (isSyncSignIn) {
|
||||
onDismiss()
|
||||
} else {
|
||||
onboardingState = UpgradeOnboardingState.SyncSignIn
|
||||
}
|
||||
}
|
||||
UpgradeOnboardingState.SyncSignIn -> {
|
||||
OnboardingMetrics.syncSignInClicked.record(NoExtras())
|
||||
onSignInButtonClick()
|
||||
}
|
||||
}
|
||||
},
|
||||
onSecondaryButtonClick = {
|
||||
when (onboardingState) {
|
||||
UpgradeOnboardingState.Welcome -> {
|
||||
// Welcome does not have a secondary button.
|
||||
}
|
||||
UpgradeOnboardingState.SyncSignIn -> {
|
||||
OnboardingMetrics.syncSkipClicked.record(NoExtras())
|
||||
onDismiss()
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user