Repository navigation
Keep the skew of a 2D matrix transform on Android - #60228
Open
bartlomiejbloniarz wants to merge 1 commit into
Open
bartlomiejbloniarz wants to merge 1 commit into
bartlomiejbloniarz wants to merge 1 commit into
Conversation
A transform: [{matrix}] that skews went through decomposition into View
properties, which have no skew, so Android drew it as a rotated and scaled
rectangle. A 16-element matrix that is 2D affine and whose axes are not
perpendicular now takes the setAnimationMatrix path that skewX/skewY already
use on Android 10+, including skewed hit testing.
The check accepts such a matrix in both SkewMatrixHelper (Kotlin) and
nativeIsAffine2DTransformWithSkew (C++, used for Fabric's arrays), and
buildAffine2DMatrix composes it around the transform origin. Matrices with
perspective, a Z axis or a Z translation, matrices without skew, 9-element
matrices and the raw matrix shorthand from Fabric LayoutAnimations still
decompose as before.
RNTester's Skew example gets a row of the same transforms written as matrices.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
On Android 10 and later,
skewXandskewYare drawn throughView.setAnimationMatrix(#56724). Amatrixtransform never takes that path:SkewMatrixHelper.isAffine2DTransformWithSkewand its C++ counterpart from #59461 reject everymatrix. The matrix is then decomposed into the View's translation, rotation and scale, which cannot express skew. A skewedmatrixtherefore renders as a rotated, scaled rectangle, and touches hit that rectangle. iOS draws the same matrix correctly. Reanimated's shared element transitions animate views with amatrix, so on Android a skewed view loses its skew for the whole transition.A 16-number
matrixthat is 2D affine, and whose X and Y axes are not perpendicular, now takes the samesetAnimationMatrixpath asskewX/skewY. Both the Kotlin check and the C++ check used for Fabric's arrays accept it, andbuildAffine2DMatrixapplies it around the transform origin. Hit testing follows the skewed shape through the existingR.id.skew_animation_matrixtag. These still decompose as before:RNTester's Skew example gets a row with the same transforms written as matrices.
As with
skewXtoday,View.getMatrix()does not include the animation matrix. Native child touch dispatch and accessibility bounds therefore still see the unskewed box.Changelog:
[ANDROID] [FIXED] - Keep the skew of a 2D
matrixtransformTest Plan:
./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests '*SkewMatrixHelperTest*'passes. The new skewed-matrix tests fail without this change.yarn flow-check, ESLint onTransformExample.js,yarn format-check-cppandyarn format-check-kotlinpass.jni/testtests are not built in open source. RNTester's props reach it as Fabric arrays, so the device runs below exercise it.mainvs this PR. In Transforms → Skew, the matrix row now matches the list rows above it. A tap inside the parallelogram but outside the square hits the box, and a tap inside the square but outside the parallelogram misses it. The rotation-only matrix renders the same as before.matrixevery frame through React state, crossing zero skew. With this PR its outline matches the[rotate, skewX]list frame by frame. Its rotate+scale and perspective rows render the same as onmain.Android 15 (API 35)
before-api35-upload.mp4
after-api35-upload.mp4
Android 10 (API 29)
before-api29-upload.mp4
after-api29-upload.mp4
RNTesterPlayground.js: paste intopackages/rn-tester/js/examples/Playground/RNTesterPlayground.jsand open the Playground tab. Tap a cell in the last row to start or stop the animation.