Skip to content

Commit a8bd6da

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Align layout event names with OSS (facebook#49423)
Summary: Changelog: [Internal] Reviewed By: huntie Differential Revision: D69655570
1 parent cda2d11 commit a8bd6da

File tree

17 files changed

+93
-79
lines changed

17 files changed

+93
-79
lines changed

packages/react-native/Libraries/Components/Pressable/Pressable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
import type {
12-
LayoutEvent,
12+
LayoutChangeEvent,
1313
MouseEvent,
1414
PressEvent,
1515
} from '../../Types/CoreEventTypes';
@@ -126,7 +126,7 @@ type Props = $ReadOnly<{
126126
/**
127127
* Called when this view's layout changes.
128128
*/
129-
onLayout?: ?(event: LayoutEvent) => mixed,
129+
onLayout?: ?(event: LayoutChangeEvent) => mixed,
130130

131131
/**
132132
* Called when the hover is activated to provide visual feedback.

packages/react-native/Libraries/Components/ScrollView/ScrollView.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {PointProp} from '../../StyleSheet/PointPropType';
1414
import type {ViewStyleProp} from '../../StyleSheet/StyleSheet';
1515
import type {ColorValue} from '../../StyleSheet/StyleSheet';
1616
import type {
17-
LayoutEvent,
17+
LayoutChangeEvent,
1818
PressEvent,
1919
ScrollEvent,
2020
} from '../../Types/CoreEventTypes';
@@ -1105,7 +1105,11 @@ class ScrollView extends React.Component<Props, State> {
11051105
}
11061106
}
11071107

1108-
_onStickyHeaderLayout(index: number, event: LayoutEvent, key: React.Key) {
1108+
_onStickyHeaderLayout(
1109+
index: number,
1110+
event: LayoutChangeEvent,
1111+
key: React.Key,
1112+
) {
11091113
const {stickyHeaderIndices} = this.props;
11101114
if (!stickyHeaderIndices) {
11111115
return;
@@ -1136,7 +1140,7 @@ class ScrollView extends React.Component<Props, State> {
11361140
this.props.onScroll && this.props.onScroll(e);
11371141
};
11381142

1139-
_handleLayout = (e: LayoutEvent) => {
1143+
_handleLayout = (e: LayoutChangeEvent) => {
11401144
if (this.props.invertStickyHeaders === true) {
11411145
this.setState({layoutHeight: e.nativeEvent.layout.height});
11421146
}
@@ -1145,7 +1149,7 @@ class ScrollView extends React.Component<Props, State> {
11451149
}
11461150
};
11471151

1148-
_handleContentOnLayout = (e: LayoutEvent) => {
1152+
_handleContentOnLayout = (e: LayoutChangeEvent) => {
11491153
const {width, height} = e.nativeEvent.layout;
11501154
this.props.onContentSizeChange &&
11511155
this.props.onContentSizeChange(width, height);

packages/react-native/Libraries/Components/ScrollView/ScrollViewStickyHeader.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @format
99
*/
1010

11-
import type {LayoutEvent} from '../../Types/CoreEventTypes';
11+
import type {LayoutChangeEvent} from '../../Types/CoreEventTypes';
1212

1313
import Animated from '../../Animated/Animated';
1414
import {isPublicInstance as isFabricPublicInstance} from '../../ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstanceUtils';
@@ -21,7 +21,7 @@ import {useCallback, useEffect, useMemo, useRef, useState} from 'react';
2121
export type Props = $ReadOnly<{
2222
children?: React.Node,
2323
nextHeaderLayoutY: ?number,
24-
onLayout: (event: LayoutEvent) => void,
24+
onLayout: (event: LayoutChangeEvent) => void,
2525
scrollAnimatedValue: Animated.Value,
2626
// Will cause sticky headers to stick at the bottom of the ScrollView instead
2727
// of the top.
@@ -253,7 +253,7 @@ const ScrollViewStickyHeaderWithForwardedRef: component(
253253
isFabric,
254254
]);
255255

256-
const _onLayout = (event: LayoutEvent) => {
256+
const _onLayout = (event: LayoutChangeEvent) => {
257257
setLayoutY(event.nativeEvent.layout.y);
258258
setLayoutHeight(event.nativeEvent.layout.height);
259259
setMeasured(true);

packages/react-native/Libraries/Components/Touchable/TouchableWithoutFeedback.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {EdgeInsetsOrSizeProp} from '../../StyleSheet/EdgeInsetsPropType';
1919
import type {
2020
BlurEvent,
2121
FocusEvent,
22-
LayoutEvent,
22+
LayoutChangeEvent,
2323
PressEvent,
2424
} from '../../Types/CoreEventTypes';
2525

@@ -73,7 +73,7 @@ type Props = $ReadOnly<{
7373
onAccessibilityAction?: ?(event: AccessibilityActionEvent) => mixed,
7474
onBlur?: ?(event: BlurEvent) => mixed,
7575
onFocus?: ?(event: FocusEvent) => mixed,
76-
onLayout?: ?(event: LayoutEvent) => mixed,
76+
onLayout?: ?(event: LayoutChangeEvent) => mixed,
7777
onLongPress?: ?(event: PressEvent) => mixed,
7878
onPress?: ?(event: PressEvent) => mixed,
7979
onPressIn?: ?(event: PressEvent) => mixed,

packages/react-native/Libraries/Components/View/ViewPropTypes.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import type {ViewStyleProp} from '../../StyleSheet/StyleSheet';
1515
import type {
1616
BlurEvent,
1717
FocusEvent,
18-
Layout,
19-
LayoutEvent,
18+
LayoutChangeEvent,
19+
LayoutRectangle,
2020
MouseEvent,
2121
PointerEvent,
2222
PressEvent,
@@ -27,8 +27,8 @@ import type {
2727
} from './ViewAccessibility';
2828
import type {Node} from 'react';
2929

30-
export type ViewLayout = Layout;
31-
export type ViewLayoutEvent = LayoutEvent;
30+
export type ViewLayout = LayoutRectangle;
31+
export type ViewLayoutEvent = LayoutChangeEvent;
3232

3333
type DirectEventProps = $ReadOnly<{
3434
/**
@@ -57,7 +57,7 @@ type DirectEventProps = $ReadOnly<{
5757
*
5858
* See https://reactnative.dev/docs/view#onlayout
5959
*/
60-
onLayout?: ?(event: LayoutEvent) => mixed,
60+
onLayout?: ?(event: LayoutChangeEvent) => mixed,
6161

6262
/**
6363
* When `accessible` is `true`, the system will invoke this function when the

packages/react-native/Libraries/Image/ImageProps.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type {
1717
ImageStyleProp,
1818
ViewStyleProp,
1919
} from '../StyleSheet/StyleSheet';
20-
import type {LayoutEvent, SyntheticEvent} from '../Types/CoreEventTypes';
20+
import type {LayoutChangeEvent, SyntheticEvent} from '../Types/CoreEventTypes';
2121
import typeof Image from './Image';
2222
import type {ImageResizeMode} from './ImageResizeMode';
2323
import type {ImageSource} from './ImageSource';
@@ -177,7 +177,7 @@ export type ImageProps = $ReadOnly<{
177177
* See https://reactnative.dev/docs/image#onlayout
178178
*/
179179

180-
onLayout?: ?(event: LayoutEvent) => mixed,
180+
onLayout?: ?(event: LayoutChangeEvent) => mixed,
181181

182182
/**
183183
* Invoked when load completes successfully.

packages/react-native/Libraries/Text/TextProps.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {
1919
} from '../Components/View/ViewAccessibility';
2020
import type {ColorValue, TextStyleProp} from '../StyleSheet/StyleSheet';
2121
import type {
22-
LayoutEvent,
22+
LayoutChangeEvent,
2323
PointerEvent,
2424
PressEvent,
2525
TextLayoutEvent,
@@ -142,7 +142,7 @@ export type TextProps = $ReadOnly<{
142142
*
143143
* See https://reactnative.dev/docs/text#onlayout
144144
*/
145-
onLayout?: ?(event: LayoutEvent) => mixed,
145+
onLayout?: ?(event: LayoutChangeEvent) => mixed,
146146

147147
/**
148148
* This function is called on long press.

packages/react-native/Libraries/Types/CoreEventTypes.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,33 @@ export type ResponderSyntheticEvent<T> = $ReadOnly<{
5454
}>,
5555
}>;
5656

57-
export type Layout = $ReadOnly<{
57+
export type LayoutRectangle = $ReadOnly<{
5858
x: number,
5959
y: number,
6060
width: number,
6161
height: number,
6262
}>;
6363

64-
export type TextLayout = $ReadOnly<{
65-
...Layout,
64+
export type TextLayoutLine = $ReadOnly<{
65+
...LayoutRectangle,
6666
ascender: number,
6767
capHeight: number,
6868
descender: number,
6969
text: string,
7070
xHeight: number,
7171
}>;
7272

73-
export type LayoutEvent = SyntheticEvent<
73+
export type LayoutChangeEvent = SyntheticEvent<
7474
$ReadOnly<{
75-
layout: Layout,
75+
layout: LayoutRectangle,
7676
}>,
7777
>;
7878

79-
export type TextLayoutEvent = SyntheticEvent<
80-
$ReadOnly<{
81-
lines: Array<TextLayout>,
82-
}>,
83-
>;
79+
export type TextLayoutEventData = $ReadOnly<{
80+
lines: Array<TextLayoutLine>,
81+
}>;
82+
83+
export type TextLayoutEvent = SyntheticEvent<TextLayoutEventData>;
8484

8585
/**
8686
* https://developer.mozilla.org/en-US/docs/Web/API/UIEvent

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ type Props = $ReadOnly<{
16161616
disabled?: ?boolean,
16171617
hitSlop?: ?RectOrSize,
16181618
pressRetentionOffset?: ?RectOrSize,
1619-
onLayout?: ?(event: LayoutEvent) => mixed,
1619+
onLayout?: ?(event: LayoutChangeEvent) => mixed,
16201620
onHoverIn?: ?(event: MouseEvent) => mixed,
16211621
onHoverOut?: ?(event: MouseEvent) => mixed,
16221622
onLongPress?: ?(event: PressEvent) => mixed,
@@ -2053,7 +2053,7 @@ exports[`public API should not change unintentionally Libraries/Components/Scrol
20532053
"export type Props = $ReadOnly<{
20542054
children?: React.Node,
20552055
nextHeaderLayoutY: ?number,
2056-
onLayout: (event: LayoutEvent) => void,
2056+
onLayout: (event: LayoutChangeEvent) => void,
20572057
scrollAnimatedValue: Animated.Value,
20582058
inverted: ?boolean,
20592059
scrollViewHeight: ?number,
@@ -3505,7 +3505,7 @@ exports[`public API should not change unintentionally Libraries/Components/Touch
35053505
onAccessibilityAction?: ?(event: AccessibilityActionEvent) => mixed,
35063506
onBlur?: ?(event: BlurEvent) => mixed,
35073507
onFocus?: ?(event: FocusEvent) => mixed,
3508-
onLayout?: ?(event: LayoutEvent) => mixed,
3508+
onLayout?: ?(event: LayoutChangeEvent) => mixed,
35093509
onLongPress?: ?(event: PressEvent) => mixed,
35103510
onPress?: ?(event: PressEvent) => mixed,
35113511
onPressIn?: ?(event: PressEvent) => mixed,
@@ -3784,12 +3784,12 @@ export type ViewNativeComponentType = HostComponent<Props>;
37843784
`;
37853785

37863786
exports[`public API should not change unintentionally Libraries/Components/View/ViewPropTypes.js 1`] = `
3787-
"export type ViewLayout = Layout;
3788-
export type ViewLayoutEvent = LayoutEvent;
3787+
"export type ViewLayout = LayoutRectangle;
3788+
export type ViewLayoutEvent = LayoutChangeEvent;
37893789
type DirectEventProps = $ReadOnly<{
37903790
onAccessibilityAction?: ?(event: AccessibilityActionEvent) => mixed,
37913791
onAccessibilityTap?: ?() => mixed,
3792-
onLayout?: ?(event: LayoutEvent) => mixed,
3792+
onLayout?: ?(event: LayoutChangeEvent) => mixed,
37933793
onMagicTap?: ?() => mixed,
37943794
onAccessibilityEscape?: ?() => mixed,
37953795
}>;
@@ -4476,7 +4476,7 @@ export type ImageProps = $ReadOnly<{
44764476
}>,
44774477
>
44784478
) => void,
4479-
onLayout?: ?(event: LayoutEvent) => mixed,
4479+
onLayout?: ?(event: LayoutChangeEvent) => mixed,
44804480
onLoad?: ?(event: ImageLoadEvent) => void,
44814481
onLoadEnd?: ?() => void,
44824482
onLoadStart?: ?() => void,
@@ -7770,7 +7770,7 @@ export type TextProps = $ReadOnly<{
77707770
maxFontSizeMultiplier?: ?number,
77717771
nativeID?: ?string,
77727772
numberOfLines?: ?number,
7773-
onLayout?: ?(event: LayoutEvent) => mixed,
7773+
onLayout?: ?(event: LayoutChangeEvent) => mixed,
77747774
onLongPress?: ?(event: PressEvent) => mixed,
77757775
onPress?: ?(event: PressEvent) => mixed,
77767776
onPressIn?: ?(event: PressEvent) => mixed,
@@ -7897,30 +7897,29 @@ export type ResponderSyntheticEvent<T> = $ReadOnly<{
78977897
>,
78987898
}>,
78997899
}>;
7900-
export type Layout = $ReadOnly<{
7900+
export type LayoutRectangle = $ReadOnly<{
79017901
x: number,
79027902
y: number,
79037903
width: number,
79047904
height: number,
79057905
}>;
7906-
export type TextLayout = $ReadOnly<{
7907-
...Layout,
7906+
export type TextLayoutLine = $ReadOnly<{
7907+
...LayoutRectangle,
79087908
ascender: number,
79097909
capHeight: number,
79107910
descender: number,
79117911
text: string,
79127912
xHeight: number,
79137913
}>;
7914-
export type LayoutEvent = SyntheticEvent<
7914+
export type LayoutChangeEvent = SyntheticEvent<
79157915
$ReadOnly<{
7916-
layout: Layout,
7917-
}>,
7918-
>;
7919-
export type TextLayoutEvent = SyntheticEvent<
7920-
$ReadOnly<{
7921-
lines: Array<TextLayout>,
7916+
layout: LayoutRectangle,
79227917
}>,
79237918
>;
7919+
export type TextLayoutEventData = $ReadOnly<{
7920+
lines: Array<TextLayoutLine>,
7921+
}>;
7922+
export type TextLayoutEvent = SyntheticEvent<TextLayoutEventData>;
79247923
export interface NativeUIEvent {
79257924
+detail: number;
79267925
}

packages/rn-tester/IntegrationTests/LayoutEventsTest.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';
1414
import type {
15-
Layout,
16-
LayoutEvent,
15+
LayoutChangeEvent,
16+
LayoutRectangle,
1717
} from 'react-native/Libraries/Types/CoreEventTypes';
1818

1919
const React = require('react');
@@ -23,7 +23,7 @@ const deepDiffer =
2323

2424
const {Image, LayoutAnimation, StyleSheet, Text, View} = ReactNative;
2525
const {TestModule} = ReactNative.NativeModules;
26-
function debug(...args: Array<void | Layout | string>) {
26+
function debug(...args: Array<void | LayoutRectangle | string>) {
2727
// console.log.apply(null, arguments);
2828
}
2929

@@ -32,9 +32,9 @@ type Props = $ReadOnly<{}>;
3232
type State = {
3333
didAnimation: boolean,
3434
extraText?: string,
35-
imageLayout?: Layout,
36-
textLayout?: Layout,
37-
viewLayout?: Layout,
35+
imageLayout?: LayoutRectangle,
36+
textLayout?: LayoutRectangle,
37+
viewLayout?: LayoutRectangle,
3838
viewStyle?: ViewStyleProp,
3939
containerStyle?: ViewStyleProp,
4040
...
@@ -106,7 +106,11 @@ class LayoutEventsTest extends React.Component<Props, State> {
106106
});
107107
};
108108

109-
compare(node: string, measured: Layout, onLayout?: ?Layout): void {
109+
compare(
110+
node: string,
111+
measured: LayoutRectangle,
112+
onLayout?: ?LayoutRectangle,
113+
): void {
110114
if (deepDiffer(measured, onLayout)) {
111115
const data = {measured, onLayout};
112116
throw new Error(
@@ -117,19 +121,19 @@ class LayoutEventsTest extends React.Component<Props, State> {
117121
}
118122
}
119123

120-
onViewLayout: (e: LayoutEvent) => void = (e: LayoutEvent) => {
124+
onViewLayout: (e: LayoutChangeEvent) => void = (e: LayoutChangeEvent) => {
121125
// $FlowFixMe[incompatible-call]
122126
debug('received view layout event\n', e.nativeEvent);
123127
this.setState({viewLayout: e.nativeEvent.layout}, this.checkLayout);
124128
};
125129

126-
onTextLayout: (e: LayoutEvent) => void = (e: LayoutEvent) => {
130+
onTextLayout: (e: LayoutChangeEvent) => void = (e: LayoutChangeEvent) => {
127131
// $FlowFixMe[incompatible-call]
128132
debug('received text layout event\n', e.nativeEvent);
129133
this.setState({textLayout: e.nativeEvent.layout}, this.checkLayout);
130134
};
131135

132-
onImageLayout: (e: LayoutEvent) => void = (e: LayoutEvent) => {
136+
onImageLayout: (e: LayoutChangeEvent) => void = (e: LayoutChangeEvent) => {
133137
// $FlowFixMe[incompatible-call]
134138
debug('received image layout event\n', e.nativeEvent);
135139
this.setState({imageLayout: e.nativeEvent.layout}, this.checkLayout);

0 commit comments

Comments
 (0)