Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/react-native/React/Fabric/RCTConversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

#import <cmath>

#import <UIKit/UIKit.h>

#import <React/Graphics.h>
Expand Down Expand Up @@ -152,6 +154,12 @@ inline UIAccessibilityTraits RCTUIAccessibilityTraitsFromAccessibilityTraits(

inline CATransform3D RCTCATransform3DFromTransformMatrix(const facebook::react::Transform &transformMatrix)
{
// Core Animation needs a finite transform: a NaN in one hides the layer and can hide its siblings.
for (const auto value : transformMatrix.matrix) {
if (!std::isfinite(value)) {
return CATransform3DIdentity;
}
}
return {
(CGFloat)transformMatrix.matrix[0],
(CGFloat)transformMatrix.matrix[1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,39 @@ - (void)testHitTestAfterScaleTransitionedToZeroReturnsNil
XCTAssertNil([view hitTest:CGPointMake(50, 50) withEvent:nil]);
}

#pragma mark - non-finite transforms

static RCTViewComponentView *makeViewWithTransform(const Transform &transform)
{
RCTViewComponentView *view = [RCTViewComponentView new];
auto props = std::make_shared<ViewProps>();
props->transform = transform;
[view updateProps:props oldProps:ViewShadowNode::defaultSharedProps()];
return view;
}

- (void)testFiniteTransformIsApplied
{
RCTViewComponentView *view = makeViewWithTransform(Transform::Translate(5, 10, 0));

XCTAssertEqual(view.layer.transform.m41, 5.0);
XCTAssertEqual(view.layer.transform.m42, 10.0);
}

- (void)testTransformWithNaNIsNotApplied
{
RCTViewComponentView *view = makeViewWithTransform(Transform::Translate(NAN, 10, 0));

XCTAssertTrue(CATransform3DIsIdentity(view.layer.transform));
}

- (void)testTransformWithInfinityIsNotApplied
{
RCTViewComponentView *view = makeViewWithTransform(Transform::Scale(INFINITY, 1, 1));

XCTAssertTrue(CATransform3DIsIdentity(view.layer.transform));
}

#pragma mark - Full Keyboard Access focusability

static RCTViewComponentView *makeViewWithRole(bool accessible, const std::string &accessibilityRole)
Expand Down
Loading