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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Custom screen options dictionary: Onboarding stack only #1079

8 changes: 4 additions & 4 deletions packages/legacy/app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -735,14 +735,14 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
anoncreds: 8e6ab626d5250ae6301c3e96d6fc739186e083f0
aries-askar: 738c677e194913ed3c256adc953db3fe0494f8f8
boost: 57d2868c099736d80fcd648bf211b4431e51a558
boost: a7c83b31436843459a1961bfd74b96033dc77234
CatCrypto: a477899b6be4954e75be4897e732da098cc0a5a8
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662
FBLazyVector: 71803c074f6325f10b5ec891c443b6bbabef0ca7
FBReactNativeSpec: 448e08a759d29a96e15725ae532445bf4343567c
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
glog: 5337263514dd6f09803962437687240c5dc39aa4
hermes-engine: f6cf92a471053245614d9d8097736f6337d5b86c
indy-vdr: 85cd66089f151256581323440e78988891f4082e
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
Expand Down Expand Up @@ -806,4 +806,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 91c24b25407631a4023c96a168470f60d473e28f

COCOAPODS: 1.13.0
COCOAPODS: 1.15.2
16 changes: 14 additions & 2 deletions packages/legacy/core/App/container-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Button } from './components/buttons/Button-api'
import { ReducerAction } from './contexts/reducers/store'
import Onboarding from './screens/Onboarding'
import { GenericFn } from './types/fn'
import { AuthenticateStackParams } from './types/navigators'
import { AuthenticateStackParams, ScreenOptionsType } from './types/navigators'

