diff --git a/app/definitions/navigationTypes.ts b/app/definitions/navigationTypes.ts index 7d6fe2eed98..246c2353a4d 100644 --- a/app/definitions/navigationTypes.ts +++ b/app/definitions/navigationTypes.ts @@ -1,11 +1,11 @@ import { type NavigatorScreenParams } from '@react-navigation/core'; import { type NativeStackNavigationOptions } from '@react-navigation/native-stack'; -import { type TSubscriptionModel } from './ISubscription'; -import { type TServerModel } from './IServer'; -import { type IAttachment } from './IAttachment'; import { type MasterDetailInsideStackParamList } from '../stacks/MasterDetailStack/types'; import { type OutsideParamList, type InsideStackParamList } from '../stacks/types'; +import { type ShareInsideStackParamList } from '../stacks/ShareExtensionStack'; + +export type { ShareInsideStackParamList }; interface INavigationProps { route?: any; @@ -31,17 +31,3 @@ export type StackParamList = { SetUsernameStack: NavigatorScreenParams; ShareExtensionStack: NavigatorScreenParams; }; - -export type ShareInsideStackParamList = { - ShareListView: undefined; - ShareView: { - attachments: IAttachment[]; - isShareView?: boolean; - isShareExtension: boolean; - serverInfo: TServerModel; - text: string; - room: TSubscriptionModel; - thread?: any; // TODO: Change - }; - SelectServerView: undefined; -}; diff --git a/app/lib/navigation/withNavigation.tsx b/app/lib/navigation/withNavigation.tsx new file mode 100644 index 00000000000..d1bc984f257 --- /dev/null +++ b/app/lib/navigation/withNavigation.tsx @@ -0,0 +1,14 @@ +import { useNavigation } from '@react-navigation/native'; +import { type ComponentType } from 'react'; + +// Screen-registration-only HOC: injects navigation via hook; does not forward refs (React Navigation static API renders screens without refs). +function withNavigation

(WrappedComponent: ComponentType

): ComponentType> { + const WithNavigation = (props: Omit) => { + const navigation = useNavigation(); + return ; + }; + WithNavigation.displayName = `WithNavigation(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`; + return WithNavigation; +} + +export default withNavigation; diff --git a/app/stacks/ShareExtensionStack.tsx b/app/stacks/ShareExtensionStack.tsx index 0236e244b1f..8053c367529 100644 --- a/app/stacks/ShareExtensionStack.tsx +++ b/app/stacks/ShareExtensionStack.tsx @@ -1,27 +1,39 @@ -import { useContext } from 'react'; +import { useContext, type ComponentType } from 'react'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; +import { type StaticParamList, type StaticScreenProps } from '@react-navigation/native'; import { ThemeContext } from '../theme'; import { defaultHeader, themedHeader } from '../lib/methods/helpers/navigation'; import SelectServerView from '../views/SelectServerView'; import ShareListView from '../views/ShareListView'; import ShareView from '../views/ShareView'; +import withNavigation from '../lib/navigation/withNavigation'; +import { type InsideStackParamList } from './types'; -const ShareExtension = createNativeStackNavigator(); -const ShareExtensionStack = () => { +// Extension-only subset: omits InsideStack callbacks/params the share extension never provides. +type ShareViewParams = Omit; + +// withNavigation(x as any) returns ComponentType<{}> — not assignable to ComponentType> — due to the +// type cycle: these components reference ShareInsideStackParamList ← StaticParamList ← these components. +const ShareListViewScreen: ComponentType> = withNavigation(ShareListView as any) as any; +const ShareViewScreen: ComponentType> = withNavigation(ShareView as any) as any; + +const ShareExtension = createNativeStackNavigator({ + screenOptions: defaultHeader, + screens: { + ShareListView: ShareListViewScreen, + ShareView: ShareViewScreen, + SelectServerView + } +}).with(({ Navigator }) => { 'use memo'; const { theme } = useContext(ThemeContext); + return ; +}); + +export type ShareInsideStackParamList = StaticParamList; - return ( - - {/* @ts-ignore */} - - {/* @ts-ignore */} - - - - ); -}; +const ShareExtensionStack = ShareExtension.getComponent(); export default ShareExtensionStack;