Skip to content

setNativeProps ignores previous style changes #1935

@piaskowyk

Description

@piaskowyk

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:

  1. Run both examples
  2. Click a couple of times on the button
  3. 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:

I made a little investigation and confirmed that setNativeProps doesn't change the initial styles of component:

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!

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions