-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed setNativeProps for web #2280
Conversation
@@ -43,7 +43,7 @@ export const _updatePropsJS = (updates, viewRef) => { | |||
); | |||
|
|||
if (typeof viewRef._component.setNativeProps === 'function') { | |||
viewRef._component.setNativeProps({ style: rawStyles }); | |||
setNativeProps(viewRef._component, rawStyles); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be viewRef.current._component
?
I was trying to use with next.js and while debugging viewRef._component
is always undefined
@piaskowyk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I thought I installed 2.2.4
I'm seeing this bug on @piaskowyk Is it possible If I revert back to diff --git a/node_modules/react-native-reanimated/lib/reanimated2/js-reanimated/index.web.js b/node_modules/react-native-reanimated/lib/reanimated2/js-reanimated/index.web.js
index 76e1dc0..46aa7bf 100644
--- a/node_modules/react-native-reanimated/lib/reanimated2/js-reanimated/index.web.js
+++ b/node_modules/react-native-reanimated/lib/reanimated2/js-reanimated/index.web.js
@@ -11,7 +11,22 @@ export const _updatePropsJS = (_viewTag, _viewName, updates, viewRef) => {
acc[index][key] = value;
return acc;
}, [{}, {}]);
- viewRef.current._component.setNativeProps({ style: rawStyles });
+ if (typeof viewRef.current._component.setNativeProps === 'function') {
+ viewRef.current._component.setNativeProps({ style: rawStyles });
+ } else if (Object.keys(viewRef.current._component.props).length > 0) {
+ Object.keys(viewRef.current._component.props).forEach((key) => {
+ if (!rawStyles[key]) {
+ return;
+ }
+ const dashedKey = key.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());
+ viewRef.current._component._touchableNode.setAttribute(
+ dashedKey,
+ rawStyles[key]
+ );
+ });
+ } else {
+ console.warn('It is not possible to manipulate component');
+ }
}
};
global._setGlobalConsole = (_val) => { |
@nandorojo with next.js, mount animations with a settimeout around 200ms. With initial render I too saw the same error |
This is also breaking for me on web with the same error as @nandorojo with this component which only uses View and Text. Works on 2.2.3
|
Description
setNativeProps
method was ignoring previously changed style, so before the method call, I merge the current style with the previous one to overcome this issue. Detailed description: necolas/react-native-web#1935Changes
setNativeProps
callScreenshots / GIFs
Before
before.mov
After
after.mov