Skip to content

Commit 3ea1b38

Browse files
authored
fix(macos): animated images (GIF) freeze on first frame (#3168)
### Summary: Fixes #3165. On macOS, animated GIFs in `<Image>` show only their first frame. `RCTUIImageViewAnimated` gets its display link from `+[RCTDisplayWeakRefreshable displayLinkWithWeakRefreshable:]`, which makes a weak proxy the link's target. On iOS that is needed because `CADisplayLink` retains its target. On macOS, `RCTPlatformDisplayLink` holds its target weakly, so nothing owns the proxy. It is freed as soon as the method returns, and the link's ticks go to `nil`. **Fix:** on macOS, make the view itself the link's target. The link already holds it weakly, so there is no retain cycle. iOS is unchanged. ### Testing: RNTester (macOS, Fabric) → Image → Animated GIF. On `main` that example is hidden by an RNTester bug that #3164 fixes. https://github.com/user-attachments/assets/4f4e561c-89f3-4082-ae1f-22136c16e6a8 - Before: the GIF stays on its first frame. After: it animates.
1 parent b55c746 commit 3ea1b38

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎packages/react-native/Libraries/Image/RCTDisplayWeakRefreshable.mm‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ @implementation RCTDisplayWeakRefreshable
1111

1212
+ (RCTPlatformDisplayLink *)displayLinkWithWeakRefreshable:(id<RCTDisplayRefreshable>)refreshable // [macOS]
1313
{
14+
#if !TARGET_OS_OSX // [macOS]
1415
RCTDisplayWeakRefreshable *target = [[RCTDisplayWeakRefreshable alloc] initWithRefreshable:refreshable];
1516
return [RCTPlatformDisplayLink displayLinkWithTarget:target selector:@selector(displayDidRefresh:)]; // [macOS]
17+
#else // [macOS
18+
// CADisplayLink retains its target, so on iOS the weak proxy above is needed to avoid a retain cycle.
19+
// RCTPlatformDisplayLink only holds its target weakly, so the proxy would have no owner and be
20+
// deallocated immediately, and the refreshable would never be called. Target the refreshable directly.
21+
return [RCTPlatformDisplayLink displayLinkWithTarget:refreshable selector:@selector(displayDidRefresh:)];
22+
#endif // macOS]
1623
}
1724

1825
- (instancetype)initWithRefreshable:(id<RCTDisplayRefreshable>)refreshable

0 commit comments

Comments
 (0)