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

Modified VirtualListCell component to enable 'useNativeDriver' as Animated parameter #1304

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alariej
Copy link

@alariej alariej commented Jun 22, 2021

The VirtualListCell component of the VirtualListView extension does not use useNativeDriver: true for Animated styles, resulting in no animations on Android.

This PR modifies the component to use 'useNativeDriver' for animating the 'top' value (moving the cell vertically in the list). The 'width' and 'left' values needed to be moved to a static style, as these values are not supported by 'useNativeDriver' (and it seems to me they were not part of the 'timing' animation anyway).

Tested on a physical device (LG G6 running Android 9).

@ghost
Copy link

ghost commented Jun 22, 2021

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

❌ alariej sign now
You have signed the CLA already but the status is still pending? Let us recheck it.

@erictraut
Copy link
Contributor

Thanks for taking the time to make a contribution.

My understanding is that the native driver supports both "top" and "left". It doesn't make sense that it would support the former but not the latter. Do you have evidence that "left" is not supported?

It makes sense that "width" is not supported by the native animation driver, but I don't think there's any need to animate the width of a cell, since the width is normally unchanged in typical use cases.

@berickson1 wrote much of this code originally, so perhaps he has some thoughts here.

@alariej
Copy link
Author

alariej commented Jun 23, 2021

You are right that 'left' could actually be included in the animation. However, it doesn't seem to be part of the animation in the current VirtualListCell code:

this._topAnimation = RX.Animated.timing(this._topValue, {
   toValue: top,
   duration: 200,
   delay: animationDelay,
   easing: RX.Animated.Easing.InOut(),
});

There is no variable called '_leftAnimation' nor a 'timing' definition for anything but the 'top' value. It could be that 'left' animation was planned in the original concept, but never implemented.

In any case, I wonder if it really makes sense to animate 'left' at all, since a VirtualListView is by definition / inheritance a vertically organized component.

Please let me know what you think. If required, I could either modify this PR, or submit a new PR with the 'left' animation.

Ref: https://github.com/microsoft/reactxp/blob/master/extensions/virtuallistview/src/VirtualListCell.tsx

@alariej
Copy link
Author

alariej commented Jun 23, 2021

Also, this code in VirtualListCell:

// On native platforms, we'll stick with translate[X|Y] because it has a performance advantage.
this._animatedStylePosition = RX.Styles.createAnimatedViewStyle({
   transform: [{
      translateY: this._topValue,
   }],
   left: this._leftValue,
});

'left' is not part of 'transform', and there is no 'translateX' anywhere.

@erictraut
Copy link
Contributor

OK, thanks. The PR looks good to me. Let's give @berickson1 another day to respond. If he doesn't have time to look at it, I'll merge it as is.

Copy link
Collaborator

@berickson1 berickson1 left a comment

Choose a reason for hiding this comment

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

Apologies on the delay, I wrote feedback but never submitted my review. In it's current state, this looks like a breaking change to me since the width and left prop won't be respected beyond the initial size that is provided.

width: this._widthValue,
});
this._staticStylePosition = RX.Styles.createViewStyle({
width: this.props.width,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change will make the width (and left position) of items static after it's first loaded. VLV cells currently support changing widths via a prop. I'm not sure this is a desirable change, at the very least it's a breaking change. Typically width doesn't change on an item in common cases, but I can't speak for all the uses of VLV.

@alariej
Copy link
Author

alariej commented Jun 23, 2021

OK thanks for the feedback @erictraut and @berickson1. Let me take another look at this PR and see if I can come up with a better solution to make it non-breaking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants