Skip to content

Conversation

tuckerconnelly
Copy link
Contributor

@tuckerconnelly tuckerconnelly commented Nov 19, 2016

Motiviation

Wanted to animate iOS's shadowOffset, which is an object, but AnimatedStyle only ran __getValue one-level deep.

Created a recursive function that walked all the styles and evaluated them.

Test plan

Added shadowOffset to the style props in the end-to-end Animated test

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @janicduplessis and @yungsters to be potential reviewers.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Nov 19, 2016
@mkonicek
Copy link
Contributor

cc @janicduplessis

Does this going to affect perf in all cases when using Animated?

@hramos
Copy link
Contributor

hramos commented Dec 22, 2016

Closing after one month with no activity. @tuckerconnelly ping me if you're still interested in landing this.

@hramos hramos closed this Dec 22, 2016
@mlanter
Copy link
Contributor

mlanter commented Mar 9, 2017

@hramos @janicduplessis @tuckerconnelly I'd love this PR as well.

If performance is a concern perhaps we could whitelist certain props so it doesn't walk all of them or limit the walking to one level deep?

Alternatively, there is a AnimatedValueXY; would a AnimatedValueWidthHeight based off that work?

@janicduplessis
Copy link
Contributor

Performance wise this shouldn't have an impact since almost all styles are not objects. My main concern is that it doesn't work with native animated. It should be possible to make it work and will require changes to AnimatedStyleNode to support Map<string, int | Map>.

I'm fine shipping this if we add a validation that makes sure we don't use useNativeDriver with nested styles.

}
}
return style;
return { ...prev, [curr]: value };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid creating a new object at each iterations and just mutate the initial one.

}
} else {
style[key] = value;
} else if (typeof value === 'object') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will cause issues with Array and null, if I remember correctly both of those will have type object but we don't want to traverse those.

@janicduplessis
Copy link
Contributor

Sorry for not looking at this earlier, if the original author or someone else want to makes the changes from my review and previous comment we could ship this.

facebook-github-bot pushed a commit that referenced this pull request Mar 16, 2017
Summary:
This adds the ability to nest animated styles and is a follow up to #11030 .

**Test plan (required)**
Verify a component with a shadowOffset animation animates.

Example:
```
<Animated.View
  style={{
    shadowOffset: {
      width: 0,
      height: this._pressAnim.interpolate({
        inputRange: [0, 1],
        outputRange: [20, 5],
      }),
    },
  }},
/>

```

![example](https://cloud.githubusercontent.com/assets/19673711/23878825/e29f6ae4-0806-11e7-8650-9cff1f591204.gif)
Closes #12909

Differential Revision: D4723933

fbshipit-source-id: 751d7ceb4f9bb22283fb14a5e597730ffd1d9ff6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants