Skip to content

Commit

Permalink
Patch setNativeProps in OSS build
Browse files Browse the repository at this point in the history
Summary:
changelog: [internal]

`setNativeProps` have been implemented in Fabric but require a React change to be accessible from JavaScript components. For React sync to be imported in OSS builds, React needs to have have a new release in NPM.
To work around this limitation, I manually copied over lines of code that glue together setNativeProps to OSS build.

Reviewed By: cortinico, cipolleschi

Differential Revision: D44216496

fbshipit-source-id: b34b598c1a317bdc03cc5a4cadb3f7c610059709
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Mar 20, 2023
1 parent 8c01b56 commit 7b916be
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3419,6 +3419,23 @@ function mountSafeCallback_NOT_REALLY_SAFE(context, callback) {
return callback.apply(context, arguments);
};
}
function warnForStyleProps(props, validAttributes) {
{
for (var key in validAttributes.style) {
if (!(validAttributes[key] || props[key] === undefined)) {
error(
"You are setting the style `{ %s" +
": ... }` as a prop. You " +
"should nest it in a style object. " +
"E.g. `{ style: { %s" +
": ... } }`",
key,
key
);
}
}
}
}

// Modules provided by RN:
var emptyObject = {};
Expand Down Expand Up @@ -5100,7 +5117,8 @@ var _nativeFabricUIManage = nativeFabricUIManager,
FabricDefaultPriority = _nativeFabricUIManage.unstable_DefaultEventPriority,
FabricDiscretePriority = _nativeFabricUIManage.unstable_DiscreteEventPriority,
fabricGetCurrentEventPriority =
_nativeFabricUIManage.unstable_getCurrentEventPriority;
_nativeFabricUIManage.unstable_getCurrentEventPriority,
_setNativeProps = _nativeFabricUIManage.setNativeProps;
var getViewConfigForType =
ReactNativePrivateInterface.ReactNativeViewConfigRegistry.get; // Counter for uniquely identifying views.
// % 10 === 1 means it is a rootTag.
Expand Down Expand Up @@ -5199,10 +5217,15 @@ var ReactFabricHostComponent = /*#__PURE__*/ (function() {

_proto.setNativeProps = function setNativeProps(nativeProps) {
{
error("Warning: setNativeProps is not currently supported in Fabric");
warnForStyleProps(nativeProps, this.viewConfig.validAttributes);
}

return;
var updatePayload = create(nativeProps, this.viewConfig.validAttributes);
var stateNode = this._internalInstanceHandle.stateNode;

if (stateNode != null && updatePayload != null) {
_setNativeProps(stateNode.node, updatePayload);
}
}; // This API (addEventListener, removeEventListener) attempts to adhere to the
// w3 Level2 Events spec as much as possible, treating HostComponent as a DOM node.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,7 @@ var _nativeFabricUIManage = nativeFabricUIManager,
FabricDiscretePriority = _nativeFabricUIManage.unstable_DiscreteEventPriority,
fabricGetCurrentEventPriority =
_nativeFabricUIManage.unstable_getCurrentEventPriority,
_setNativeProps = _nativeFabricUIManage.setNativeProps,
getViewConfigForType =
ReactNativePrivateInterface.ReactNativeViewConfigRegistry.get,
nextReactTag = 2;
Expand Down Expand Up @@ -1979,7 +1980,18 @@ var ReactFabricHostComponent = (function() {
);
}
};
_proto.setNativeProps = function() {};
_proto.setNativeProps = function(nativeProps) {
nativeProps = diffProperties(
null,
emptyObject,
nativeProps,
this.viewConfig.validAttributes
);
var stateNode = this._internalInstanceHandle.stateNode;
null != stateNode &&
null != nativeProps &&
_setNativeProps(stateNode.node, nativeProps);
};
_proto.addEventListener_unstable = function(eventType, listener, options) {
if ("string" !== typeof eventType)
throw Error("addEventListener_unstable eventType must be a string");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,7 @@ var _nativeFabricUIManage = nativeFabricUIManager,
FabricDiscretePriority = _nativeFabricUIManage.unstable_DiscreteEventPriority,
fabricGetCurrentEventPriority =
_nativeFabricUIManage.unstable_getCurrentEventPriority,
_setNativeProps = _nativeFabricUIManage.setNativeProps,
getViewConfigForType =
ReactNativePrivateInterface.ReactNativeViewConfigRegistry.get,
nextReactTag = 2;
Expand Down Expand Up @@ -2038,7 +2039,18 @@ var ReactFabricHostComponent = (function() {
);
}
};
_proto.setNativeProps = function() {};
_proto.setNativeProps = function(nativeProps) {
nativeProps = diffProperties(
null,
emptyObject,
nativeProps,
this.viewConfig.validAttributes
);
var stateNode = this._internalInstanceHandle.stateNode;
null != stateNode &&
null != nativeProps &&
_setNativeProps(stateNode.node, nativeProps);
};
_proto.addEventListener_unstable = function(eventType, listener, options) {
if ("string" !== typeof eventType)
throw Error("addEventListener_unstable eventType must be a string");
Expand Down

0 comments on commit 7b916be

Please sign in to comment.