-
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suite-native): analytics consent screen redesign
- Loading branch information
Showing
8 changed files
with
202 additions
and
17 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
42 changes: 42 additions & 0 deletions
42
suite-native/module-onboarding/src/components/AnalyticsInfoRow.tsx
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,42 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
import { Icon, IconName } from '@suite-native/icons'; | ||
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles'; | ||
import { Box, HStack, Text, VStack } from '@suite-native/atoms'; | ||
|
||
type AnalyticsInfoRowProps = { | ||
iconName: IconName; | ||
title: ReactNode; | ||
description: ReactNode; | ||
}; | ||
|
||
const WRAPPER_SIZE = 36; | ||
|
||
const iconWrapper = prepareNativeStyle(utils => ({ | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
width: WRAPPER_SIZE, | ||
height: WRAPPER_SIZE, | ||
backgroundColor: utils.colors.backgroundSurfaceElevation2, | ||
borderRadius: utils.borders.radii.r12, | ||
borderWidth: 1, | ||
borderColor: utils.colors.backgroundTertiaryDefaultOnElevation0, | ||
})); | ||
|
||
export const AnalyticsInfoRow = ({ iconName, title, description }: AnalyticsInfoRowProps) => { | ||
const { applyStyle } = useNativeStyles(); | ||
|
||
return ( | ||
<HStack spacing="sp12" flexDirection="row" alignItems="center"> | ||
<Box style={applyStyle(iconWrapper)}> | ||
<Icon name={iconName} size="mediumLarge" /> | ||
</Box> | ||
<VStack spacing="sp4" flex={1}> | ||
<Text variant="highlight">{title}</Text> | ||
<Text variant="hint" color="textSubdued"> | ||
{description} | ||
</Text> | ||
</VStack> | ||
</HStack> | ||
); | ||
}; |
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
129 changes: 129 additions & 0 deletions
129
suite-native/module-onboarding/src/screens/AnalyticsConsentScreen.tsx
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,129 @@ | ||
import { useState } from 'react'; | ||
|
||
import { Screen } from '@suite-native/navigation'; | ||
import { Box, Button, Card, Switch, Text, TitleHeader, VStack } from '@suite-native/atoms'; | ||
import { Translation } from '@suite-native/intl'; | ||
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles'; | ||
import { EventType, analytics } from '@suite-native/analytics'; | ||
import { useOpenLink } from '@suite-native/link'; | ||
import { useToast } from '@suite-native/toasts'; | ||
|
||
import { AnalyticsInfoRow } from '../components/AnalyticsInfoRow'; | ||
|
||
const LEARN_MORE_LINK = 'https://data.trezor.io/legal/privacy-policy.html'; | ||
|
||
const consentWrapperStyle = prepareNativeStyle(utils => ({ | ||
padding: utils.spacings.sp16, | ||
borderRadius: utils.borders.radii.r16, | ||
backgroundColor: utils.colors.backgroundTertiaryDefaultOnElevation1, | ||
})); | ||
|
||
const reportAnalyticsOnboardingCompleted = (isTrackingAllowed: boolean) => { | ||
// For users who have not allowed tracking, enable analytics just for reporting | ||
// the OnboardingCompleted event and then disable it again. | ||
if (!isTrackingAllowed) analytics.enable(); | ||
analytics.report({ | ||
type: EventType.OnboardingCompleted, | ||
payload: { analyticsPermission: isTrackingAllowed }, | ||
}); | ||
if (!isTrackingAllowed) analytics.disable(); | ||
}; | ||
|
||
export const AnalyticsConsentScreen = () => { | ||
const { showToast } = useToast(); | ||
const [isEnabled, setIsEnabled] = useState(true); | ||
|
||
const { applyStyle } = useNativeStyles(); | ||
|
||
const handleOpenLink = useOpenLink(); | ||
|
||
const handleRedirect = () => { | ||
reportAnalyticsOnboardingCompleted(isEnabled); | ||
|
||
showToast({ variant: 'warning', message: 'TODO: implement next screen' }); | ||
// navigation.navigate(OnboardingStackRoutes.Biometrics); | ||
}; | ||
|
||
const handleAnalyticsConsent = () => { | ||
analytics.enable(); | ||
handleRedirect(); | ||
}; | ||
|
||
const handleClickOnLearMoreLink = () => { | ||
handleOpenLink(LEARN_MORE_LINK); | ||
}; | ||
|
||
return ( | ||
<Screen> | ||
<VStack justifyContent="space-between" flex={1}> | ||
<VStack spacing="sp24" paddingTop="sp32"> | ||
<TitleHeader | ||
title={<Translation id="moduleOnboarding.analyticsConsentScreen.title" />} | ||
titleVariant="titleMedium" | ||
subtitle={ | ||
<Translation id="moduleOnboarding.analyticsConsentScreen.subtitle" /> | ||
} | ||
titleSpacing="sp12" | ||
/> | ||
<Card> | ||
<Box> | ||
<VStack flex={1}> | ||
<VStack spacing="sp24" paddingBottom="sp16"> | ||
<AnalyticsInfoRow | ||
iconName="eyeSlash" | ||
title={ | ||
<Translation id="moduleOnboarding.analyticsConsentScreen.bulletPoints.privacy.title" /> | ||
} | ||
description={ | ||
<Translation id="moduleOnboarding.analyticsConsentScreen.bulletPoints.privacy.description" /> | ||
} | ||
/> | ||
<AnalyticsInfoRow | ||
iconName="bugBeetle" | ||
title={ | ||
<Translation id="moduleOnboarding.analyticsConsentScreen.bulletPoints.dataCollection.title" /> | ||
} | ||
description={ | ||
<Translation id="moduleOnboarding.analyticsConsentScreen.bulletPoints.dataCollection.description" /> | ||
} | ||
/> | ||
</VStack> | ||
<Box | ||
flexDirection="row" | ||
alignItems="center" | ||
justifyContent="space-between" | ||
style={applyStyle(consentWrapperStyle)} | ||
> | ||
<Text> | ||
<Translation id="moduleOnboarding.analyticsConsentScreen.helpSwitchTitle" /> | ||
</Text> | ||
<Switch | ||
isChecked={isEnabled} | ||
onChange={enabled => { | ||
setIsEnabled(enabled); | ||
}} | ||
/> | ||
</Box> | ||
</VStack> | ||
</Box> | ||
</Card> | ||
</VStack> | ||
<VStack spacing="sp12"> | ||
<Button | ||
testID="@onboarding/UserDataConsent/allow" | ||
onPress={isEnabled ? handleAnalyticsConsent : handleRedirect} | ||
> | ||
<Translation id="generic.buttons.confirm" /> | ||
</Button> | ||
<Button | ||
colorScheme="tertiaryElevation0" | ||
testID="@onboarding/UserDataConsent/allow" | ||
onPress={handleClickOnLearMoreLink} | ||
> | ||
<Translation id="moduleOnboarding.analyticsConsentScreen.learnMoreButton" /> | ||
</Button> | ||
</VStack> | ||
</VStack> | ||
</Screen> | ||
); | ||
}; |
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