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

This PR makes all header buttons injectable #1335

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/legacy/core/App/container-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const LOAD_STATE_TOKENS = {
} as const

export const OBJECT_TOKENS = {
OBJECT_ONBOARDING_CONFIG: 'object.onboarding-config',
OBJECT_SCREEN_CONFIG: 'object.screen-config',
} as const

export const CACHE_TOKENS = {
Expand Down Expand Up @@ -166,7 +166,7 @@ export type TokenMapping = {
customNotificationConfig?: CustomNotification
}
[TOKENS.NOTIFICATIONS_LIST_ITEM]: React.FC<NotificationListItemProps>
[TOKENS.OBJECT_ONBOARDING_CONFIG]: ScreenOptionsType
[TOKENS.OBJECT_SCREEN_CONFIG]: ScreenOptionsType
[TOKENS.COMPONENT_PIN_CREATE_HEADER]: React.FC<PINCreateHeaderProps>
[TOKENS.CACHE_CRED_DEFS]: { did: string; id: string }[]
[TOKENS.CACHE_SCHEMAS]: { did: string; id: string }[]
Expand Down
2 changes: 1 addition & 1 deletion packages/legacy/core/App/container-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class MainContainer implements Container {
this._container.registerInstance(TOKENS.GROUP_BY_REFERENT, false)
this._container.registerInstance(TOKENS.HISTORY_ENABLED, false)
this._container.registerInstance(TOKENS.CRED_HELP_ACTION_OVERRIDES, [])
this._container.registerInstance(TOKENS.OBJECT_ONBOARDING_CONFIG, DefaultScreenOptionsDictionary)
this._container.registerInstance(TOKENS.OBJECT_SCREEN_CONFIG, DefaultScreenOptionsDictionary)
this._container.registerInstance(TOKENS.UTIL_LOGGER, new ConsoleLogger())
this._container.registerInstance(TOKENS.UTIL_OCA_RESOLVER, new DefaultOCABundleResolver(bundle))
this._container.registerInstance(TOKENS.UTIL_LEDGERS, defaultIndyLedgers)
Expand Down
13 changes: 11 additions & 2 deletions packages/legacy/core/App/navigators/ConnectStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ConnectStack: React.FC = () => {
const Stack = createStackNavigator<ConnectStackParams>()
const theme = useTheme()
const defaultStackOptions = useDefaultStackOptions(theme)
const [scan] = useServices([TOKENS.SCREEN_SCAN])
const [scan, ScreenOptionsDictionary] = useServices([TOKENS.SCREEN_SCAN, TOKENS.OBJECT_SCREEN_CONFIG])
const { t } = useTranslation()

return (
Expand All @@ -32,15 +32,24 @@ const ConnectStack: React.FC = () => {
options={() => ({
title: t('PasteUrl.PasteUrl'),
headerBackTestID: testIdWithKey('Back'),
...ScreenOptionsDictionary[Screens.PasteUrl]
})}
/>
<Stack.Screen name={Screens.ScanHelp} component={ScanHelp} />
<Stack.Screen
name={Screens.ScanHelp}
component={ScanHelp}
options={{
...ScreenOptionsDictionary[Screens.ScanHelp]
}}
/>

<Stack.Screen
name={Screens.NameWallet}
component={NameWallet}
options={{
title: t('Screens.NameWallet'),
headerBackTestID: testIdWithKey('Back'),
...ScreenOptionsDictionary[Screens.NameWallet]
}}
/>
</Stack.Navigator>
Expand Down
47 changes: 40 additions & 7 deletions packages/legacy/core/App/navigators/ContactStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,85 @@ import WhatAreContacts from '../screens/WhatAreContacts'
import { ContactStackParams, Screens } from '../types/navigators'

import { useDefaultStackOptions } from './defaultStackOptions'
import { TOKENS, useServices } from '../container-api'

const ContactStack: React.FC = () => {
const Stack = createStackNavigator<ContactStackParams>()
const theme = useTheme()
const { t } = useTranslation()
const defaultStackOptions = useDefaultStackOptions(theme)
const [ScreenOptionsDictionary] = useServices([TOKENS.OBJECT_SCREEN_CONFIG])

return (
<Stack.Navigator screenOptions={{ ...defaultStackOptions }}>
<Stack.Screen name={Screens.Contacts} component={ListContacts} options={{ title: t('Screens.Contacts') }} />
<Stack.Screen
name={Screens.Contacts}
component={ListContacts}
options={{ title: t('Screens.Contacts'),
...ScreenOptionsDictionary[Screens.Contacts]
}}
/>
<Stack.Screen
name={Screens.ContactDetails}
component={ContactDetails}
options={{
title: t('Screens.ContactDetails'),
...ScreenOptionsDictionary[Screens.ContactDetails]
}}
/>
<Stack.Screen
name={Screens.RenameContact}
component={RenameContact}
options={{ title: t('Screens.RenameContact') }}
options={{
title: t('Screens.RenameContact'),
...ScreenOptionsDictionary[Screens.RenameContact]
}}
/>
<Stack.Screen
name={Screens.Chat}
component={Chat}
options={{
...ScreenOptionsDictionary[Screens.Chat]
}}
/>
<Stack.Screen
name={Screens.WhatAreContacts}
component={WhatAreContacts}
options={{
title: '',
...ScreenOptionsDictionary[Screens.WhatAreContacts]
}}
/>
<Stack.Screen name={Screens.Chat} component={Chat} />
<Stack.Screen name={Screens.WhatAreContacts} component={WhatAreContacts} options={{ title: '' }} />
<Stack.Screen
name={Screens.CredentialDetails}
component={CredentialDetails}
options={{ title: t('Screens.CredentialDetails') }}
options={{ title: t('Screens.CredentialDetails'),
...ScreenOptionsDictionary[Screens.CredentialDetails]
}}
/>
<Stack.Screen
name={Screens.CredentialOffer}
component={CredentialOffer}
options={{ title: t('Screens.CredentialOffer') }}
options={{ title: t('Screens.CredentialOffer'),
...ScreenOptionsDictionary[Screens.CredentialOffer]
}}
/>
<Stack.Screen
name={Screens.ProofDetails}
component={ProofDetails}
options={() => ({
title: '',
headerRight: () => <HeaderRightHome />,
...ScreenOptionsDictionary[Screens.ProofDetails]
})}
/>
<Stack.Screen
name={Screens.ProofRequest}
component={ProofRequest}
options={{ title: t('Screens.ProofRequest') }}
options={{
title: t('Screens.ProofRequest'),
...ScreenOptionsDictionary[Screens.ProofRequest]
}}
/>
</Stack.Navigator>
)
Expand Down
13 changes: 10 additions & 3 deletions packages/legacy/core/App/navigators/CredentialStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const CredentialStack: React.FC = () => {
const Stack = createStackNavigator<CredentialStackParams>()
const theme = useTheme()
const { t } = useTranslation()
const [CredentialListHeaderRight] = useServices([TOKENS.COMPONENT_CRED_LIST_HEADER_RIGHT])
const [CredentialListHeaderRight, ScreenOptionsDictionary] = useServices([TOKENS.COMPONENT_CRED_LIST_HEADER_RIGHT, TOKENS.OBJECT_SCREEN_CONFIG])
const defaultStackOptions = useDefaultStackOptions(theme)

return (
Expand All @@ -28,17 +28,24 @@ const CredentialStack: React.FC = () => {
title: t('Screens.Credentials'),
headerRight: () => <CredentialListHeaderRight />,
headerLeft: () => <SettingsMenu />,
...ScreenOptionsDictionary[Screens.Credentials]
})}
/>
<Stack.Screen
name={Screens.CredentialDetails}
component={CredentialDetails}
options={{ title: t('Screens.CredentialDetails') }}
options={{
title: t('Screens.CredentialDetails'),
...ScreenOptionsDictionary[Screens.CredentialDetails]
}}
/>
<Stack.Screen
name={Screens.OpenIDCredentialDetails}
component={OpenIDCredentialDetails}
options={{ title: t('Screens.CredentialDetails') }}
options={{
title: t('Screens.CredentialDetails'),
...ScreenOptionsDictionary[Screens.OpenIDCredentialDetails]
}}
/>
</Stack.Navigator>
)
Expand Down
28 changes: 23 additions & 5 deletions packages/legacy/core/App/navigators/DeliveryStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import { DeliveryStackParams, Screens } from '../types/navigators'
import { useDefaultStackOptions } from './defaultStackOptions'
import OpenIDCredentialDetails from '../modules/openid/screens/OpenIDCredentialOffer'
import OpenIDProofPresentation from '../modules/openid/screens/OpenIDProofPresentation'
import { TOKENS, useServices } from '../container-api'

const DeliveryStack: React.FC = () => {
const Stack = createStackNavigator<DeliveryStackParams>()
const { t } = useTranslation()
const theme = useTheme()
const defaultStackOptions = useDefaultStackOptions(theme)
const [ScreenOptionsDictionary] = useServices([TOKENS.OBJECT_SCREEN_CONFIG])

return (
<Stack.Navigator
Expand All @@ -29,28 +31,44 @@ const DeliveryStack: React.FC = () => {
presentation: 'modal',
headerLeft: () => null,
headerRight: () => <HeaderRightHome />,
...ScreenOptionsDictionary[Screens.Connection]
}}
>
<Stack.Screen name={Screens.Connection} component={Connection} options={{ ...defaultStackOptions }} />
<Stack.Screen
name={Screens.Connection}
component={Connection}
options={{...defaultStackOptions }} />
<Stack.Screen
name={Screens.ProofRequest}
component={ProofRequest}
options={{ title: t('Screens.ProofRequest') }}
options={{
title: t('Screens.ProofRequest'),
...ScreenOptionsDictionary[Screens.ProofRequest]
}}
/>
<Stack.Screen
name={Screens.CredentialOffer}
component={CredentialOffer}
options={{ title: t('Screens.CredentialOffer') }}
options={{
title: t('Screens.CredentialOffer'),
...ScreenOptionsDictionary[Screens.CredentialOffer]
}}
/>
<Stack.Screen
name={Screens.OpenIDCredentialDetails}
component={OpenIDCredentialDetails}
options={{ title: t('Screens.CredentialOffer') }}
options={{
title: t('Screens.CredentialOffer'),
...ScreenOptionsDictionary[Screens.OpenIDCredentialDetails]
}}
/>
<Stack.Screen
name={Screens.OpenIDProofPresentation}
component={OpenIDProofPresentation}
options={{ title: t('Screens.ProofRequest') }}
options={{
title: t('Screens.ProofRequest'),
...ScreenOptionsDictionary[Screens.OpenIDProofPresentation]
}}
/>
</Stack.Navigator>
)
Expand Down
3 changes: 3 additions & 0 deletions packages/legacy/core/App/navigators/HomeStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import Home from '../screens/Home'
import { HomeStackParams, Screens } from '../types/navigators'

import { useDefaultStackOptions } from './defaultStackOptions'
import { TOKENS, useServices } from '../container-api'

const HomeStack: React.FC = () => {
const Stack = createStackNavigator<HomeStackParams>()
const theme = useTheme()
const { t } = useTranslation()
const [store] = useStore()
const defaultStackOptions = useDefaultStackOptions(theme)
const [ScreenOptionsDictionary] = useServices([TOKENS.OBJECT_SCREEN_CONFIG])

return (
<Stack.Navigator screenOptions={{ ...defaultStackOptions }}>
Expand All @@ -27,6 +29,7 @@ const HomeStack: React.FC = () => {
title: t('Screens.Home'),
headerRight: () => (store.preferences.useHistoryCapability ? <HistoryMenu /> : null),
headerLeft: () => <SettingsMenu />,
...ScreenOptionsDictionary[Screens.Home]
})}
/>
</Stack.Navigator>
Expand Down
22 changes: 17 additions & 5 deletions packages/legacy/core/App/navigators/NotificationStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,42 @@ const NotificationStack: React.FC = () => {
const theme = useTheme()
const { t } = useTranslation()
const defaultStackOptions = useDefaultStackOptions(theme)
const [{ customNotificationConfig: customNotification }] = useServices([TOKENS.NOTIFICATIONS])
const [{ customNotificationConfig: customNotification }, ScreenOptionsDictionary] = useServices([TOKENS.NOTIFICATIONS, TOKENS.OBJECT_SCREEN_CONFIG])

return (
<Stack.Navigator screenOptions={{ ...defaultStackOptions }}>
<Stack.Screen
name={Screens.CredentialDetails}
component={CredentialDetails}
options={{ title: t('Screens.CredentialDetails') }}
options={{
title: t('Screens.CredentialDetails'),
...ScreenOptionsDictionary[Screens.CredentialDetails]
}}
/>
<Stack.Screen
name={Screens.CredentialOffer}
component={CredentialOffer}
options={{ title: t('Screens.CredentialOffer') }}
options={{
title: t('Screens.CredentialOffer'),
...ScreenOptionsDictionary[Screens.CredentialOffer]
}}
/>
<Stack.Screen
name={Screens.ProofRequest}
component={ProofRequest}
options={{ title: t('Screens.ProofRequest') }}
options={{
title: t('Screens.ProofRequest'),
...ScreenOptionsDictionary[Screens.ProofRequest]
}}
/>
{customNotification && (
<Stack.Screen
name={Screens.CustomNotification}
component={customNotification.component}
options={{ title: t(customNotification.pageTitle as any) }}
options={{
title: t(customNotification.pageTitle as any),
...ScreenOptionsDictionary[Screens.CustomNotification]
}}
/>
)}
{customNotification &&
Expand Down
2 changes: 1 addition & 1 deletion packages/legacy/core/App/navigators/OnboardingStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const OnboardingStack: React.FC = () => {
const theme = useTheme()
const OnboardingTheme = theme.OnboardingTheme
const carousel = createCarouselStyle(OnboardingTheme)
const [splash, pages, useBiometry, Onboarding, Developer, { screen: Terms }, onTutorialCompletedCurried, ScreenOptionsDictionary, Preface] = useServices([TOKENS.SCREEN_SPLASH, TOKENS.SCREEN_ONBOARDING_PAGES, TOKENS.SCREEN_USE_BIOMETRY, TOKENS.SCREEN_ONBOARDING, TOKENS.SCREEN_DEVELOPER, TOKENS.SCREEN_TERMS, TOKENS.FN_ONBOARDING_DONE, TOKENS.OBJECT_ONBOARDING_CONFIG, TOKENS.SCREEN_PREFACE])
const [splash, pages, useBiometry, Onboarding, Developer, { screen: Terms }, onTutorialCompletedCurried, ScreenOptionsDictionary, Preface] = useServices([TOKENS.SCREEN_SPLASH, TOKENS.SCREEN_ONBOARDING_PAGES, TOKENS.SCREEN_USE_BIOMETRY, TOKENS.SCREEN_ONBOARDING, TOKENS.SCREEN_DEVELOPER, TOKENS.SCREEN_TERMS, TOKENS.FN_ONBOARDING_DONE, TOKENS.OBJECT_SCREEN_CONFIG, TOKENS.SCREEN_PREFACE])
const defaultStackOptions = useDefaultStackOptions(theme)
const navigation = useNavigation<StackNavigationProp<AuthenticateStackParams>>()
const onTutorialCompleted = onTutorialCompletedCurried(dispatch, navigation)
Expand Down
Loading