-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Drive any numerical prop via NativeAnimated #10658
Conversation
By analyzing the blame information on this pull request, we identified @janicduplessis and @kmagiera to be potential reviewers. |
Should we wait for some progress on the native side before shipping this? I think it should (almost) work on Android since we're using UIManager to update props. On iOS we don't so there is quite a bit more work to do for it to work. |
Sure, we can hold off until I have that ready |
3d8070d
to
db18753
Compare
@janicduplessis I updated this to drive any numerical prop on iOS. Note that this depends on #10663. Check out the third and final commit in this diff for my most recent changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also already works on Android?
@@ -82,7 +82,12 @@ - (void)performUpdate | |||
} | |||
} | |||
|
|||
_propsDictionary[@"transform"] = [NSValue valueWithCATransform3D:transform]; | |||
_propsDictionary[@"transform"] = @[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just pass the transform config as is now and do the conversion to CATransform3D
when setting the prop in the UIViewManager. This is what android does now, I think iOS still does some parsing in JS it could be a good opportunity to fix that as well. This would avoid having multiple representations of the transform (Array of objects -> CATransform -> number array -> CATransform). That way we'd always just have Array of objects -> CATransform.
db18753
to
5f2e055
Compare
5f2e055
to
898e90b
Compare
@ryangomba Can you rebase this now that #10663 landed. |
898e90b
to
8da21d8
Compare
@janicduplessis yep, done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just a few changes
@javache Could you also have a look at the iOS part to make sure I didn't overlook anything since it will affect transforms a lot.
|
||
#import "RCTConvert+Transform.h" | ||
|
||
@implementation RCTConvert(CoreLocation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be RCTConvert (Transform)
return transform; | ||
} | ||
if (![json isKindOfClass:[NSArray class]]) { | ||
RCTLogError(@"Expected array for transform matrix"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shoud that also be RCTLogConvertError
?
return transform; | ||
} | ||
if ([json count] != 16) { | ||
RCTLogError(@"Expected 4x4 matrix array, but count is %zd: %@", [json count], json); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
CGFloat rotate = [self convertToRadians:value]; | ||
transform = CATransform3DRotate(transform, rotate, 0, 1, 0); | ||
|
||
} else if ([property isEqualToString:@"rotate"]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to also support rotateZ
in that case.
@ryangomba Could you also try rebasing again to have tests passing, looks like tests are on a bad commit and fail on an invalid packager command. |
8da21d8
to
caf2bed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a huge race condition.
RCTAssertMainQueue(); | ||
RCTComponentData *componentData = _componentDataByName[viewName]; | ||
UIView *view = _viewRegistry[reactTag]; | ||
[componentData setProps:props forView:view]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if some of the props you're changing also need to be set on the shadow view? What if there's pending changes in flight from the shadowqueue to this view? They'll overwrite the ones you just set synchronously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, in what scenario would this be true? No prop should be driven both by the shadow view and a native animation, it's one or the other. Native animated props actually get stripped from the set of props sent to the shadow view; they are mutated independently via this package, completely outside the shadow view hierarchy. It's a limitation for sure, e.g. we can't drive layout props like width or height, but this should be safe from a race.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like you've added that restriction at the Animated ViewManager logic, but this code is not aware of it. I'm worried that 3rd party view manager authors may use this API incorrectly.
Perhaps we could have this use a separate API and in RCTComponentData as well and verify that the props you're setting are main-thread only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you feel that the comment in the header file is insufficient?
/**
* Used by native animated module to bypass the process of updating the values through the shadow
* view hierarchy. This method will directly update native views, which means that updates for
* layout-related propertied won't be handled properly.
* Make sure you know what you're doing before calling this method :)
*/
This warning also exists in the Android codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javache I don't think the current solution is perfect but this is how it is done on Android so I think this is a good first step (vs the adhoc property setter that we had before).
Ideally we'd want to have the normal prop setting mechanism aware of native animated props and use that to properly update views instead of not passing the props at all but I haven't looked at this yet so I'm not sure how this could be implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still a bit worried about this but feel free to go ahead with docs added.
caf2bed
to
18a1e6c
Compare
Summary: This improves JS validations of the transform object and makes it a bit stricter (hence the breaking change). When moving transform objects parsing to native (facebook#10658) the validations got out of sync a bit, this makes sure JS validations are the same or stricter than the native ones to make sure we get consistent errors across platforms. See facebook#12110 for an example of an error that now gets caught by JS validations. Also added snapshot tests for the errors to make sure `processTransform` throws when passing invalid values. It only tests the validation since the object parsing is now done natively for iOS and Android. **Test plan** Test that there are no errors in UIExplorer Run new unit tests Closes facebook#12115 Differential Revision: D4488933 Pulled By: mkonicek fbshipit-source-id: a714e6175b2892284a44c870506165099efec1ed
Summary: In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist. Closes facebook/react-native#10658 Differential Revision: D4379031 Pulled By: ericvicenti fbshipit-source-id: fe9c30ea101e93a8b260d7d09a909fafbb82fee6
Summary: In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist. Closes facebook#10658 Differential Revision: D4379031 Pulled By: ericvicenti fbshipit-source-id: fe9c30ea101e93a8b260d7d09a909fafbb82fee6
Summary: This improves JS validations of the transform object and makes it a bit stricter (hence the breaking change). When moving transform objects parsing to native (facebook#10658) the validations got out of sync a bit, this makes sure JS validations are the same or stricter than the native ones to make sure we get consistent errors across platforms. See facebook#12110 for an example of an error that now gets caught by JS validations. Also added snapshot tests for the errors to make sure `processTransform` throws when passing invalid values. It only tests the validation since the object parsing is now done natively for iOS and Android. **Test plan** Test that there are no errors in UIExplorer Run new unit tests Closes facebook#12115 Differential Revision: D4488933 Pulled By: mkonicek fbshipit-source-id: a714e6175b2892284a44c870506165099efec1ed
Summary: In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist. Closes facebook#10658 Differential Revision: D4379031 Pulled By: ericvicenti fbshipit-source-id: fe9c30ea101e93a8b260d7d09a909fafbb82fee6
Summary: This improves JS validations of the transform object and makes it a bit stricter (hence the breaking change). When moving transform objects parsing to native (facebook#10658) the validations got out of sync a bit, this makes sure JS validations are the same or stricter than the native ones to make sure we get consistent errors across platforms. See facebook#12110 for an example of an error that now gets caught by JS validations. Also added snapshot tests for the errors to make sure `processTransform` throws when passing invalid values. It only tests the validation since the object parsing is now done natively for iOS and Android. **Test plan** Test that there are no errors in UIExplorer Run new unit tests Closes facebook#12115 Differential Revision: D4488933 Pulled By: mkonicek fbshipit-source-id: a714e6175b2892284a44c870506165099efec1ed
Summary: In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist. Closes facebook#10658 Differential Revision: D4379031 Pulled By: ericvicenti fbshipit-source-id: fe9c30ea101e93a8b260d7d09a909fafbb82fee6
Summary: This improves JS validations of the transform object and makes it a bit stricter (hence the breaking change). When moving transform objects parsing to native (facebook#10658) the validations got out of sync a bit, this makes sure JS validations are the same or stricter than the native ones to make sure we get consistent errors across platforms. See facebook#12110 for an example of an error that now gets caught by JS validations. Also added snapshot tests for the errors to make sure `processTransform` throws when passing invalid values. It only tests the validation since the object parsing is now done natively for iOS and Android. **Test plan** Test that there are no errors in UIExplorer Run new unit tests Closes facebook#12115 Differential Revision: D4488933 Pulled By: mkonicek fbshipit-source-id: a714e6175b2892284a44c870506165099efec1ed
Summary: In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist. Closes facebook#10658 Differential Revision: D4379031 Pulled By: ericvicenti fbshipit-source-id: fe9c30ea101e93a8b260d7d09a909fafbb82fee6
Summary: This improves JS validations of the transform object and makes it a bit stricter (hence the breaking change). When moving transform objects parsing to native (facebook#10658) the validations got out of sync a bit, this makes sure JS validations are the same or stricter than the native ones to make sure we get consistent errors across platforms. See facebook#12110 for an example of an error that now gets caught by JS validations. Also added snapshot tests for the errors to make sure `processTransform` throws when passing invalid values. It only tests the validation since the object parsing is now done natively for iOS and Android. **Test plan** Test that there are no errors in UIExplorer Run new unit tests Closes facebook#12115 Differential Revision: D4488933 Pulled By: mkonicek fbshipit-source-id: a714e6175b2892284a44c870506165099efec1ed
Summary: In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist. Closes facebook#10658 Differential Revision: D4379031 Pulled By: ericvicenti fbshipit-source-id: fe9c30ea101e93a8b260d7d09a909fafbb82fee6
Summary: This improves JS validations of the transform object and makes it a bit stricter (hence the breaking change). When moving transform objects parsing to native (facebook#10658) the validations got out of sync a bit, this makes sure JS validations are the same or stricter than the native ones to make sure we get consistent errors across platforms. See facebook#12110 for an example of an error that now gets caught by JS validations. Also added snapshot tests for the errors to make sure `processTransform` throws when passing invalid values. It only tests the validation since the object parsing is now done natively for iOS and Android. **Test plan** Test that there are no errors in UIExplorer Run new unit tests Closes facebook#12115 Differential Revision: D4488933 Pulled By: mkonicek fbshipit-source-id: a714e6175b2892284a44c870506165099efec1ed
Summary: In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist. Closes facebook#10658 Differential Revision: D4379031 Pulled By: ericvicenti fbshipit-source-id: fe9c30ea101e93a8b260d7d09a909fafbb82fee6
Summary: This improves JS validations of the transform object and makes it a bit stricter (hence the breaking change). When moving transform objects parsing to native (facebook#10658) the validations got out of sync a bit, this makes sure JS validations are the same or stricter than the native ones to make sure we get consistent errors across platforms. See facebook#12110 for an example of an error that now gets caught by JS validations. Also added snapshot tests for the errors to make sure `processTransform` throws when passing invalid values. It only tests the validation since the object parsing is now done natively for iOS and Android. **Test plan** Test that there are no errors in UIExplorer Run new unit tests Closes facebook#12115 Differential Revision: D4488933 Pulled By: mkonicek fbshipit-source-id: a714e6175b2892284a44c870506165099efec1ed
Summary: In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist. Closes facebook#10658 Differential Revision: D4379031 Pulled By: ericvicenti fbshipit-source-id: fe9c30ea101e93a8b260d7d09a909fafbb82fee6
Summary: This improves JS validations of the transform object and makes it a bit stricter (hence the breaking change). When moving transform objects parsing to native (facebook#10658) the validations got out of sync a bit, this makes sure JS validations are the same or stricter than the native ones to make sure we get consistent errors across platforms. See facebook#12110 for an example of an error that now gets caught by JS validations. Also added snapshot tests for the errors to make sure `processTransform` throws when passing invalid values. It only tests the validation since the object parsing is now done natively for iOS and Android. **Test plan** Test that there are no errors in UIExplorer Run new unit tests Closes facebook#12115 Differential Revision: D4488933 Pulled By: mkonicek fbshipit-source-id: a714e6175b2892284a44c870506165099efec1ed
Summary: In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist. Closes facebook#10658 Differential Revision: D4379031 Pulled By: ericvicenti fbshipit-source-id: fe9c30ea101e93a8b260d7d09a909fafbb82fee6
Summary: This improves JS validations of the transform object and makes it a bit stricter (hence the breaking change). When moving transform objects parsing to native (facebook#10658) the validations got out of sync a bit, this makes sure JS validations are the same or stricter than the native ones to make sure we get consistent errors across platforms. See facebook#12110 for an example of an error that now gets caught by JS validations. Also added snapshot tests for the errors to make sure `processTransform` throws when passing invalid values. It only tests the validation since the object parsing is now done natively for iOS and Android. **Test plan** Test that there are no errors in UIExplorer Run new unit tests Closes facebook#12115 Differential Revision: D4488933 Pulled By: mkonicek fbshipit-source-id: a714e6175b2892284a44c870506165099efec1ed
Summary: In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist. Closes facebook#10658 Differential Revision: D4379031 Pulled By: ericvicenti fbshipit-source-id: fe9c30ea101e93a8b260d7d09a909fafbb82fee6
Summary: This improves JS validations of the transform object and makes it a bit stricter (hence the breaking change). When moving transform objects parsing to native (facebook#10658) the validations got out of sync a bit, this makes sure JS validations are the same or stricter than the native ones to make sure we get consistent errors across platforms. See facebook#12110 for an example of an error that now gets caught by JS validations. Also added snapshot tests for the errors to make sure `processTransform` throws when passing invalid values. It only tests the validation since the object parsing is now done natively for iOS and Android. **Test plan** Test that there are no errors in UIExplorer Run new unit tests Closes facebook#12115 Differential Revision: D4488933 Pulled By: mkonicek fbshipit-source-id: a714e6175b2892284a44c870506165099efec1ed
Summary: In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist. Closes facebook#10658 Differential Revision: D4379031 Pulled By: ericvicenti fbshipit-source-id: fe9c30ea101e93a8b260d7d09a909fafbb82fee6
Summary: In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist. Closes facebook#10658 Differential Revision: D4379031 Pulled By: ericvicenti fbshipit-source-id: fe9c30ea101e93a8b260d7d09a909fafbb82fee6
Summary: In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist. Closes facebook#10658 Differential Revision: D4379031 Pulled By: ericvicenti fbshipit-source-id: fe9c30ea101e93a8b260d7d09a909fafbb82fee6
Summary: In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist. Closes facebook#10658 Differential Revision: D4379031 Pulled By: ericvicenti fbshipit-source-id: fe9c30ea101e93a8b260d7d09a909fafbb82fee6
Summary: In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist. Closes facebook#10658 Differential Revision: D4379031 Pulled By: ericvicenti fbshipit-source-id: fe9c30ea101e93a8b260d7d09a909fafbb82fee6
Summary: This improves JS validations of the transform object and makes it a bit stricter (hence the breaking change). When moving transform objects parsing to native (facebook#10658) the validations got out of sync a bit, this makes sure JS validations are the same or stricter than the native ones to make sure we get consistent errors across platforms. See facebook#12110 for an example of an error that now gets caught by JS validations. Also added snapshot tests for the errors to make sure `processTransform` throws when passing invalid values. It only tests the validation since the object parsing is now done natively for iOS and Android. **Test plan** Test that there are no errors in UIExplorer Run new unit tests Closes facebook#12115 Differential Revision: D4488933 Pulled By: mkonicek fbshipit-source-id: a714e6175b2892284a44c870506165099efec1ed
Summary: In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist. Closes facebook#10658 Differential Revision: D4379031 Pulled By: ericvicenti fbshipit-source-id: fe9c30ea101e93a8b260d7d09a909fafbb82fee6
Summary: This improves JS validations of the transform object and makes it a bit stricter (hence the breaking change). When moving transform objects parsing to native (facebook#10658) the validations got out of sync a bit, this makes sure JS validations are the same or stricter than the native ones to make sure we get consistent errors across platforms. See facebook#12110 for an example of an error that now gets caught by JS validations. Also added snapshot tests for the errors to make sure `processTransform` throws when passing invalid values. It only tests the validation since the object parsing is now done natively for iOS and Android. **Test plan** Test that there are no errors in UIExplorer Run new unit tests Closes facebook#12115 Differential Revision: D4488933 Pulled By: mkonicek fbshipit-source-id: a714e6175b2892284a44c870506165099efec1ed
Summary: This fixes a bug that causes properties to keep stale values because they were not restored to their default after being removed when their value was controlled by native animated. To fix this we restore default values in `disconnectFromView` by updating views with null values for all props that we modified previously. However this causes another issue where we lose any props that were set by the normal process because NativeAnimated operations are always executed after UIManager operatations. To fix this I added a way to hook into UIManager view updating process to be able to execute NativeAnimated operations either before or after updating native views. In the case of disconnecting we want to do it before updating views so that it does: Value changed by native animated -> value restored to default -> (optional) value updated by normal prop. This PR also depends on #10658. **Test plan** Tested that this fixed a particular bug in an app that uses ex-navigation + native animations where a navbar w Closes #11819 Differential Revision: D4752566 Pulled By: javache fbshipit-source-id: 68ee28200ffeba859ae1b98ac753bd7dcb8910f0
Summary: This fixes a bug that causes properties to keep stale values because they were not restored to their default after being removed when their value was controlled by native animated. To fix this we restore default values in `disconnectFromView` by updating views with null values for all props that we modified previously. However this causes another issue where we lose any props that were set by the normal process because NativeAnimated operations are always executed after UIManager operatations. To fix this I added a way to hook into UIManager view updating process to be able to execute NativeAnimated operations either before or after updating native views. In the case of disconnecting we want to do it before updating views so that it does: Value changed by native animated -> value restored to default -> (optional) value updated by normal prop. This PR also depends on facebook#10658. **Test plan** Tested that this fixed a particular bug in an app that uses ex-navigation + native animations where a navbar w Closes facebook#11819 Differential Revision: D4752566 Pulled By: javache fbshipit-source-id: 68ee28200ffeba859ae1b98ac753bd7dcb8910f0
In theory, we should be able to animate any non-layout property, including custom ones. While there is still work to be done on the native side to fully enable this, we should start by dropping the prop whitelist.