Skip to content
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

Image Component cannot update transform props #23808

Closed
halftrue opened this issue Mar 7, 2019 · 4 comments
Closed

Image Component cannot update transform props #23808

halftrue opened this issue Mar 7, 2019 · 4 comments
Labels
Bug Component: Image Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@halftrue
Copy link

halftrue commented Mar 7, 2019

🐛 Bug Report

Image Component has two way to set transform properties.

  1. just the top level props.
<Image ...some other props transform={[{rotate: '180deg'}]}>
  1. in the style
<Image style={{ transform: [{rotate: '180deg'}] }}>

when you use the first way to set transform, it will fail to setState to update transform props.
while the second works well.

After read source code, I found that in react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js
line 3537

      var shouldUpdate =
        prevProp === undefined ||
        (typeof attributeConfig.diff === "function"
          ? attributeConfig.diff(prevProp, nextProp)
          : defaultDiffer(prevProp, nextProp));

in Situation1: shouldUpdate is false. Situation2 : it is true.

Situation 1

<Image ...someotherprops transform={[{rotate: '180deg'}]}>
the attributeConfig.diff is Matric Differ
which in this case will return false.

Situation 2

<Image style={{ transform: [{rotate: '180deg'}] }}>
the attributeConfig.process has a value of processTransform, which result in below code will excute instead:(bold below)

var shouldUpdate =
        prevProp === undefined ||
        (typeof attributeConfig.diff === "function"
          ? attributeConfig.diff(prevProp, nextProp)
          : **defaultDiffer(prevProp, nextProp));**
      if (shouldUpdate) {
        var _nextValue =
          typeof attributeConfig.process === "function"
            ? attributeConfig.process(nextProp)
            : nextProp;
        (updatePayload || (updatePayload = {}))[propKey] = _nextValue;
      }

In my sight, it is caused by the different value of attributeConfig which retrieves from attributeConfig = validAttributes[propKey];
I checked the propKey, both transform, but they have a different value.

I don't know much about RN, so I can't trace any more about this question.

Expected Behavior

setState should trigger update correctly.

To Reproduce

Just place transform in the top level and try to update it. (only one transform should be set due to the matric diff).

Code Example

I made a small demo.
In this demo, only the second one cannot transform.
DEMO

Environment

React Native Environment Info:
System:
OS: macOS 10.14.3
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Memory: 713.85 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 11.10.1 - /usr/local/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.7.0 - /usr/local/bin/npm
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5056338
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.5.0 => 16.5.0
react-native: https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz => 0.57.1
npmGlobalPackages:
create-react-native-app: 2.0.2

@halftrue halftrue changed the title Image Component got wrong transform props Image Component cannot update transform props Mar 7, 2019
@react-native-bot
Copy link
Collaborator

Thanks for submitting your issue. Can you take another look at your description and make sure the issue template has been filled in its entirety?

👉 Click here if you want to take another look at the Bug Report issue template.

@jayu
Copy link

jayu commented May 30, 2019

It's supposed to work on my android 9 device - Xiamo Mi Mix 2S. Is it still an issue @halftrue? Can you provide a device on which it can be reproduced? Thanks in advance 😃

@stale
Copy link

stale bot commented Aug 28, 2019

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 28, 2019
@stale
Copy link

stale bot commented Sep 4, 2019

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Sep 4, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Component: Image Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

4 participants