Skip to content

Commit

Permalink
Fix crash with snapshot on iOS (software-mansion#4092)
Browse files Browse the repository at this point in the history
## Summary

The `transformMatrix` prop in snapshot is optional and used only for
Shared Transitions. I added a check in the
`prepareDataForLayoutAnimatingWorklet` function to prevent inserting
`nil`s objects.
  • Loading branch information
piaskowyk authored Feb 23, 2023
1 parent 4d3b1af commit 3fd09dd
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions ios/LayoutReanimation/REAAnimationsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -272,24 +272,25 @@ - (NSDictionary *)prepareDataForAnimatingWorklet:(NSMutableDictionary *)values f
- (NSDictionary *)prepareDataForLayoutAnimatingWorklet:(NSMutableDictionary *)currentValues
targetValues:(NSMutableDictionary *)targetValues
{
NSDictionary *preparedData = @{
@"currentWidth" : currentValues[@"width"],
@"currentHeight" : currentValues[@"height"],
@"currentOriginX" : currentValues[@"originX"],
@"currentOriginY" : currentValues[@"originY"],
@"currentGlobalOriginX" : currentValues[@"globalOriginX"],
@"currentGlobalOriginY" : currentValues[@"globalOriginY"],
@"currentTransformMatrix" : currentValues[@"transformMatrix"],
@"targetWidth" : targetValues[@"width"],
@"targetHeight" : targetValues[@"height"],
@"targetOriginX" : targetValues[@"originX"],
@"targetOriginY" : targetValues[@"originY"],
@"targetGlobalOriginX" : targetValues[@"globalOriginX"],
@"targetGlobalOriginY" : targetValues[@"globalOriginY"],
@"targetTransformMatrix" : targetValues[@"transformMatrix"],
@"windowWidth" : currentValues[@"windowWidth"],
@"windowHeight" : currentValues[@"windowHeight"]
};
NSMutableDictionary *preparedData = [NSMutableDictionary new];
preparedData[@"currentWidth"] = currentValues[@"width"];
preparedData[@"currentHeight"] = currentValues[@"height"];
preparedData[@"currentOriginX"] = currentValues[@"originX"];
preparedData[@"currentOriginY"] = currentValues[@"originY"];
preparedData[@"currentGlobalOriginX"] = currentValues[@"globalOriginX"];
preparedData[@"currentGlobalOriginY"] = currentValues[@"globalOriginY"];
preparedData[@"targetWidth"] = targetValues[@"width"];
preparedData[@"targetHeight"] = targetValues[@"height"];
preparedData[@"targetOriginX"] = targetValues[@"originX"];
preparedData[@"targetOriginY"] = targetValues[@"originY"];
preparedData[@"targetGlobalOriginX"] = targetValues[@"globalOriginX"];
preparedData[@"targetGlobalOriginY"] = targetValues[@"globalOriginY"];
preparedData[@"windowWidth"] = currentValues[@"windowWidth"];
preparedData[@"windowHeight"] = currentValues[@"windowHeight"];
if (currentValues[@"transformMatrix"] != nil && targetValues[@"transformMatrix"] != nil) {
preparedData[@"currentTransformMatrix"] = currentValues[@"transformMatrix"];
preparedData[@"targetTransformMatrix"] = targetValues[@"transformMatrix"];
}
return preparedData;
}

Expand Down

0 comments on commit 3fd09dd

Please sign in to comment.