Skip to content

Commit 0b134ec

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Align layout event names with OSS (#49423)
Summary: Changelog: [Internal] Differential Revision: D69655570
1 parent 893d1c5 commit 0b134ec

File tree

18 files changed

+152
-80
lines changed

18 files changed

+152
-80
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,
@@ -31,8 +31,8 @@ import type {
3131
} from './ViewAccessibility';
3232
import type {Node} from 'react';
3333

34-
export type ViewLayout = Layout;
35-
export type ViewLayoutEvent = LayoutEvent;
34+
export type ViewLayout = LayoutRectangle;
35+
export type ViewLayoutEvent = LayoutChangeEvent;
3636

3737
type DirectEventProps = $ReadOnly<{
3838
/**
@@ -61,7 +61,7 @@ type DirectEventProps = $ReadOnly<{
6161
*
6262
* See https://reactnative.dev/docs/view#onlayout
6363
*/
64-
onLayout?: ?(event: LayoutEvent) => mixed,
64+
onLayout?: ?(event: LayoutChangeEvent) => mixed,
6565

6666
/**
6767
* 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/Renderer/shims/ReactNativeTypes.js

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,75 @@ export type PartialViewConfig = $ReadOnly<{
103103

104104
/**
105105
* Current usages should migrate to this definition
106+
*
107+
* NativeMethods provides methods to access the underlying native component directly.
108+
* This can be useful in cases when you want to focus a view or measure its on-screen dimensions,
109+
* for example.
110+
* The methods described here are available on most of the default components provided by React Native.
111+
* Note, however, that they are not available on composite components that aren't directly backed by a
112+
* native view. This will generally include most components that you define in your own app.
106113
*/
107114
export interface INativeMethods {
115+
/**
116+
* Requests focus for the given input or view. The exact behavior triggered
117+
* will depend on the platform and type of view.
118+
*/
108119
blur(): void;
120+
/**
121+
* Removes focus from an input or view. This is the opposite of `focus()`.
122+
*/
109123
focus(): void;
124+
/**
125+
* Determines the location on screen, width, and height of the given view and
126+
* returns the values via an async callback. If successful, the callback will
127+
* be called with the following arguments:
128+
*
129+
* - x
130+
* - y
131+
* - width
132+
* - height
133+
* - pageX
134+
* - pageY
135+
*
136+
* Note that these measurements are not available until after the rendering
137+
* has been completed in native. If you need the measurements as soon as
138+
* possible, consider using the [`onLayout`
139+
* prop](docs/view.html#onlayout) instead.
140+
*/
110141
measure(callback: MeasureOnSuccessCallback): void;
142+
/**
143+
* Determines the location of the given view in the window and returns the
144+
* values via an async callback. If the React root view is embedded in
145+
* another native view, this will give you the absolute coordinates. If
146+
* successful, the callback will be called with the following
147+
* arguments:
148+
*
149+
* - x
150+
* - y
151+
* - width
152+
* - height
153+
*
154+
* Note that these measurements are not available until after the rendering
155+
* has been completed in native.
156+
*/
111157
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;
158+
/**
159+
* Like [`measure()`](#measure), but measures the view relative an ancestor,
160+
* specified as `relativeToNativeComponentRef`. This means that the returned x, y
161+
* are relative to the origin x, y of the ancestor view.
162+
* _Can also be called with a relativeNativeNodeHandle but is deprecated._
163+
*/
112164
measureLayout(
113165
relativeToNativeNode: number | HostInstance,
114166
onSuccess: MeasureLayoutOnSuccessCallback,
115167
onFail?: () => void,
116168
): void;
169+
/**
170+
* This function sends props straight to native. They will not participate in
171+
* future diff process - this means that if you do not include them in the
172+
* next render, they will remain active (see [Direct
173+
* Manipulation](https://reactnative.dev/docs/direct-manipulation)).
174+
*/
117175
setNativeProps(nativeProps: {...}): void;
118176
}
119177

@@ -166,6 +224,7 @@ export type InspectorData = $ReadOnly<{
166224
}>;
167225

168226
export type TouchedViewDataAtPoint = $ReadOnly<{
227+
...InspectorData,
169228
pointerY: number,
170229
touchedViewTag?: number,
171230
frame: $ReadOnly<{
@@ -175,7 +234,6 @@ export type TouchedViewDataAtPoint = $ReadOnly<{
175234
height: number,
176235
}>,
177236
closestPublicInstance?: PublicInstance,
178-
...InspectorData,
179237
}>;
180238

181239
export type RenderRootOptions = {

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

0 commit comments

Comments
 (0)