Remove {eventName}: true from ViewConfig validAttributes

Summary:
For every direct and bubbling event, RCTComponentData (iOS-only) creates a {eventName}: true entry in the component's ViewConfig validAttributes. This entry is unnecessary, and creates a discrepancy between ViewConfigs on iOS vs Android.

This diff removes this entry for all events to:
1. Reduce bloat in native ViewConfigs
2. Create consistency betweeen Android and iOS.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D33303950

fbshipit-source-id: 870c8a2a6d41156ac89bd8554eb09f292bb6108e
This commit is contained in:
Ramanpreet Nara
2022-01-06 19:07:45 -08:00
committed by Facebook GitHub Bot
parent 252b2a63c5
commit ca5aaa7663
7 changed files with 30 additions and 34 deletions
+5
View File
@@ -164,6 +164,11 @@ RCT_EXTERN void RCTEnableTurboModuleSharedMutexInit(BOOL enabled);
RCT_EXTERN BOOL RCTTurboModuleManagerDelegateLockingDisabled(void);
RCT_EXTERN void RCTDisableTurboModuleManagerDelegateLocking(BOOL enabled);
// Turn off validAttribute: entries inside ViewConfigs for events
// TODO(109509380): Remove this gating
RCT_EXTERN BOOL RCTViewConfigEventValidAttributesDisabled(void);
RCT_EXTERN void RCTDisableViewConfigEventValidAttributes(BOOL disabled);
typedef enum {
kRCTGlobalScope,
kRCTGlobalScopeUsingRetainJSCallback,
+12
View File
@@ -162,6 +162,18 @@ void RCTDisableTurboModuleManagerDelegateLocking(BOOL disabled)
turboModuleManagerDelegateLockingDisabled = disabled;
}
// Turn off TurboModule delegate locking
static BOOL viewConfigEventValidAttributesDisabled = NO;
BOOL RCTViewConfigEventValidAttributesDisabled(void)
{
return viewConfigEventValidAttributesDisabled;
}
void RCTDisableViewConfigEventValidAttributes(BOOL disabled)
{
viewConfigEventValidAttributesDisabled = disabled;
}
@interface RCTBridge () <RCTReloadListener>
@end
+10 -2
View File
@@ -428,10 +428,18 @@ static RCTPropBlock createNSInvocationSetter(NSMethodSignature *typeSignature, S
if ([type isEqualToString:@"RCTBubblingEventBlock"]) {
[bubblingEvents addObject:RCTNormalizeInputEventName(name)];
propTypes[name] = @"BOOL";
// TODO(109509380): Remove this gating
if (!RCTViewConfigEventValidAttributesDisabled()) {
propTypes[name] = @"BOOL";
}
} else if ([type isEqualToString:@"RCTDirectEventBlock"]) {
[directEvents addObject:RCTNormalizeInputEventName(name)];
propTypes[name] = @"BOOL";
// TODO(109509380): Remove this gating
if (!RCTViewConfigEventValidAttributesDisabled()) {
propTypes[name] = @"BOOL";
}
} else {
propTypes[name] = type;
}
@@ -45,9 +45,7 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
}
},
validAttributes: {
boolean_default_true_optional_both: true,
onDirectEventDefinedInlineNull: true,
onBubblingEventDefinedInlineNull: true
boolean_default_true_optional_both: true
}
}));
export const Commands = {
@@ -107,9 +105,7 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
}
},
validAttributes: {
boolean_default_true_optional_both: true,
onDirectEventDefinedInlineNull: true,
onBubblingEventDefinedInlineNull: true
boolean_default_true_optional_both: true
}
}));
export const Commands = {
@@ -202,7 +202,6 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
validAttributes: {
disabled: true,
onChange: true,
},
}));
",
@@ -293,12 +292,6 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
validAttributes: {
disabled: true,
onChange: true,
onEventDirect: true,
onEventDirectWithPaperName: true,
onOrientationChange: true,
onEnd: true,
onEventBubblingWithPaperName: true,
},
}));
",
@@ -442,7 +435,6 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
validAttributes: {
title: true,
onChange: true,
},
}));
",
@@ -155,13 +155,6 @@ function normalizeInputEventName(name) {
return name;
}
// Replicates the behavior of viewConfig in RCTComponentData.m
function getValidAttributesForEvents(events) {
return events.map(eventType => {
return j.property('init', j.identifier(eventType.name), j.literal(true));
});
}
function generateBubblingEventInfo(event, nameOveride) {
return j.property(
'init',
@@ -234,7 +227,6 @@ function buildViewConfig(
getReactDiffProcessValue(schemaProp.typeAnnotation),
);
}),
...getValidAttributesForEvents(componentEvents),
]);
const bubblingEventNames = component.events
@@ -291,7 +291,6 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
validAttributes: {
disabled: true,
onChange: true,
},
}));
",
@@ -349,10 +348,6 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
validAttributes: {
disabled: true,
onChange: true,
onEventDirect: true,
onOrientationChange: true,
onEnd: true,
},
}));
",
@@ -408,10 +403,7 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
},
},
validAttributes: {
onChange: true,
onDire tChange: true,
},
validAttributes: {},
}));
",
}
@@ -673,7 +665,6 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
validAttributes: {
accessibilityHint: true,
onChange: true,
},
}));
",