Skip to content

Commit

Permalink
Fixed filtering nested animated styles. (#2202)
Browse files Browse the repository at this point in the history
`flattenArray` function was not used during filtering non-animated props, so when the style property in `Animated.View` was a nested array, the app was crashing. I've changed that so know nested array can be passed as a style property.
  • Loading branch information
jmysliv committed Jul 21, 2021
1 parent 84558ff commit 5a8dedb
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/createAnimatedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function hasAnimatedNodes(value) {

function flattenArray(array) {
if (!Array.isArray(array)) {
return array;
return [array];
}
const resultArr = [];

Expand Down Expand Up @@ -279,10 +279,7 @@ export default function createAnimatedComponent(Component, options = {}) {
}

_attachAnimatedStyles() {
let styles = Array.isArray(this.props.style)
? this.props.style
: [this.props.style];
styles = flattenArray(styles);
const styles = flattenArray(this.props.style);
this._styles = styles;
let viewTag, viewName;
if (Platform.OS === 'web') {
Expand Down Expand Up @@ -453,7 +450,7 @@ export default function createAnimatedComponent(Component, options = {}) {
for (const key in inputProps) {
const value = inputProps[key];
if (key === 'style') {
const styles = Array.isArray(value) ? value : [value];
const styles = flattenArray(value);
const processedStyle = styles.map((style) => {
if (style && style.viewDescriptors) {
// this is how we recognize styles returned by useAnimatedStyle
Expand Down

0 comments on commit 5a8dedb

Please sign in to comment.