Skip to content

Commit

Permalink
Return final animation values to JS when animation completes
Browse files Browse the repository at this point in the history
Summary:
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: d107d3871219dda6ce3aee86aea9b759ac6583eb
  • Loading branch information
genkikondo authored and facebook-github-bot committed Jun 14, 2023
1 parent de6bfec commit 618426e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ - (void)startAnimation

- (void)stopAnimation
{
_valueNode = nil;
if (_callback) {
_callback(@[ @{@"finished" : @(_animationHasFinished)} ]);
_callback(@[ @{@"finished" : @(_animationHasFinished), @"value" : @(_valueNode.value)} ]);
}
_valueNode = nil;
}

- (void)stepAnimationWithTime:(NSTimeInterval)currentTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ - (void)startAnimation

- (void)stopAnimation
{
_valueNode = nil;
if (_callback) {
_callback(@[ @{@"finished" : @(_animationHasFinished)} ]);
_callback(@[ @{@"finished" : @(_animationHasFinished), @"value" : @(_valueNode.value)} ]);
}
_valueNode = nil;
}

- (void)stepAnimationWithTime:(NSTimeInterval)currentTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ - (void)startAnimation

- (void)stopAnimation
{
_valueNode = nil;
if (_callback) {
_callback(@[ @{@"finished" : @(_animationHasFinished)} ]);
_callback(@[ @{@"finished" : @(_animationHasFinished), @"value" : @(_valueNode.value)} ]);
}
_valueNode = nil;
}

- (void)stepAnimationWithTime:(NSTimeInterval)currentTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ - (void)testAnimationCallbackFinish

RCTResponseSenderBlock endCallback = ^(NSArray *response) {
endCallbackCalls++;
XCTAssertEqualObjects(response, @[ @{@"finished" : @YES} ]);
NSArray *expected = @[ @{@"finished" : @YES, @"value" : @1} ];
XCTAssertEqualObjects(response, expected);
};

[_nodesManager startAnimatingNode:@1
Expand Down Expand Up @@ -714,7 +715,8 @@ - (void)testHandleStoppingAnimation

RCTResponseSenderBlock endCallback = ^(NSArray *response) {
endCallbackCalled = YES;
XCTAssertEqualObjects(response, @[ @{@"finished" : @NO} ]);
XCTAssertEqual(response.count, 1);
XCTAssertEqualObjects(response[0][@"finished"], @NO);
};

[_nodesManager startAnimatingNode:@404
Expand Down

0 comments on commit 618426e

Please sign in to comment.