-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
The problem
Update react-native-web from 0.12.3 to 0.13.0 broke setNativeProps function, and next call setNativeProps override previously applayed style.
For example. I have component:
<View
ref={viewRef}
style={{ width: 100, height: 100, background: "#333" }}
/>I want to change the style of the component.
Operation:
viewRef.setNativeProps({ style: { width: 200 } });
viewRef.setNativeProps({ style: { height: 200 } })Result in version 0.12.3:
view style = { width: 200, height: 200 }
Result in version 0.13.0 (and newer):
view style = { width: 100, height: 200 }
How to reproduce
Just run both apps
Example in version 0.12.3: https://codesandbox.io/s/rnw-12-y11uy
Example in version 0.13.0: https://codesandbox.io/s/rnw-13-sbuto
Steps to reproduce:
- Run both examples
- Click a couple of times on the button
- Observe differences
Expected behavior
I expect behavior like was in version 0.12.3
Environment (include versions). Did this work in previous versions?
- React Native for Web (version): 0.13.0
- React (version): 17.01
- Browser: 17.01
Additional context
In react-native-reanimated we use setNativeProps to apply changed style during an animation. But after upgrade react-native-web, we have strange issues on the web version if one animation is longer than another component back to the initial style.
Example issue:
- withSpring is behaving weirdly software-mansion/react-native-reanimated#1804
- interpolateColor and withTiming with duration < 250ms dont work in web software-mansion/react-native-reanimated#1450
I made a little investigation and confirmed that setNativeProps doesn't change the initial styles of component:
react-native-web/packages/react-native-web/src/modules/usePlatformMethods/index.js
Lines 29 to 40 in c47bec7
| const nextDomStyle = domProps.style; | |
| if (previousStyleRef.current != null) { | |
| if (domProps.style == null) { | |
| domProps.style = {}; | |
| } | |
| for (const styleName in previousStyleRef.current) { | |
| if (domProps.style[styleName] == null) { | |
| domProps.style[styleName] = ''; | |
| } | |
| } | |
| } |
I can prepare PR to apply changes to the initial style, but I'm not sure how this can affect other components.
Thanks for any help!