Skip to content

Commit

Permalink
Remove {eventName}: true from ViewConfig validAttributes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RSNara authored and facebook-github-bot committed Jan 7, 2022
1 parent 252b2a6 commit ca5aaa7
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 34 deletions.
5 changes: 5 additions & 0 deletions React/Base/RCTBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions React/Base/RCTBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 10 additions & 2 deletions React/Views/RCTComponentData.m
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,18 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forShadowView:(RCTShadowV

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
validAttributes: {
disabled: true,
onChange: true,
},
}));
",
Expand Down Expand Up @@ -293,12 +292,6 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
validAttributes: {
disabled: true,
onChange: true,
onEventDirect: true,
onEventDirectWithPaperName: true,
onOrientationChange: true,
onEnd: true,
onEventBubblingWithPaperName: true,
},
}));
",
Expand Down Expand Up @@ -442,7 +435,6 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
validAttributes: {
title: true,
onChange: true,
},
}));
",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -234,7 +227,6 @@ function buildViewConfig(
getReactDiffProcessValue(schemaProp.typeAnnotation),
);
}),
...getValidAttributesForEvents(componentEvents),
]);

const bubblingEventNames = component.events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
validAttributes: {
disabled: true,
onChange: true,
},
}));
",
Expand Down Expand Up @@ -349,10 +348,6 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
validAttributes: {
disabled: true,
onChange: true,
onEventDirect: true,
onOrientationChange: true,
onEnd: true,
},
}));
",
Expand Down Expand Up @@ -408,10 +403,7 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
},
},
validAttributes: {
onChange: true,
onDire tChange: true,
},
validAttributes: {},
}));
",
}
Expand Down Expand Up @@ -673,7 +665,6 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
validAttributes: {
accessibilityHint: true,
onChange: true,
},
}));
",
Expand Down

0 comments on commit ca5aaa7

Please sign in to comment.