Skip to content

Commit b0485be

Browse files
genkikondofacebook-github-bot
authored andcommitted
Return final animation values to JS when animation completes (#37886)
Summary: Pull Request resolved: #37886 When using the native driver for animations that involve layout changes (ie. translateY and other transforms, but not styles such as opacity), because it bypasses Fabric, the new coordinates are not updated so the Pressability responder region/tap target is incorrect **This diff:** - Returning the final values from the native side, at the same place it sets the "finished" flag. This gets sent to JS in `animated/animations/Animation.js`. Changelog: [iOS][Changed] - return animated values to JS for natively driven animations Reviewed By: rshest Differential Revision: D46709214 fbshipit-source-id: f16f36a05cd052d1120ba6e04ec6dd72eb4a98e5
1 parent 875f6a7 commit b0485be

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

packages/react-native/Libraries/NativeAnimation/Drivers/RCTDecayAnimation.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ - (void)startAnimation
7070

7171
- (void)stopAnimation
7272
{
73-
_valueNode = nil;
7473
if (_callback) {
75-
_callback(@[ @{@"finished" : @(_animationHasFinished)} ]);
74+
_callback(@[ @{@"finished" : @(_animationHasFinished), @"value" : @(_valueNode.value)} ]);
7675
}
76+
_valueNode = nil;
7777
}
7878

7979
- (void)stepAnimationWithTime:(NSTimeInterval)currentTime

packages/react-native/Libraries/NativeAnimation/Drivers/RCTFrameAnimation.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ - (void)startAnimation
7676

7777
- (void)stopAnimation
7878
{
79-
_valueNode = nil;
8079
if (_callback) {
81-
_callback(@[ @{@"finished" : @(_animationHasFinished)} ]);
80+
_callback(@[ @{@"finished" : @(_animationHasFinished), @"value" : @(_valueNode.value)} ]);
8281
}
82+
_valueNode = nil;
8383
}
8484

8585
- (void)stepAnimationWithTime:(NSTimeInterval)currentTime

packages/react-native/Libraries/NativeAnimation/Drivers/RCTSpringAnimation.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ - (void)startAnimation
9696

9797
- (void)stopAnimation
9898
{
99-
_valueNode = nil;
10099
if (_callback) {
101-
_callback(@[ @{@"finished" : @(_animationHasFinished)} ]);
100+
_callback(@[ @{@"finished" : @(_animationHasFinished), @"value" : @(_valueNode.value)} ]);
102101
}
102+
_valueNode = nil;
103103
}
104104

105105
- (void)stepAnimationWithTime:(NSTimeInterval)currentTime

packages/rn-tester/RNTesterUnitTests/RCTNativeAnimatedNodesManagerTests.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,8 @@ - (void)testAnimationCallbackFinish
486486

487487
RCTResponseSenderBlock endCallback = ^(NSArray *response) {
488488
endCallbackCalls++;
489-
XCTAssertEqualObjects(response, @[ @{@"finished" : @YES} ]);
489+
NSArray *expected = @[ @{@"finished" : @YES, @"value" : @1} ];
490+
XCTAssertEqualObjects(response, expected);
490491
};
491492

492493
[_nodesManager startAnimatingNode:@1
@@ -714,7 +715,8 @@ - (void)testHandleStoppingAnimation
714715

715716
RCTResponseSenderBlock endCallback = ^(NSArray *response) {
716717
endCallbackCalled = YES;
717-
XCTAssertEqualObjects(response, @[ @{@"finished" : @NO} ]);
718+
XCTAssertEqual(response.count, 1);
719+
XCTAssertEqualObjects(response[0][@"finished"], @NO);
718720
};
719721

720722
[_nodesManager startAnimatingNode:@404

0 commit comments

Comments
 (0)