mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Leave a view untransformed on iOS when its transform is not finite (#59133)
Summary: A view whose transform holds a `NaN` disappears on iOS, together with the siblings drawn before it. On Android the same view renders untransformed and its siblings are unaffected. I hit it through Reanimated, whose `withTiming` computes a `NaN` for an `undefined` duration, but any transform computed as `NaN` does it. `RCTCATransform3DFromTransformMatrix` copies the resolved matrix into a `CATransform3D` unchecked, so the `NaN` reaches Core Animation. Android's `BaseViewManager` reads each transform value through `sanitizeFloatPropertyValue` first, and on iOS `updateLayoutMetrics` already skips a non-finite frame because a `CALayer` cannot take one. `RCTCATransform3DFromTransformMatrix` now returns the identity for a matrix with a non-finite entry, so `RCTViewComponentView` and the synchronous update in `RCTMountingManager` render the view untransformed, as Android does. ## Changelog: [IOS] [FIXED] - Render a view untransformed when its transform is not finite, instead of hiding it and the siblings drawn before it Pull Request resolved: https://github.com/react/react-native/pull/59133 Test Plan: - `RCTViewComponentViewTests` gains three cases that set a transform through `updateProps`: a translate with `NaN` and a scale with infinity leave the layer's transform at the identity, and a finite translate is applied. I ran `React-RCTFabric`'s test spec on an iPad (iOS 27.0.1), with the spec enabled in RNTester's Podfile locally: all 22 `RCTViewComponentViewTests` pass with this change, and with `main`'s `RCTConversions.h` the `NaN` and infinity cases fail. The spec's one other failure, `RCTTextInputUtilsTest testCopyBackedTextInputPreservesTintColor`, fails the same way on `main` on that device. - RNTester release builds of `main` and of this change on the same iPad, with a root component that renders a build label, a button, a view whose `translateX` becomes `NaN` after mount, and a second view. On `main` only the second view is drawn: the label, the button and the `NaN` view are gone. With this change all four are drawn and the `NaN` view sits untransformed. The before and after are in a comment below. - clang-format 21.1.2 passes on both files. Reviewed By: cipolleschi Differential Revision: D126289250 Pulled By: vzaidman fbshipit-source-id: d94e1aa110ab2d03ab66923dc435c5ef990df557
This commit is contained in:
1 parent
fcd141cf81
commit
a613baf9d1
2 files changed
+41
No files matched your search
@@ -5,6 +5,8 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <cmath>
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import <React/Graphics.h>
|
||||
@@ -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],
|
||||
|
||||
@@ -204,6 +204,39 @@ static Props::Shared makeViewProps(bool removeClippedSubviews)
|
||||
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)
|
||||
|
||||
Reference in new issue
Block a user