Repository navigation
[iOS] Animate the image view clipping mask along with the view bounds - #60253
dileepapeiris wants to merge 4 commits into
Conversation
|
Hi @dileepapeiris! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
cipolleschi
left a comment
There was a problem hiding this comment.
This is overall good, I think that if the layer is not animated [layer animationForKey:@"bounds.size"] will return null.
I wonder if we can add this check earlier, so we can avoid also this work
CGPathRef imageMaskPath = RCTPathCreateWithRoundedRect(subview.bounds, cornerInsets, nil, NO);
[self setMaskLayer:imageMask path:imageMaskPath followingBoundsAnimationOfLayer:subview.layer];
CGPathRelease(imageMaskPath);
altogether.
WDYT?
ffa9aff to
cc7f266
Compare
Thanks, I tried this before replying because it sounded like a nice win, but skipping that block when there is no animation breaks two things.
So "no animation" only means "nothing to animate". The path still has to be set every time. What I did instead is move the I recorded the three versions in the same app (React Native 0.88.1 from source, iPhone 17 Pro simulator on iOS 26.5, Slow Animations on). The app rotates itself at 5 s and 13 s, and the row of images goes from 3 to 2 without animation after each rotation. Upstream, where the gap from #60252 shows during the rotation back to portrait: upstream-run.mp4The early return: the bordered image covers its border from the start, and after the rotation the two images stay cut at their old width: early-return-run.mp4This PR: pr-run.mp4 |
Summary:
When a view clips its content,
RCTViewComponentView.invalidateLayerputs aCAShapeLayermask on everyUIImageViewsubview so the image follows the border radius. The mask is a fresh layer whose path is the image view's bounds at layout time. When the layout change is animated by UIKit, for example during a device rotation, the image view's bounds animate but the mask is already at the final size, so the image is clipped to its final size on the first frame while the view is still animating.This is visible with
<Image>directly and with any library that hosts aUIImageViewin a clipping view (expo/expo#54040 is the same bug throughexpo-image).This change reuses the mask layer that is already installed and, when UIKit has added a
bounds.sizeanimation to the image view's layer, copies that animation onto the mask'spathso the mask follows the view with the same timing.Fixes #60252.
Changelog:
[IOS] [FIXED] - Image views in clipping views are no longer clipped to their final size while a layout animation, such as a rotation, is in progress
Test Plan:
Reproducer: https://github.com/dileepapeiris/react-native-image-rotation-mask-repro (community reproducer template, React Native 0.88.1). The screen has a row of three
<Image resizeMode="cover">inside greenoverflow: 'hidden'items, and a control row with plain views. Rotate the simulator from landscape to portrait with Slow Animations on.Before: the image rows show the green item background on the right for the whole rotation, because the image is already clipped to its portrait width. After: the image fills its item through the whole animation. The control row is unchanged.
Portrait and landscape at rest render identically before and after.
Before and after frames, 0.2 s into the rotation, iPhone 17 Pro simulator, iOS 26.5: