Skip to content

Commit 4aca1ae

Browse files
authored
fix: add missing events (#2095)
## Description <!-- Description and motivation for this PR. Include Fixes #<number> if this is fixing some issue. Fixes # . --> Add missing `ScreenStackHeaderConfig` events to fabric spec and remove the manual registration of events. Also changed `Bubbling` events to `Direct` which fixes extraneous lifecycle events. It was to be done quite a while ago already: #1308 (comment)
1 parent 0ff580f commit 4aca1ae

File tree

5 files changed

+38
-44
lines changed

5 files changed

+38
-44
lines changed

src/components/Screen.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@ import {
1616
import ScreenNativeComponent from '../fabric/ScreenNativeComponent';
1717
import ModalScreenNativeComponent from '../fabric/ModalScreenNativeComponent';
1818

19-
// @ts-ignore - its taken straight from RN
20-
// eslint-disable-next-line import/namespace
21-
import { customDirectEventTypes } from 'react-native/Libraries/Renderer/shims/ReactNativeViewConfigRegistry';
22-
23-
customDirectEventTypes.topInsetsChange = {
24-
registrationName: 'topInsetsChange',
25-
};
26-
customDirectEventTypes.topAttached = {
27-
registrationName: 'topAttached',
28-
};
29-
customDirectEventTypes.topDetached = {
30-
registrationName: 'topDetached',
31-
};
32-
3319
export const NativeScreen: React.ComponentType<ScreenProps> =
3420
ScreenNativeComponent as any;
3521
const AnimatedNativeScreen = Animated.createAnimatedComponent(NativeScreen);

src/fabric/ModalScreenNativeComponent.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
22
import type { ViewProps, ColorValue } from 'react-native';
33
import type {
4-
BubblingEventHandler,
4+
DirectEventHandler,
55
WithDefault,
66
Int32,
77
Float,
@@ -60,16 +60,16 @@ type ReplaceAnimation = 'pop' | 'push';
6060
type SheetDetentTypes = 'large' | 'medium' | 'all';
6161

6262
export interface NativeProps extends ViewProps {
63-
onAppear?: BubblingEventHandler<ScreenEvent>;
64-
onDisappear?: BubblingEventHandler<ScreenEvent>;
65-
onDismissed?: BubblingEventHandler<ScreenDismissedEvent>;
66-
onNativeDismissCancelled?: BubblingEventHandler<ScreenDismissedEvent>;
67-
onWillAppear?: BubblingEventHandler<ScreenEvent>;
68-
onWillDisappear?: BubblingEventHandler<ScreenEvent>;
69-
onHeaderHeightChange?: BubblingEventHandler<HeaderHeightChangeEvent>;
70-
onTransitionProgress?: BubblingEventHandler<TransitionProgressEvent>;
71-
onGestureCancel?: BubblingEventHandler<ScreenEvent>;
72-
onHeaderBackButtonClicked?: BubblingEventHandler<ScreenEvent>;
63+
onAppear?: DirectEventHandler<ScreenEvent>;
64+
onDisappear?: DirectEventHandler<ScreenEvent>;
65+
onDismissed?: DirectEventHandler<ScreenDismissedEvent>;
66+
onNativeDismissCancelled?: DirectEventHandler<ScreenDismissedEvent>;
67+
onWillAppear?: DirectEventHandler<ScreenEvent>;
68+
onWillDisappear?: DirectEventHandler<ScreenEvent>;
69+
onHeaderHeightChange?: DirectEventHandler<HeaderHeightChangeEvent>;
70+
onTransitionProgress?: DirectEventHandler<TransitionProgressEvent>;
71+
onGestureCancel?: DirectEventHandler<ScreenEvent>;
72+
onHeaderBackButtonClicked?: DirectEventHandler<ScreenEvent>;
7373
sheetAllowedDetents?: WithDefault<SheetDetentTypes, 'large'>;
7474
sheetLargestUndimmedDetent?: WithDefault<SheetDetentTypes, 'all'>;
7575
sheetGrabberVisible?: WithDefault<boolean, false>;

src/fabric/ScreenNativeComponent.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
22
import type { ViewProps, ColorValue } from 'react-native';
33
import type {
4-
BubblingEventHandler,
4+
DirectEventHandler,
55
WithDefault,
66
Int32,
77
Float,
@@ -60,16 +60,16 @@ type ReplaceAnimation = 'pop' | 'push';
6060
type SheetDetentTypes = 'large' | 'medium' | 'all';
6161

6262
export interface NativeProps extends ViewProps {
63-
onAppear?: BubblingEventHandler<ScreenEvent>;
64-
onDisappear?: BubblingEventHandler<ScreenEvent>;
65-
onDismissed?: BubblingEventHandler<ScreenDismissedEvent>;
66-
onNativeDismissCancelled?: BubblingEventHandler<ScreenDismissedEvent>;
67-
onWillAppear?: BubblingEventHandler<ScreenEvent>;
68-
onWillDisappear?: BubblingEventHandler<ScreenEvent>;
69-
onHeaderHeightChange?: BubblingEventHandler<HeaderHeightChangeEvent>;
70-
onTransitionProgress?: BubblingEventHandler<TransitionProgressEvent>;
71-
onGestureCancel?: BubblingEventHandler<ScreenEvent>;
72-
onHeaderBackButtonClicked?: BubblingEventHandler<ScreenEvent>;
63+
onAppear?: DirectEventHandler<ScreenEvent>;
64+
onDisappear?: DirectEventHandler<ScreenEvent>;
65+
onDismissed?: DirectEventHandler<ScreenDismissedEvent>;
66+
onNativeDismissCancelled?: DirectEventHandler<ScreenDismissedEvent>;
67+
onWillAppear?: DirectEventHandler<ScreenEvent>;
68+
onWillDisappear?: DirectEventHandler<ScreenEvent>;
69+
onHeaderHeightChange?: DirectEventHandler<HeaderHeightChangeEvent>;
70+
onTransitionProgress?: DirectEventHandler<TransitionProgressEvent>;
71+
onGestureCancel?: DirectEventHandler<ScreenEvent>;
72+
onHeaderBackButtonClicked?: DirectEventHandler<ScreenEvent>;
7373
sheetAllowedDetents?: WithDefault<SheetDetentTypes, 'large'>;
7474
sheetLargestUndimmedDetent?: WithDefault<SheetDetentTypes, 'all'>;
7575
sheetGrabberVisible?: WithDefault<boolean, false>;

src/fabric/ScreenStackHeaderConfigNativeComponent.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@ import type { ViewProps, ColorValue } from 'react-native';
33
import type {
44
Int32,
55
WithDefault,
6+
DirectEventHandler,
67
} from 'react-native/Libraries/Types/CodegenTypes';
78

89
type DirectionType = 'rtl' | 'ltr';
910

11+
// eslint-disable-next-line @typescript-eslint/ban-types
12+
type OnAttachedEvent = Readonly<{}>;
13+
// eslint-disable-next-line @typescript-eslint/ban-types
14+
type OnDetachedEvent = Readonly<{}>;
15+
1016
export interface NativeProps extends ViewProps {
17+
onAttached?: DirectEventHandler<OnAttachedEvent>;
18+
onDetached?: DirectEventHandler<OnDetachedEvent>;
1119
backgroundColor?: ColorValue;
1220
backTitle?: string;
1321
backTitleFontFamily?: string;

src/fabric/SearchBarNativeComponent.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNati
33
import type { ViewProps, ColorValue, HostComponent } from 'react-native';
44
import type {
55
WithDefault,
6-
BubblingEventHandler,
6+
DirectEventHandler,
77
} from 'react-native/Libraries/Types/CodegenTypes';
88
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
99

@@ -22,11 +22,11 @@ type SearchBarPlacement = 'automatic' | 'inline' | 'stacked';
2222
type AutoCapitalizeType = 'none' | 'words' | 'sentences' | 'characters';
2323

2424
interface NativeProps extends ViewProps {
25-
onFocus?: BubblingEventHandler<SearchBarEvent> | null;
26-
onBlur?: BubblingEventHandler<SearchBarEvent> | null;
27-
onSearchButtonPress?: BubblingEventHandler<SearchButtonPressedEvent> | null;
28-
onCancelButtonPress?: BubblingEventHandler<SearchBarEvent> | null;
29-
onChangeText?: BubblingEventHandler<ChangeTextEvent> | null;
25+
onFocus?: DirectEventHandler<SearchBarEvent> | null;
26+
onBlur?: DirectEventHandler<SearchBarEvent> | null;
27+
onSearchButtonPress?: DirectEventHandler<SearchButtonPressedEvent> | null;
28+
onCancelButtonPress?: DirectEventHandler<SearchBarEvent> | null;
29+
onChangeText?: DirectEventHandler<ChangeTextEvent> | null;
3030
hideWhenScrolling?: boolean;
3131
autoCapitalize?: WithDefault<AutoCapitalizeType, 'none'>;
3232
placeholder?: string;
@@ -43,8 +43,8 @@ interface NativeProps extends ViewProps {
4343
disableBackButtonOverride?: boolean;
4444
// TODO: consider creating enum here
4545
inputType?: string;
46-
onClose?: BubblingEventHandler<SearchBarEvent> | null;
47-
onOpen?: BubblingEventHandler<SearchBarEvent> | null;
46+
onClose?: DirectEventHandler<SearchBarEvent> | null;
47+
onOpen?: DirectEventHandler<SearchBarEvent> | null;
4848
hintTextColor?: ColorValue;
4949
headerIconColor?: ColorValue;
5050
shouldShowHintSearchIcon?: WithDefault<boolean, true>;

0 commit comments

Comments
 (0)