export enum SCREEN_TOKENS {
SCREEN_PREFACE = 'screen.preface',
Expand All @@ -30,7 +30,18 @@ export enum SERVICE_TOKENS {
SERVICE_TERMS = 'screen.terms',
}

export const TOKENS = { ...SCREEN_TOKENS, ...SERVICE_TOKENS, ...STACK_TOKENS, ...FN_TOKENS, ...COMP_TOKENS }
export enum OBJECT_TOKENS {
OBJECT_ONBOARDINGCONFIG = 'object.onboarding-config',
}

export const TOKENS = {
...SCREEN_TOKENS,
...SERVICE_TOKENS,
...STACK_TOKENS,
...FN_TOKENS,
...COMP_TOKENS,
...OBJECT_TOKENS,
}

export type FN_ONBOARDING_DONE = (
dispatch: React.Dispatch<ReducerAction<unknown>>,
Expand All @@ -45,6 +56,7 @@ export interface TokenMapping {
[TOKENS.SCREEN_ONBOARDING]: typeof Onboarding
[TOKENS.FN_ONBOARDING_DONE]: FN_ONBOARDING_DONE
[TOKENS.COMP_BUTTON]: Button
[TOKENS.OBJECT_ONBOARDINGCONFIG]: ScreenOptionsType
}

export interface Container {
Expand Down
2 changes: 2 additions & 0 deletions packages/legacy/core/App/container-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Button from './components/buttons/Button'
import { TOKENS, Container, TokenMapping } from './container-api'
import { DispatchAction, ReducerAction } from './contexts/reducers/store'
import OnboardingStack from './navigators/OnboardingStack'
import { DefaultScreenOptionsDictionary } from './navigators/defaultStackOptions'
import Developer from './screens/Developer'
import Onboarding from './screens/Onboarding'
import Preface from './screens/Preface'
Expand All @@ -27,6 +28,7 @@ export class MainContainer implements Container {
this.container.registerInstance(TOKENS.SCREEN_ONBOARDING, Onboarding)
this.container.registerInstance(TOKENS.STACK_ONBOARDING, OnboardingStack)
this.container.registerInstance(TOKENS.COMP_BUTTON, Button)
this.container.registerInstance(TOKENS.OBJECT_ONBOARDINGCONFIG, DefaultScreenOptionsDictionary)

this.container.registerInstance(
TOKENS.FN_ONBOARDING_DONE,
Expand Down
42 changes: 11 additions & 31 deletions packages/legacy/core/App/navigators/OnboardingStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { createCarouselStyle } from '../screens/OnboardingPages'
import PINCreate from '../screens/PINCreate'
import PushNotification from '../screens/PushNotification'
import { AuthenticateStackParams, Screens } from '../types/navigators'
import { testIdWithKey } from '../utils/testable'

import { createDefaultStackOptions } from './defaultStackOptions'

Expand Down Expand Up @@ -49,6 +48,7 @@ const OnboardingStack: React.FC = () => {
const onTutorialCompleted = container.resolve(TOKENS.FN_ONBOARDING_DONE)(dispatch, navigation)
const { screen: Terms } = container.resolve(TOKENS.SCREEN_TERMS)
const Developer = container.resolve(TOKENS.SCREEN_DEVELOPER)
const ScreenOptionsDictionary = container.resolve(TOKENS.OBJECT_ONBOARDINGCONFIG)
const Preface = container.resolve(TOKENS.SCREEN_PREFACE)

const onAuthenticated = (status: boolean): void => {
Expand Down Expand Up @@ -83,38 +83,31 @@ const OnboardingStack: React.FC = () => {
component: Preface,
options: () => {
return {
...ScreenOptionsDictionary[Screens.Preface],
title: t('Screens.Preface'),
headerTintColor: OnboardingTheme.headerTintColor,
headerShown: true,
headerLeft: () => false,
}
},
},
{
name: Screens.Splash,
component: splash,
options: ScreenOptionsDictionary[Screens.Splash],
},
{
name: Screens.Onboarding,
component: OnBoardingScreen,
options: () => {
return {
...ScreenOptionsDictionary[Screens.Onboarding],
title: t('Screens.Onboarding'),
headerTintColor: OnboardingTheme.headerTintColor,
headerShown: true,
gestureEnabled: false,
headerLeft: () => false,
}
},
},
{
name: Screens.Terms,
options: () => ({
...ScreenOptionsDictionary[Screens.Terms],
title: t('Screens.Terms'),
headerTintColor: OnboardingTheme.headerTintColor,
headerShown: true,
headerLeft: () => false,
rightLeft: () => false,
}),
component: Terms,
},
Expand All @@ -123,42 +116,31 @@ const OnboardingStack: React.FC = () => {
component: CreatePINScreen,
initialParams: {},
options: () => ({
...ScreenOptionsDictionary[Screens.CreatePIN],
title: t('Screens.CreatePIN'),
headerShown: true,
headerLeft: () => false,
rightLeft: () => false,
}),
},
{
name: Screens.NameWallet,
options: () => ({
...ScreenOptionsDictionary[Screens.CreatePIN],
title: t('Screens.NameWallet'),
headerTintColor: OnboardingTheme.headerTintColor,
headerShown: true,
headerLeft: () => false,
rightLeft: () => false,
}),
component: NameWallet,
},
{
name: Screens.UseBiometry,
options: () => ({
...ScreenOptionsDictionary[Screens.CreatePIN],
title: t('Screens.Biometry'),
headerTintColor: OnboardingTheme.headerTintColor,
headerShown: true,
headerLeft: () => false,
rightLeft: () => false,
}),
component: useBiometry,
},
{
name: Screens.UsePushNotifications,
options: () => ({
...ScreenOptionsDictionary[Screens.CreatePIN],
title: t('Screens.UsePushNotifications'),
headerTintColor: OnboardingTheme.headerTintColor,
headerShown: true,
headerLeft: () => false,
rightLeft: () => false,
}),
component: PushNotification,
},
Expand All @@ -167,18 +149,16 @@ const OnboardingStack: React.FC = () => {
component: Developer,
options: () => {
return {
...ScreenOptionsDictionary[Screens.Developer],
title: t('Screens.Developer'),
headerTintColor: OnboardingTheme.headerTintColor,
headerShown: true,
headerBackAccessibilityLabel: t('Global.Back'),
headerBackTestID: testIdWithKey('Back'),
}
},
},
]

return (
<Stack.Navigator initialRouteName={Screens.Splash} screenOptions={{ ...defaultStackOptions, headerShown: false }}>
<Stack.Navigator initialRouteName={Screens.Splash} screenOptions={{ ...defaultStackOptions }}>
{screens.map((item) => {
return <Stack.Screen key={item.name} {...item} />
})}
Expand Down
43 changes: 42 additions & 1 deletion packages/legacy/core/App/navigators/defaultStackOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,48 @@ import { useTranslation } from 'react-i18next'

import HeaderTitle from '../components/texts/HeaderTitle'
import { useConfiguration } from '../contexts/configuration'
import { ITheme } from '../theme'
import { ITheme, OnboardingTheme } from '../theme'
import { ScreenOptionsType, Screens } from '../types/navigators'
import { testIdWithKey } from '../utils/testable'

export const DefaultScreenOptionsDictionary: ScreenOptionsType = {
[Screens.Preface]: {
headerTintColor: OnboardingTheme.headerTintColor,
headerLeft: () => false,
},
[Screens.Splash]: {
headerShown: false,
},
[Screens.Onboarding]: {
headerTintColor: OnboardingTheme.headerTintColor,
gestureEnabled: false,
headerLeft: () => false,
},
[Screens.Terms]: {
headerTintColor: OnboardingTheme.headerTintColor,
headerLeft: () => false,
},
[Screens.CreatePIN]: {
headerLeft: () => false,
},
[Screens.NameWallet]: {
headerTintColor: OnboardingTheme.headerTintColor,
headerLeft: () => false,
},
[Screens.UseBiometry]: {
headerTintColor: OnboardingTheme.headerTintColor,
headerLeft: () => false,
},
[Screens.Developer]: {
headerTintColor: OnboardingTheme.headerTintColor,
headerShown: false,
MosCD3 marked this conversation as resolved.
Show resolved Hide resolved
headerBackTestID: testIdWithKey('Back'),
},
[Screens.UsePushNotifications]: {
headerTintColor: OnboardingTheme.headerTintColor,
headerLeft: () => false,
},
}

export function createDefaultStackOptions({ ColorPallet }: ITheme): StackNavigationOptions {
const { t } = useTranslation()
Expand Down
3 changes: 3 additions & 0 deletions packages/legacy/core/App/types/navigators.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CredentialExchangeRecord } from '@aries-framework/core'
import { NavigatorScreenParams } from '@react-navigation/core'
import { StackNavigationOptions } from '@react-navigation/stack'

export enum Screens {
AttemptLockout = 'Temporarily Locked',
Expand Down Expand Up @@ -164,3 +165,5 @@ export type DeliveryStackParams = {
[Screens.Declined]: { credentialId: string }
[Screens.Chat]: { connectionId: string }
}

export type ScreenOptionsType = Partial<Record<Screens, StackNavigationOptions>>
Loading