Skip to content

Commit 22310c8

Browse files
authored
refactor: Separate API props and NativeProps for ScreenStack (#2450)
## Description Continuation of #2423. Separate public `ScreenStackProps` and `NativeProps` by not casting NativeComponent as `React.ComponentType<ScreenStackProps> `. ## Checklist - [ ] Ensured that CI passes
1 parent 5b9b8bd commit 22310c8

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/components/ScreenStack.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { freezeEnabled } from '../core';
66
import DelayedFreeze from './helpers/DelayedFreeze';
77

88
// Native components
9-
import ScreenStackNativeComponent from '../fabric/ScreenStackNativeComponent';
10-
const NativeScreenStack: React.ComponentType<ScreenStackProps> =
11-
ScreenStackNativeComponent as any;
9+
import ScreenStackNativeComponent, {
10+
NativeProps,
11+
} from '../fabric/ScreenStackNativeComponent';
1212

1313
function isFabric() {
1414
return 'nativeFabricUIManager' in global;
@@ -45,9 +45,19 @@ function ScreenStack(props: ScreenStackProps) {
4545
}
4646
});
4747
return (
48-
<NativeScreenStack {...rest} ref={ref}>
48+
<ScreenStackNativeComponent
49+
{...rest}
50+
/**
51+
* This messy override is to conform NativeProps used by codegen and
52+
* our Public API. To see reasoning go to this PR:
53+
* https://github.com/software-mansion/react-native-screens/pull/2423#discussion_r1810616995
54+
*/
55+
onFinishTransitioning={
56+
props.onFinishTransitioning as NativeProps['onFinishTransitioning']
57+
}
58+
ref={ref}>
4959
{childrenWithFreeze}
50-
</NativeScreenStack>
60+
</ScreenStackNativeComponent>
5161
);
5262
}
5363

src/fabric/ScreenStackNativeComponent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTyp
77
// eslint-disable-next-line @typescript-eslint/ban-types
88
type FinishTransitioningEvent = Readonly<{}>;
99

10-
interface NativeProps extends ViewProps {
10+
export interface NativeProps extends ViewProps {
1111
onFinishTransitioning?: DirectEventHandler<FinishTransitioningEvent>;
1212
}
1313

0 commit comments

Comments
 (0)