Skip to content

Commit afcb4ed

Browse files
huntiefacebook-github-bot
authored andcommitted
Hide ReactNativeElement constructor from public API
Summary: Mark `ReactNativeElement` as non-user-constructible in the generated TypeScript definitions by emitting `private constructor()`. **Motivation** - Correctness — like web DOM elements (`HTMLElement`, etc.), `ReactNativeElement` instances are created by the React Native runtime, not in user space. - Reduce public API surface (in particular, ahead of likely dropping the `LegacyHostInstanceMethods` type). **Changes** - Adds a new `build-types private-constructor` directive and corresponding `build-types` post-transform. - Applies directive to `ReactNativeElement`. - Also extracts shared `build-types` directive helpers into `transforms/typescript/utils/buildDirectives.js`. Changelog: [Internal] Differential Revision: D107119545
1 parent 7f396d1 commit afcb4ed

7 files changed

Lines changed: 328 additions & 158 deletions

File tree

packages/react-native/ReactNativeApi.d.ts

Lines changed: 102 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<a438af540f18c77572f05cef9481b7a6>>
7+
* @generated SignedSource<<00cb2351bba6e33a8d2f129e6ccdf4c0>>
88
*
99
* This file was generated by scripts/js-api/build-types/index.js.
1010
*/
@@ -4047,12 +4047,7 @@ declare class ReactNativeElement_default
40474047
implements NativeMethods
40484048
{
40494049
blur(): void
4050-
constructor(
4051-
tag: number,
4052-
viewConfig: ViewConfig,
4053-
instanceHandle: InstanceHandle,
4054-
ownerDocument: ReactNativeDocument_default,
4055-
)
4050+
private constructor()
40564051
focus(): void
40574052
measure(callback: MeasureOnSuccessCallback): void
40584053
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void
@@ -5992,23 +5987,23 @@ declare type WrapperComponentProvider = (
59925987
appParameters: Object,
59935988
) => React.ComponentType<any>
59945989
export {
5995-
AccessibilityActionEvent, // 5c5928b9
5996-
AccessibilityInfo, // 539eb4b3
5990+
AccessibilityActionEvent, // 33aba12a
5991+
AccessibilityInfo, // 54271401
59975992
AccessibilityProps, // 5a2836fc
59985993
AccessibilityRole, // f2f2e066
59995994
AccessibilityState, // b0c2b3f7
60005995
AccessibilityValue, // cf8bcb74
60015996
ActionSheetIOS, // b558559e
60025997
ActionSheetIOSOptions, // 1756eb5a
6003-
ActivityIndicator, // f06b0687
6004-
ActivityIndicatorProps, // 5e976856
5998+
ActivityIndicator, // c37376bf
5999+
ActivityIndicatorProps, // 9e338734
60056000
Alert, // 5bf12165
60066001
AlertButton, // bf1a3b60
60076002
AlertButtonStyle, // ec9fb242
60086003
AlertOptions, // a0cdac0f
60096004
AlertType, // 5ab91217
60106005
AndroidKeyboardEvent, // e03becc8
6011-
Animated, // 1a47480c
6006+
Animated, // 47b79675
60126007
AppConfig, // ce4209a7
60136008
AppRegistry, // 5edf0524
60146009
AppState, // 12012be5
@@ -6018,12 +6013,12 @@ export {
60186013
AutoCapitalize, // c0e857a0
60196014
BackHandler, // f139fc69
60206015
BackPressEventName, // 4620fb76
6021-
BlurEvent, // e6151a1f
6016+
BlurEvent, // 780c86b3
60226017
BoxShadowValue, // b679703f
6023-
Button, // 869e5a89
6024-
ButtonProps, // 349967e6
6018+
Button, // ef9592c5
6019+
ButtonProps, // 314e63c6
60256020
Clipboard, // 41addb89
6026-
CodegenTypes, // 0b8108a8
6021+
CodegenTypes, // 449fadfa
60276022
ColorSchemeName, // 6615edd6
60286023
ColorValue, // 98989a8f
60296024
ComponentProvider, // b5c60ddd
@@ -6039,9 +6034,9 @@ export {
60396034
DimensionsPayload, // 653bc26c
60406035
DisplayMetrics, // 1dc35cef
60416036
DisplayMetricsAndroid, // 872e62eb
6042-
DrawerLayoutAndroid, // eb4bcfa5
6043-
DrawerLayoutAndroidProps, // 1ddb208e
6044-
DrawerSlideEvent, // 0256d35a
6037+
DrawerLayoutAndroid, // 94e81861
6038+
DrawerLayoutAndroidProps, // 9ff4484a
6039+
DrawerSlideEvent, // d175a538
60456040
DropShadowValue, // e9df2606
60466041
DynamicColorIOS, // d96c228c
60476042
DynamicColorIOSTuple, // 023ce58e
@@ -6055,29 +6050,29 @@ export {
60556050
EventSubscription, // b8d084aa
60566051
ExtendedExceptionData, // 5a6ccf5a
60576052
FilterFunction, // bf24c0e3
6058-
FlatList, // e47faa4e
6059-
FlatListProps, // 22cacca0
6060-
FocusEvent, // 62fc1eb8
6053+
FlatList, // c05cd406
6054+
FlatListProps, // ccbb7cbf
6055+
FocusEvent, // 62f32376
60616056
FontVariant, // 7c7558bb
6062-
GestureResponderEvent, // f693e9a5
6063-
GestureResponderHandlers, // cc70e4cb
6057+
GestureResponderEvent, // e63debf2
6058+
GestureResponderHandlers, // 2b92c86d
60646059
Handle, // 2d65285d
6065-
HostComponent, // 16fccab5
6066-
HostInstance, // 9b5a9ec2
6060+
HostComponent, // 03bfd9f4
6061+
HostInstance, // ca179e31
60676062
I18nManager, // f9870e00
60686063
IEventEmitter, // fbef6131
60696064
IOSKeyboardEvent, // e67bfe3a
60706065
IgnorePattern, // ec6f6ece
6071-
Image, // 1891541a
6072-
ImageBackground, // cf95f60b
6073-
ImageBackgroundProps, // c68c896d
6074-
ImageErrorEvent, // d3ee606e
6075-
ImageLoadEvent, // 6b547ea5
6076-
ImageProgressEventIOS, // 4c866a82
6077-
ImageProps, // 801d1e1c
6066+
Image, // fd93f5d1
6067+
ImageBackground, // 4fe27d63
6068+
ImageBackgroundProps, // b2720e58
6069+
ImageErrorEvent, // 786fdfcc
6070+
ImageLoadEvent, // bef775c1
6071+
ImageProgressEventIOS, // 7aff2128
6072+
ImageProps, // 918d8ffe
60786073
ImagePropsAndroid, // 9fd9bcbb
6079-
ImagePropsBase, // 372b652b
6080-
ImagePropsIOS, // c4ae0c06
6074+
ImagePropsBase, // 085d3f57
6075+
ImagePropsIOS, // 872d46ca
60816076
ImageRequireSource, // 681d683b
60826077
ImageResolvedAssetSource, // f3060931
60836078
ImageSize, // 1c47cf88
@@ -6090,12 +6085,12 @@ export {
60906085
InputModeOptions, // 4e8581b9
60916086
Insets, // e7fe432a
60926087
InteractionManager, // c324d6e3
6093-
KeyDownEvent, // d4971b72
6088+
KeyDownEvent, // b97b3b72
60946089
KeyEvent, // 20fa4267
6095-
KeyUpEvent, // bc6bd87b
6090+
KeyUpEvent, // c0fda285
60966091
Keyboard, // 49414c97
6097-
KeyboardAvoidingView, // c8c29c8d
6098-
KeyboardAvoidingViewProps, // 4114f649
6092+
KeyboardAvoidingView, // 4cfb12da
6093+
KeyboardAvoidingViewProps, // 399d87a5
60996094
KeyboardEvent, // c3f895d4
61006095
KeyboardEventEasing, // af4091c8
61016096
KeyboardEventName, // 59299ad6
@@ -6108,7 +6103,7 @@ export {
61086103
LayoutAnimationProperty, // 52995f01
61096104
LayoutAnimationType, // 2da0a29b
61106105
LayoutAnimationTypes, // 081b3bde
6111-
LayoutChangeEvent, // c388ba2b
6106+
LayoutChangeEvent, // 37529b47
61126107
LayoutConformanceProps, // 055f03b8
61136108
LayoutRectangle, // 6601b294
61146109
Linking, // 9a6a174d
@@ -6120,34 +6115,34 @@ export {
61206115
MeasureInWindowOnSuccessCallback, // a285f598
61216116
MeasureLayoutOnSuccessCallback, // 3592502a
61226117
MeasureOnSuccessCallback, // 82824e59
6123-
Modal, // bdd9bb3f
6124-
ModalBaseProps, // 3cca97dc
6125-
ModalProps, // aa4211df
6118+
Modal, // 22be095d
6119+
ModalBaseProps, // a278cadf
6120+
ModalProps, // 63861662
61266121
ModalPropsAndroid, // 515fb173
6127-
ModalPropsIOS, // 144bbc95
6128-
ModeChangeEvent, // a5e9864f
6129-
MouseEvent, // fdce82bc
6122+
ModalPropsIOS, // ac424bbd
6123+
ModeChangeEvent, // 679fe81e
6124+
MouseEvent, // 8e5523a5
61306125
NativeAppEventEmitter, // 08d4c47d
61316126
NativeColorValue, // d2094c29
6132-
NativeComponentRegistry, // 21481a60
6127+
NativeComponentRegistry, // 616e1846
61336128
NativeDialogManagerAndroid, // 5be8497e
61346129
NativeEventEmitter, // 27f97c1a
61356130
NativeEventSubscription, // de3942e7
6136-
NativeMethods, // a2311987
6137-
NativeMethodsMixin, // a819ef55
6131+
NativeMethods, // 53965456
6132+
NativeMethodsMixin, // 263e85c9
61386133
NativeModules, // 4597cd36
6139-
NativeMouseEvent, // 558d45b0
6140-
NativePointerEvent, // f1763d80
6134+
NativeMouseEvent, // 723e899b
6135+
NativePointerEvent, // e28e3782
61416136
NativeScrollEvent, // caad7f53
6142-
NativeSyntheticEvent, // 35855c4c
6137+
NativeSyntheticEvent, // cb87886b
61436138
NativeTouchEvent, // 59b676df
61446139
NativeUIEvent, // 44ac26ac
61456140
Networking, // bbc5be42
61466141
OpaqueColorValue, // 25f3fa5b
6147-
PanResponder, // 4320c1ba
6148-
PanResponderCallbacks, // ed54b109
6142+
PanResponder, // f95255ab
6143+
PanResponderCallbacks, // d54e3183
61496144
PanResponderGestureState, // 54baf558
6150-
PanResponderInstance, // 46b4629d
6145+
PanResponderInstance, // 957e6213
61516146
Permission, // 06473f4f
61526147
PermissionStatus, // 4b7de97b
61536148
PermissionsAndroid, // db2a401e
@@ -6157,52 +6152,52 @@ export {
61576152
PlatformOSType, // 0a17561e
61586153
PlatformSelectSpec, // 09ed7758
61596154
PointValue, // 69db075f
6160-
PointerEvent, // fe3989a1
6161-
PressabilityConfig, // 6dedcb61
6162-
PressabilityEventHandlers, // 3e6c0f56
6163-
Pressable, // 0241ba70
6155+
PointerEvent, // 4af4b669
6156+
PressabilityConfig, // ad5b865f
6157+
PressabilityEventHandlers, // 28f81d78
6158+
Pressable, // 6a0232e2
61646159
PressableAndroidRippleConfig, // ee32eaca
6165-
PressableProps, // a9048420
6160+
PressableProps, // 2410d681
61666161
PressableStateCallbackType, // 9af36561
61676162
ProcessedColorValue, // 33f74304
6168-
ProgressBarAndroid, // 00fcd180
6169-
ProgressBarAndroidProps, // f59f8f03
6163+
ProgressBarAndroid, // a4af8a30
6164+
ProgressBarAndroidProps, // 07dcdf0d
61706165
PromiseTask, // 5102c862
61716166
PublicRootInstance, // 8040afd7
6172-
PublicTextInstance, // cd0d8f8d
6167+
PublicTextInstance, // 9fcf80fb
61736168
PushNotificationEventName, // 84e7e150
61746169
PushNotificationIOS, // b4d1fe78
61756170
PushNotificationPermissions, // c2e7ae4f
61766171
Rationale, // 5df1b1c1
61776172
ReactNativeVersion, // abd76827
6178-
RefreshControl, // ed67a3b2
6179-
RefreshControlProps, // bfc35644
6173+
RefreshControl, // 047bfe27
6174+
RefreshControlProps, // b50092cb
61806175
RefreshControlPropsAndroid, // 99f64c97
61816176
RefreshControlPropsIOS, // 72a36381
61826177
Registry, // 6c39216d
6183-
ResponderSyntheticEvent, // fb10247c
6178+
ResponderSyntheticEvent, // adf32caa
61846179
ReturnKeyTypeOptions, // afd47ba3
61856180
Role, // af7b889d
61866181
RootTag, // 3cd10504
61876182
RootTagContext, // 38bfc8f6
61886183
RootViewStyleProvider, // d4818465
61896184
Runnable, // 594dd93a
61906185
Runnables, // 4367c557
6191-
SafeAreaView, // a7cd92bb
6186+
SafeAreaView, // cb3671f3
61926187
ScaledSize, // 07e417c7
6193-
ScrollEvent, // 5d529218
6194-
ScrollResponderType, // 197f0107
6188+
ScrollEvent, // 759fc8e1
6189+
ScrollResponderType, // 316d87b4
61956190
ScrollToLocationParamsType, // d7ecdad1
6196-
ScrollView, // 938178e6
6197-
ScrollViewImperativeMethods, // 27f6b917
6198-
ScrollViewProps, // d5d9f043
6191+
ScrollView, // 1051f16e
6192+
ScrollViewImperativeMethods, // c8dcbb4a
6193+
ScrollViewProps, // 3b182fce
61996194
ScrollViewPropsAndroid, // 44210553
6200-
ScrollViewPropsIOS, // b34b696c
6195+
ScrollViewPropsIOS, // 60c9a301
62016196
ScrollViewScrollToOptions, // 3313411e
62026197
SectionBase, // b376bddc
6203-
SectionList, // 6b202d76
6198+
SectionList, // 7f74e8c2
62046199
SectionListData, // 119baf83
6205-
SectionListProps, // 6bdbf0ef
6200+
SectionListProps, // f38d74b2
62066201
SectionListRenderItem, // 1fad0435
62076202
SectionListRenderItemInfo, // 745e1992
62086203
Separators, // 6a45f7e3
@@ -6221,66 +6216,66 @@ export {
62216216
StyleProp, // fa0e9b4a
62226217
StyleSheet, // e77dd046
62236218
SubmitBehavior, // c4ddf490
6224-
Switch, // 015be3f7
6225-
SwitchChangeEvent, // 63e9c50b
6226-
SwitchProps, // 0dbf23ea
6219+
Switch, // 51333910
6220+
SwitchChangeEvent, // 8634990d
6221+
SwitchProps, // 73fbe487
62276222
Systrace, // 626d178c
62286223
TVViewPropsIOS, // 330ce7b5
62296224
TargetedEvent, // 16e98910
62306225
TaskProvider, // 266dedf2
6231-
Text, // 608149e8
6226+
Text, // 1e6955ef
62326227
TextContentType, // 239b3ecc
6233-
TextInput, // 3b7016bb
6228+
TextInput, // 1962fa97
62346229
TextInputAndroidProps, // 3f09ce49
6235-
TextInputChangeEvent, // 3ab11bb4
6236-
TextInputContentSizeChangeEvent, // f71f8571
6237-
TextInputEndEditingEvent, // e5f70633
6238-
TextInputFocusEvent, // 020507e6
6230+
TextInputChangeEvent, // 9e0264a8
6231+
TextInputContentSizeChangeEvent, // c0485b00
6232+
TextInputEndEditingEvent, // 5bab0db2
6233+
TextInputFocusEvent, // acd57d4f
62396234
TextInputIOSProps, // 0d05a855
6240-
TextInputKeyPressEvent, // 3924ad9b
6241-
TextInputProps, // 96c07405
6242-
TextInputSelectionChangeEvent, // d4d10630
6243-
TextInputSubmitEditingEvent, // 22885c31
6244-
TextLayoutEvent, // 73ab173e
6245-
TextProps, // 4c29419c
6235+
TextInputKeyPressEvent, // 3e9cd7e9
6236+
TextInputProps, // 719dad29
6237+
TextInputSelectionChangeEvent, // f4aee983
6238+
TextInputSubmitEditingEvent, // 69f5aed4
6239+
TextLayoutEvent, // 44ce8450
6240+
TextProps, // c5c6ea95
62466241
TextStyle, // bb9b7a58
62476242
ToastAndroid, // 88a8969a
6248-
Touchable, // da3239ee
6249-
TouchableHighlight, // 49bbefe7
6250-
TouchableHighlightProps, // f14a1131
6251-
TouchableNativeFeedback, // d89b59a8
6252-
TouchableNativeFeedbackProps, // a88ade2e
6253-
TouchableOpacity, // 8d1b023b
6254-
TouchableOpacityProps, // 908e84b9
6255-
TouchableWithoutFeedback, // 71d446ec
6256-
TouchableWithoutFeedbackProps, // e0c1c566
6243+
Touchable, // 761abfef
6244+
TouchableHighlight, // c83e68c2
6245+
TouchableHighlightProps, // e1dcb561
6246+
TouchableNativeFeedback, // 44c0e01f
6247+
TouchableNativeFeedbackProps, // 3b815822
6248+
TouchableOpacity, // 2047870f
6249+
TouchableOpacityProps, // e24c059e
6250+
TouchableWithoutFeedback, // 989607ab
6251+
TouchableWithoutFeedbackProps, // d6aa3eec
62576252
TransformsStyle, // 65e70f18
62586253
TurboModule, // dfe29706
62596254
TurboModuleRegistry, // 4ace6db2
62606255
UIManager, // a1a7cc01
62616256
UTFSequence, // ad625158
62626257
Vibration, // 31e4bbf8
6263-
View, // 234d8db5
6264-
ViewProps, // 6d644e8b
6265-
ViewPropsAndroid, // ac650c5c
6258+
View, // d70ecdb5
6259+
ViewProps, // ee6b9e68
6260+
ViewPropsAndroid, // 5f51df6e
62666261
ViewPropsIOS, // 58ee19bf
62676262
ViewStyle, // 00a0f8fb
62686263
VirtualViewMode, // 6be59722
62696264
VirtualizedList, // 68c7345e
6270-
VirtualizedListProps, // 9453ce86
6265+
VirtualizedListProps, // 037e96db
62716266
VirtualizedSectionList, // 9fd9cd61
6272-
VirtualizedSectionListProps, // 7a993da5
6267+
VirtualizedSectionListProps, // 6d45e684
62736268
WrapperComponentProvider, // 9cf3844c
62746269
codegenNativeCommands, // 628a7c0a
6275-
codegenNativeComponent, // 2baac257
6270+
codegenNativeComponent, // 2121cbfd
62766271
findNodeHandle, // 93f80214
62776272
processColor, // 6e877698
62786273
registerCallableModule, // 839c8cfe
6279-
requireNativeComponent, // 7f7f105a
6274+
requireNativeComponent, // 319187c5
62806275
useAnimatedColor, // e3511f81
62816276
useAnimatedValue, // b18adb63
62826277
useAnimatedValueXY, // c7ee2332
62836278
useColorScheme, // d585efdb
6284-
usePressability, // b4e21b46
6279+
usePressability, // 60593cad
62856280
useWindowDimensions, // bb4b683f
62866281
}

packages/react-native/src/private/webapis/dom/nodes/ReactNativeElement.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const noop = () => {};
6767
// was slower than this method because the engine has to create an object than
6868
// we then discard to create a new one.
6969

70+
/** @build-types private-constructor */
7071
class ReactNativeElement extends ReadOnlyElement implements NativeMethods {
7172
// These need to be accessible from `ReactFabricPublicInstanceUtils`.
7273
__nativeTag: number;

0 commit comments

Comments
 (0)