feat(app): React Navigation shell and i18next setup
- React Navigation 7: conditional root stack (Auth | Main | Repository | Settings | Accounts modal), 5 bottom tabs with nested native stacks - typed param lists, deep-link config, header options, root-nav helper - providers: gesture handler, safe area, theme, persisted query client, app lock - i18next + expo-localization (en/nl), persisted language preference
This commit is contained in:
1 parent
08229fdf86
commit
ad81db07b3
17 files changed
+1500
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { AccountsScreen } from '@/features/accounts/screens/accounts-screen';
|
||||
import { AddAccountScreen } from '@/features/accounts/screens/add-account-screen';
|
||||
import { useStackScreenOptions } from '@/navigation/header-options';
|
||||
import type { AccountsStackParamList } from '@/navigation/types';
|
||||
|
||||
const Stack = createNativeStackNavigator<AccountsStackParamList>();
|
||||
|
||||
export function AccountsNavigator() {
|
||||
const { t } = useTranslation();
|
||||
const screenOptions = useStackScreenOptions();
|
||||
|
||||
return (
|
||||
<Stack.Navigator screenOptions={screenOptions}>
|
||||
<Stack.Screen
|
||||
name="Accounts"
|
||||
component={AccountsScreen}
|
||||
options={{ title: t('accounts.title') }}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="AddAccount"
|
||||
component={AddAccountScreen}
|
||||
options={{ title: t('accounts.addAccount') }}
|
||||
/>
|
||||
</Stack.Navigator>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { ConnectScreen } from '@/features/auth/screens/connect-screen';
|
||||
import { WelcomeScreen } from '@/features/auth/screens/welcome-screen';
|
||||
import { useStackScreenOptions } from '@/navigation/header-options';
|
||||
import type { AuthStackParamList } from '@/navigation/types';
|
||||
|
||||
const Stack = createNativeStackNavigator<AuthStackParamList>();
|
||||
|
||||
export function AuthNavigator() {
|
||||
const { t } = useTranslation();
|
||||
const screenOptions = useStackScreenOptions();
|
||||
|
||||
return (
|
||||
<Stack.Navigator screenOptions={screenOptions}>
|
||||
<Stack.Screen name="Welcome" component={WelcomeScreen} options={{ headerShown: false }} />
|
||||
<Stack.Screen
|
||||
name="Connect"
|
||||
component={ConnectScreen}
|
||||
options={{ title: t('auth.connect.title') }}
|
||||
/>
|
||||
</Stack.Navigator>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Shared native-stack screen options derived from the active theme, so every
|
||||
* stack (tabs, repository, settings, accounts) renders identical headers.
|
||||
*/
|
||||
|
||||
import { useMemo } from 'react';
|
||||
import type { NativeStackNavigationOptions } from '@react-navigation/native-stack';
|
||||
|
||||
import { useTheme } from '@/theme/theme-provider';
|
||||
|
||||
export function useStackScreenOptions(): NativeStackNavigationOptions {
|
||||
const { colors } = useTheme();
|
||||
return useMemo(
|
||||
() => ({
|
||||
headerStyle: { backgroundColor: colors.surface },
|
||||
headerTintColor: colors.text,
|
||||
headerTitleStyle: { color: colors.text },
|
||||
headerShadowVisible: false,
|
||||
headerBackButtonDisplayMode: 'minimal',
|
||||
contentStyle: { backgroundColor: colors.background },
|
||||
}),
|
||||
[colors],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Deep linking config.
|
||||
*
|
||||
* Custom scheme: `giteanative://…` (see app.json).
|
||||
* Universal links are intentionally not claimed — the app is unofficial and
|
||||
* has no associated-domains entitlement configured.
|
||||
*/
|
||||
|
||||
import * as Linking from 'expo-linking';
|
||||
|
||||
import type { LinkingOptions } from '@react-navigation/native';
|
||||
|
||||
import type { RootStackParamList } from './types';
|
||||
|
||||
const prefixes = [Linking.createURL('/')];
|
||||
|
||||
export const linking: LinkingOptions<RootStackParamList> = {
|
||||
prefixes,
|
||||
config: {
|
||||
screens: {
|
||||
Auth: {
|
||||
screens: {
|
||||
Welcome: 'welcome',
|
||||
Connect: 'connect',
|
||||
},
|
||||
},
|
||||
Main: {
|
||||
screens: {
|
||||
HomeTab: {
|
||||
screens: { Home: 'home' },
|
||||
},
|
||||
RepositoriesTab: {
|
||||
screens: { RepositoryList: 'repositories' },
|
||||
},
|
||||
IssuesTab: {
|
||||
screens: { Issues: 'issues' },
|
||||
},
|
||||
PullsTab: {
|
||||
screens: { PullRequests: 'pull-requests' },
|
||||
},
|
||||
InboxTab: {
|
||||
screens: { Inbox: 'inbox' },
|
||||
},
|
||||
},
|
||||
},
|
||||
Repository: {
|
||||
screens: {
|
||||
RepoOverview: 'repo/:owner/:name',
|
||||
Files: 'repo/:owner/:name/tree/:path',
|
||||
FileViewer: 'repo/:owner/:name/blob/:path',
|
||||
Commits: 'repo/:owner/:name/commits',
|
||||
CommitDetail: 'repo/:owner/:name/commit/:sha',
|
||||
Branches: 'repo/:owner/:name/branches',
|
||||
Tags: 'repo/:owner/:name/tags',
|
||||
RepoIssues: 'repo/:owner/:name/issues',
|
||||
IssueDetail: 'repo/:owner/:name/issue/:index',
|
||||
RepoPulls: 'repo/:owner/:name/pulls',
|
||||
PullDetail: 'repo/:owner/:name/pull/:index',
|
||||
},
|
||||
},
|
||||
Settings: {
|
||||
screens: { Settings: 'settings' },
|
||||
},
|
||||
Accounts: {
|
||||
screens: { Accounts: 'accounts', AddAccount: 'accounts/add' },
|
||||
},
|
||||
},
|
||||
},
|
||||
// getInitialURL / subscribe default to React Native's Linking, which is what
|
||||
// we want; Expo's `Linking.createURL` above covers Expo Go/scheme handling.
|
||||
};
|
||||
@@ -0,0 +1,82 @@
|
||||
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Icon, type IconName } from '@/components/ui/icon';
|
||||
import { useUnreadCount } from '@/features/notifications/queries';
|
||||
import { useSettingsStore } from '@/features/settings/settings-store';
|
||||
import { useTheme } from '@/theme/theme-provider';
|
||||
import {
|
||||
HomeStackNavigator,
|
||||
InboxStackNavigator,
|
||||
IssuesStackNavigator,
|
||||
PullsStackNavigator,
|
||||
RepositoriesStackNavigator,
|
||||
} from '@/navigation/tab-stacks';
|
||||
import type { MainTabParamList } from '@/navigation/types';
|
||||
|
||||
const Tab = createBottomTabNavigator<MainTabParamList>();
|
||||
|
||||
const TAB_ICONS: Record<keyof MainTabParamList, IconName> = {
|
||||
HomeTab: 'home',
|
||||
RepositoriesTab: 'repo',
|
||||
IssuesTab: 'issue',
|
||||
PullsTab: 'pullRequest',
|
||||
InboxTab: 'inbox',
|
||||
};
|
||||
|
||||
/** The five-tab shell. Headers live in the inner stacks, so they are hidden here. */
|
||||
export function MainTabs() {
|
||||
const { t } = useTranslation();
|
||||
const { colors } = useTheme();
|
||||
const pollSeconds = useSettingsStore((s) => s.notificationPollSeconds);
|
||||
const unread = useUnreadCount(pollSeconds);
|
||||
const unreadCount = unread.data?.count ?? 0;
|
||||
|
||||
return (
|
||||
<Tab.Navigator
|
||||
screenOptions={({ route }) => ({
|
||||
headerShown: false,
|
||||
tabBarActiveTintColor: colors.primary,
|
||||
tabBarInactiveTintColor: colors.textTertiary,
|
||||
tabBarStyle: {
|
||||
backgroundColor: colors.surface,
|
||||
borderTopColor: colors.border,
|
||||
},
|
||||
tabBarLabelStyle: { fontSize: 11 },
|
||||
tabBarIcon: ({ color, size }) => (
|
||||
<Icon name={TAB_ICONS[route.name]} size={size} color={color} />
|
||||
),
|
||||
})}
|
||||
>
|
||||
<Tab.Screen
|
||||
name="HomeTab"
|
||||
component={HomeStackNavigator}
|
||||
options={{ title: t('tabs.home') }}
|
||||
/>
|
||||
<Tab.Screen
|
||||
name="RepositoriesTab"
|
||||
component={RepositoriesStackNavigator}
|
||||
options={{ title: t('tabs.repositories') }}
|
||||
/>
|
||||
<Tab.Screen
|
||||
name="IssuesTab"
|
||||
component={IssuesStackNavigator}
|
||||
options={{ title: t('tabs.issues') }}
|
||||
/>
|
||||
<Tab.Screen
|
||||
name="PullsTab"
|
||||
component={PullsStackNavigator}
|
||||
options={{ title: t('tabs.pullRequests') }}
|
||||
/>
|
||||
<Tab.Screen
|
||||
name="InboxTab"
|
||||
component={InboxStackNavigator}
|
||||
options={{
|
||||
title: t('tabs.inbox'),
|
||||
tabBarBadge: unreadCount > 0 ? unreadCount : undefined,
|
||||
tabBarBadgeStyle: { backgroundColor: colors.error, color: '#FFFFFF' },
|
||||
}}
|
||||
/>
|
||||
</Tab.Navigator>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* Repository stack: pushed on top of the tab shell from anywhere a repository
|
||||
* is opened (search, home, inbox, deep links).
|
||||
*/
|
||||
|
||||
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { HeaderAccountAndSettings } from '@/components/layout/header-buttons';
|
||||
import { BranchesScreen } from '@/features/repository/screens/branches-screen';
|
||||
import { CommitDetailScreen } from '@/features/repository/screens/commit-detail-screen';
|
||||
import { CommitsScreen } from '@/features/repository/screens/commits-screen';
|
||||
import { FileViewerScreen } from '@/features/repository/screens/file-viewer-screen';
|
||||
import { FilesScreen } from '@/features/repository/screens/files-screen';
|
||||
import { IssueDetailScreen } from '@/features/repository/screens/issue-detail-screen';
|
||||
import { PullDetailScreen } from '@/features/repository/screens/pull-detail-screen';
|
||||
import { RepoIssuesScreen } from '@/features/repository/screens/repo-issues-screen';
|
||||
import { RepoOverviewScreen } from '@/features/repository/screens/repo-overview-screen';
|
||||
import { RepoPullsScreen } from '@/features/repository/screens/repo-pulls-screen';
|
||||
import { TagsScreen } from '@/features/repository/screens/tags-screen';
|
||||
import { shortSha } from '@/core/utils/format';
|
||||
import { useStackScreenOptions } from '@/navigation/header-options';
|
||||
import type { RepositoryStackParamList } from '@/navigation/types';
|
||||
|
||||
const Stack = createNativeStackNavigator<RepositoryStackParamList>();
|
||||
|
||||
function lastSegment(path: string | undefined, fallback: string): string {
|
||||
if (!path) return fallback;
|
||||
const segments = path.split('/').filter(Boolean);
|
||||
return segments[segments.length - 1] ?? fallback;
|
||||
}
|
||||
|
||||
export function RepositoryNavigator() {
|
||||
const { t } = useTranslation();
|
||||
const base = useStackScreenOptions();
|
||||
|
||||
return (
|
||||
<Stack.Navigator
|
||||
screenOptions={{ ...base, headerRight: () => <HeaderAccountAndSettings /> }}
|
||||
>
|
||||
<Stack.Screen
|
||||
name="RepoOverview"
|
||||
component={RepoOverviewScreen}
|
||||
options={({ route }) => ({ title: `${route.params.owner}/${route.params.name}` })}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="Files"
|
||||
component={FilesScreen}
|
||||
options={({ route }) => ({
|
||||
title: lastSegment(route.params.path, t('repo.files')),
|
||||
})}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="FileViewer"
|
||||
component={FileViewerScreen}
|
||||
options={({ route }) => ({
|
||||
title: lastSegment(route.params.path, t('files.title')),
|
||||
})}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="Commits"
|
||||
component={CommitsScreen}
|
||||
options={{ title: t('repo.commits') }}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="CommitDetail"
|
||||
component={CommitDetailScreen}
|
||||
options={({ route }) => ({ title: shortSha(route.params.sha) })}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="Branches"
|
||||
component={BranchesScreen}
|
||||
options={{ title: t('repo.branches') }}
|
||||
/>
|
||||
<Stack.Screen name="Tags" component={TagsScreen} options={{ title: t('repo.tags') }} />
|
||||
<Stack.Screen
|
||||
name="RepoIssues"
|
||||
component={RepoIssuesScreen}
|
||||
options={{ title: t('repo.issuesTab') }}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="IssueDetail"
|
||||
component={IssueDetailScreen}
|
||||
options={({ route }) => ({ title: `#${route.params.index}` })}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="RepoPulls"
|
||||
component={RepoPullsScreen}
|
||||
options={{ title: t('repo.pullsTab') }}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="PullDetail"
|
||||
component={PullDetailScreen}
|
||||
options={({ route }) => ({ title: `#${route.params.index}` })}
|
||||
/>
|
||||
</Stack.Navigator>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Root navigator.
|
||||
*
|
||||
* Renders either the auth flow (no signed-in account) or the main app. The
|
||||
* switch is driven entirely by session state, so connecting/disconnecting an
|
||||
* account transitions the UI without imperative navigation.
|
||||
*/
|
||||
|
||||
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
||||
|
||||
import { useSession } from '@/features/accounts/use-session';
|
||||
import { AccountsNavigator } from '@/navigation/accounts-navigator';
|
||||
import { AuthNavigator } from '@/navigation/auth-navigator';
|
||||
import { MainTabs } from '@/navigation/main-tabs';
|
||||
import { RepositoryNavigator } from '@/navigation/repository-navigator';
|
||||
import { SettingsNavigator } from '@/navigation/settings-navigator';
|
||||
import type { RootStackParamList } from '@/navigation/types';
|
||||
|
||||
const Stack = createNativeStackNavigator<RootStackParamList>();
|
||||
|
||||
export function RootNavigator() {
|
||||
const { hasAccounts, token } = useSession();
|
||||
const signedIn = hasAccounts && Boolean(token);
|
||||
|
||||
return (
|
||||
<Stack.Navigator screenOptions={{ headerShown: false }}>
|
||||
{signedIn ? (
|
||||
<>
|
||||
<Stack.Screen name="Main" component={MainTabs} />
|
||||
<Stack.Screen name="Repository" component={RepositoryNavigator} />
|
||||
<Stack.Screen name="Settings" component={SettingsNavigator} />
|
||||
<Stack.Screen
|
||||
name="Accounts"
|
||||
component={AccountsNavigator}
|
||||
options={{ presentation: 'modal' }}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<Stack.Screen name="Auth" component={AuthNavigator} />
|
||||
)}
|
||||
</Stack.Navigator>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { SettingsScreen } from '@/features/settings/screens/settings-screen';
|
||||
import { useStackScreenOptions } from '@/navigation/header-options';
|
||||
import type { SettingsStackParamList } from '@/navigation/types';
|
||||
|
||||
const Stack = createNativeStackNavigator<SettingsStackParamList>();
|
||||
|
||||
export function SettingsNavigator() {
|
||||
const { t } = useTranslation();
|
||||
const screenOptions = useStackScreenOptions();
|
||||
|
||||
return (
|
||||
<Stack.Navigator screenOptions={screenOptions}>
|
||||
<Stack.Screen
|
||||
name="Settings"
|
||||
component={SettingsScreen}
|
||||
options={{ title: t('settings.title') }}
|
||||
/>
|
||||
</Stack.Navigator>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* The native stack behind each bottom tab. Keeping a stack per tab gives every
|
||||
* tab its own header (title + account/settings actions) while sharing the
|
||||
* tab bar (which hides the redundant outer header).
|
||||
*/
|
||||
|
||||
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { HeaderAccountAndSettings } from '@/components/layout/header-buttons';
|
||||
import { HomeScreen } from '@/features/home/screens/home-screen';
|
||||
import { InboxScreen } from '@/features/inbox/screens/inbox-screen';
|
||||
import { IssuesScreen } from '@/features/issues/screens/issues-screen';
|
||||
import { PullRequestsScreen } from '@/features/pulls/screens/pull-requests-screen';
|
||||
import { RepositoryListScreen } from '@/features/repositories/screens/repository-list-screen';
|
||||
import { useStackScreenOptions } from '@/navigation/header-options';
|
||||
import type {
|
||||
HomeStackParamList,
|
||||
InboxStackParamList,
|
||||
IssuesStackParamList,
|
||||
PullsStackParamList,
|
||||
RepositoriesStackParamList,
|
||||
} from '@/navigation/types';
|
||||
|
||||
function useTabHeader() {
|
||||
const screenOptions = useStackScreenOptions();
|
||||
return {
|
||||
...screenOptions,
|
||||
headerRight: () => <HeaderAccountAndSettings />,
|
||||
};
|
||||
}
|
||||
|
||||
const HomeStack = createNativeStackNavigator<HomeStackParamList>();
|
||||
export function HomeStackNavigator() {
|
||||
const { t } = useTranslation();
|
||||
const options = useTabHeader();
|
||||
return (
|
||||
<HomeStack.Navigator screenOptions={options}>
|
||||
<HomeStack.Screen name="Home" component={HomeScreen} options={{ title: t('tabs.home') }} />
|
||||
</HomeStack.Navigator>
|
||||
);
|
||||
}
|
||||
|
||||
const RepositoriesStack = createNativeStackNavigator<RepositoriesStackParamList>();
|
||||
export function RepositoriesStackNavigator() {
|
||||
const { t } = useTranslation();
|
||||
const options = useTabHeader();
|
||||
return (
|
||||
<RepositoriesStack.Navigator screenOptions={options}>
|
||||
<RepositoriesStack.Screen
|
||||
name="RepositoryList"
|
||||
component={RepositoryListScreen}
|
||||
options={{ title: t('tabs.repositories') }}
|
||||
/>
|
||||
</RepositoriesStack.Navigator>
|
||||
);
|
||||
}
|
||||
|
||||
const IssuesStack = createNativeStackNavigator<IssuesStackParamList>();
|
||||
export function IssuesStackNavigator() {
|
||||
const { t } = useTranslation();
|
||||
const options = useTabHeader();
|
||||
return (
|
||||
<IssuesStack.Navigator screenOptions={options}>
|
||||
<IssuesStack.Screen
|
||||
name="Issues"
|
||||
component={IssuesScreen}
|
||||
options={{ title: t('tabs.issues') }}
|
||||
/>
|
||||
</IssuesStack.Navigator>
|
||||
);
|
||||
}
|
||||
|
||||
const PullsStack = createNativeStackNavigator<PullsStackParamList>();
|
||||
export function PullsStackNavigator() {
|
||||
const { t } = useTranslation();
|
||||
const options = useTabHeader();
|
||||
return (
|
||||
<PullsStack.Navigator screenOptions={options}>
|
||||
<PullsStack.Screen
|
||||
name="PullRequests"
|
||||
component={PullRequestsScreen}
|
||||
options={{ title: t('tabs.pullRequests') }}
|
||||
/>
|
||||
</PullsStack.Navigator>
|
||||
);
|
||||
}
|
||||
|
||||
const InboxStack = createNativeStackNavigator<InboxStackParamList>();
|
||||
export function InboxStackNavigator() {
|
||||
const { t } = useTranslation();
|
||||
const options = useTabHeader();
|
||||
return (
|
||||
<InboxStack.Navigator screenOptions={options}>
|
||||
<InboxStack.Screen name="Inbox" component={InboxScreen} options={{ title: t('tabs.inbox') }} />
|
||||
</InboxStack.Navigator>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* React Navigation param lists. Every `useNavigation` / `useRoute` in the app
|
||||
* is typed against these — adding a screen means adding it here first.
|
||||
*/
|
||||
|
||||
import type { NavigatorScreenParams } from '@react-navigation/native';
|
||||
|
||||
export type AuthStackParamList = {
|
||||
Welcome: undefined;
|
||||
Connect: { baseUrl?: string } | undefined;
|
||||
};
|
||||
|
||||
export type HomeStackParamList = {
|
||||
Home: undefined;
|
||||
};
|
||||
|
||||
export type RepositoriesStackParamList = {
|
||||
RepositoryList: undefined;
|
||||
};
|
||||
|
||||
export type IssuesStackParamList = {
|
||||
Issues: undefined;
|
||||
};
|
||||
|
||||
export type PullsStackParamList = {
|
||||
PullRequests: undefined;
|
||||
};
|
||||
|
||||
export type InboxStackParamList = {
|
||||
Inbox: undefined;
|
||||
};
|
||||
|
||||
export type MainTabParamList = {
|
||||
HomeTab: NavigatorScreenParams<HomeStackParamList>;
|
||||
RepositoriesTab: NavigatorScreenParams<RepositoriesStackParamList>;
|
||||
IssuesTab: NavigatorScreenParams<IssuesStackParamList>;
|
||||
PullsTab: NavigatorScreenParams<PullsStackParamList>;
|
||||
InboxTab: NavigatorScreenParams<InboxStackParamList>;
|
||||
};
|
||||
|
||||
export type RepositoryStackParamList = {
|
||||
RepoOverview: { owner: string; name: string; ref?: string };
|
||||
Files: { owner: string; name: string; path?: string; ref?: string };
|
||||
FileViewer: { owner: string; name: string; path: string; ref?: string };
|
||||
Commits: { owner: string; name: string; sha?: string; path?: string };
|
||||
CommitDetail: { owner: string; name: string; sha: string };
|
||||
Branches: { owner: string; name: string };
|
||||
Tags: { owner: string; name: string };
|
||||
RepoIssues: { owner: string; name: string };
|
||||
IssueDetail: { owner: string; name: string; index: number };
|
||||
RepoPulls: { owner: string; name: string };
|
||||
PullDetail: { owner: string; name: string; index: number };
|
||||
};
|
||||
|
||||
export type SettingsStackParamList = {
|
||||
Settings: undefined;
|
||||
};
|
||||
|
||||
export type AccountsStackParamList = {
|
||||
Accounts: undefined;
|
||||
AddAccount: { baseUrl?: string } | undefined;
|
||||
};
|
||||
|
||||
export type RootStackParamList = {
|
||||
Auth: NavigatorScreenParams<AuthStackParamList>;
|
||||
Main: NavigatorScreenParams<MainTabParamList>;
|
||||
Repository: NavigatorScreenParams<RepositoryStackParamList>;
|
||||
Settings: NavigatorScreenParams<SettingsStackParamList>;
|
||||
Accounts: NavigatorScreenParams<AccountsStackParamList>;
|
||||
};
|
||||
|
||||
declare global {
|
||||
namespace ReactNavigation {
|
||||
// Empty interface intentionally augments the library's default param list.
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
||||
interface RootParamList extends RootStackParamList {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Screen prop helpers: every screen gets a navigation prop that is composed
|
||||
* with the main tabs and the root stack, so screens can navigate anywhere
|
||||
* (`navigation.navigate('Repository', …)`, `navigate('Settings')`, …) while
|
||||
* keeping full type safety.
|
||||
*/
|
||||
|
||||
import type { BottomTabScreenProps } from '@react-navigation/bottom-tabs';
|
||||
import type { CompositeScreenProps, ParamListBase } from '@react-navigation/native';
|
||||
import type { NativeStackScreenProps } from '@react-navigation/native-stack';
|
||||
|
||||
import type { MainTabParamList, RootStackParamList } from './types';
|
||||
|
||||
export type ScreenProps<
|
||||
Params extends ParamListBase,
|
||||
RouteName extends keyof Params & string,
|
||||
> = CompositeScreenProps<
|
||||
NativeStackScreenProps<Params, RouteName>,
|
||||
CompositeScreenProps<
|
||||
BottomTabScreenProps<MainTabParamList>,
|
||||
NativeStackScreenProps<RootStackParamList>
|
||||
>
|
||||
>;
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Typed handle on the *root* navigator.
|
||||
*
|
||||
* Screens nested inside a stack/tab use this to open root-level screens
|
||||
* (Settings, the Accounts modal) without fighting `CompositeScreenProps`
|
||||
* param-list merging when route names overlap between navigators.
|
||||
*/
|
||||
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
||||
|
||||
import type { RootStackParamList } from './types';
|
||||
|
||||
export type RootNavigationProp = NativeStackNavigationProp<RootStackParamList>;
|
||||
|
||||
export function useRootNavigation(): RootNavigationProp {
|
||||
return useNavigation<RootNavigationProp>();
|
||||
}
|
||||
Reference in new issue
Block a user