Do not define default transformOrigin (#52598)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/52598

Defining this as {50%, 50%} mean we do unnecessary work as part of every transform. Instead set it to undefined, which means we'll ignore it when determining the final transform.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D78298587

fbshipit-source-id: 9d3b7375fc3bd9ea04f0a6d7e314fbba0fba6949
This commit is contained in:
Pieter De Baets authored and Facebook GitHub Bot committed 2025-07-15 04:13:15 -07:00
1 parent 7dc84491e9
commit 0d2e0abc45
3 files changed
+43 -9

No files matched your search

@@ -10,9 +10,14 @@
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
import type {HostInstance} from 'react-native';
import ensureInstance from '../../../../src/private/__tests__/utilities/ensureInstance';
import * as Fantom from '@react-native/fantom';
import * as React from 'react';
import {createRef} from 'react';
import {View} from 'react-native';
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
describe('<View>', () => {
describe('width and height style', () => {
@@ -181,6 +186,40 @@ describe('<View>', () => {
<rn-view transform='[{"translateX": 10.000000}]' />,
);
});
[
[undefined, {x: -5, y: 0, width: 20, height: 10}],
['50% 50%', {x: -5, y: 0, width: 20, height: 10}],
['top left', {x: 0, y: 0, width: 20, height: 10}],
['right bottom', {x: -10, y: 0, width: 20, height: 10}],
].forEach(([transformOrigin, expectedBounds]) => {
it(`applies transformOrigin correctly for ${String(transformOrigin)}`, () => {
const root = Fantom.createRoot();
const viewRef = createRef<HostInstance>();
Fantom.runTask(() => {
root.render(
<View
ref={viewRef}
style={{
width: 10,
height: 10,
transform: [{scaleX: 2}],
transformOrigin,
}}
/>,
);
});
const viewElement = ensureInstance(viewRef.current, ReactNativeElement);
const viewBounds = viewElement.getBoundingClientRect();
expect(viewBounds.x).toBe(expectedBounds.x);
expect(viewBounds.y).toBe(expectedBounds.y);
expect(viewBounds.width).toBe(expectedBounds.width);
expect(viewBounds.height).toBe(expectedBounds.height);
});
});
});
describe('props', () => {
@@ -84,14 +84,7 @@ class BaseViewProps : public YogaStylableProps, public AccessibilityProps {
// Transform
Transform transform{};
TransformOrigin transformOrigin{
{
ValueUnit{50.0f, UnitType::Percent},
ValueUnit{50.0f, UnitType::Percent},
},
0.0f,
};
TransformOrigin transformOrigin{};
BackfaceVisibility backfaceVisibility{};
bool shouldRasterize{};
std::optional<int> zIndex{};
@@ -55,7 +55,9 @@ struct TransformOperation {
};
struct TransformOrigin {
std::array<ValueUnit, 2> xy;
std::array<ValueUnit, 2> xy = {
ValueUnit(0.0f, UnitType::Undefined),
ValueUnit(0.0f, UnitType::Undefined)};
float z = 0.0f;
bool operator==(const TransformOrigin& other) const {