Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit 2b86d0c

Browse files
author
featherless
authored
Fix a bug on iOS 14 causing flickers in MDC's ActivityIndicator (#127)
Context: https://github.com/material-components/material-components-ios/issues/10109
1 parent 2cafc9e commit 2b86d0c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/MDMMotionAnimator.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,21 @@ - (void)addAnimation:(CABasicAnimation *)animation
342342
animation.beginTime = ([layer convertTime:CACurrentMediaTime() fromLayer:nil]
343343
+ traits.delay * timeScaleFactor);
344344
animation.fillMode = kCAFillModeBackwards;
345+
} else if (@available(iOS 14, *)) {
346+
// iOS 14 introduced a behavioral change for animations such that they no longer appear to
347+
// immediately be committed to the render server, potentially resulting in a brief flicker to
348+
// the model layer's value before the animation takes effect. This could reasonably be
349+
// considered a bug in iOS.
350+
// To work around this, we can explicitly enforce the contract that this animation is expected
351+
// to start "now" in terms of render server timing. This does mean we may lose some microseconds
352+
// of animation timing at the beginning of the animation, so we only apply this on iOS 14+ where
353+
// it's needed. If and when iOS fixes this bug we can remove the following line and lean on the
354+
// render server choosing the appropriate start time once the animation is flushed to the render
355+
// server.
356+
animation.beginTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
345357
}
346358

359+
347360
[_registrar addAnimation:animation toLayer:layer forKey:key completion:completion];
348361
}
349362

0 commit comments

Comments
 (0)