@@ -3,6 +3,7 @@ import 'package:flutter/widgets.dart';
33
44import '../api/model/model.dart' ;
55import '../model/emoji.dart' ;
6+ import '../model/settings.dart' ;
67import 'content.dart' ;
78
89/// A widget showing an emoji.
@@ -13,7 +14,7 @@ class EmojiWidget extends StatelessWidget {
1314 required this .squareDimension,
1415 this .squareDimensionScaler = TextScaler .noScaling,
1516 this .imagePlaceholderStyle = EmojiImagePlaceholderStyle .square,
16- this .neverAnimateImage = false ,
17+ this .imageAnimationMode = ImageAnimationMode .animateConditionally ,
1718 this .buildCustomTextEmoji,
1819 });
1920
@@ -35,11 +36,12 @@ class EmojiWidget extends StatelessWidget {
3536
3637 final EmojiImagePlaceholderStyle imagePlaceholderStyle;
3738
38- /// Whether to show an animated emoji in its still (non-animated) variant
39- /// only, even if device settings permit animation.
39+ /// Whether to show an animated emoji in its still or animated version.
4040 ///
41- /// Defaults to false.
42- final bool neverAnimateImage;
41+ /// Ignored except for animated image emoji.
42+ ///
43+ /// Defaults to [ImageAnimationMode.animateConditionally] .
44+ final ImageAnimationMode imageAnimationMode;
4345
4446 /// An optional callback to specify a custom plain-text emoji style.
4547 ///
@@ -71,7 +73,7 @@ class EmojiWidget extends StatelessWidget {
7173 size: squareDimension,
7274 textScaler: squareDimensionScaler,
7375 errorBuilder: _getImageErrorBuilder (effectiveSquareDimension),
74- neverAnimate : neverAnimateImage ),
76+ animationMode : imageAnimationMode ),
7577 UnicodeEmojiDisplay () => UnicodeEmojiWidget (
7678 size: squareDimension,
7779 emojiDisplay: emojiDisplay),
@@ -189,7 +191,7 @@ class ImageEmojiWidget extends StatelessWidget {
189191 required this .size,
190192 this .textScaler = TextScaler .noScaling,
191193 this .errorBuilder,
192- this .neverAnimate = false ,
194+ this .animationMode = ImageAnimationMode .animateConditionally ,
193195 });
194196
195197 final ImageEmojiDisplay emojiDisplay;
@@ -206,30 +208,20 @@ class ImageEmojiWidget extends StatelessWidget {
206208
207209 final ImageErrorWidgetBuilder ? errorBuilder;
208210
209- /// Whether to show an animated emoji in its still (non-animated) variant
210- /// only, even if device settings permit animation.
211+ /// Whether to show an animated emoji in its still or animated version.
212+ ///
213+ /// Ignored for non-animated emoji.
211214 ///
212- /// Defaults to false .
213- final bool neverAnimate ;
215+ /// Defaults to [ImageAnimationMode.animateConditionally] .
216+ final ImageAnimationMode animationMode ;
214217
215218 @override
216219 Widget build (BuildContext context) {
217- final doNotAnimate =
218- neverAnimate
219- // From reading code, this doesn't actually get set on iOS:
220- // https://github.com/zulip/zulip-flutter/pull/410#discussion_r1408522293
221- || MediaQuery .disableAnimationsOf (context)
222- || (defaultTargetPlatform == TargetPlatform .iOS
223- // TODO(#1924) On iOS 17+ (new in 2023), there's a more closely
224- // relevant setting than "reduce motion". It's called "auto-play
225- // animated images"; we should use that once Flutter exposes it.
226- && WidgetsBinding .instance.platformDispatcher.accessibilityFeatures.reduceMotion);
227-
228220 final size = textScaler.scale (this .size);
229221
230- final resolvedUrl = doNotAnimate
231- ? ( emojiDisplay.resolvedStillUrl ?? emojiDisplay. resolvedUrl)
232- : emojiDisplay.resolvedUrl;
222+ final resolvedUrl = animationMode. resolve (context)
223+ ? emojiDisplay.resolvedUrl
224+ : ( emojiDisplay.resolvedStillUrl ?? emojiDisplay. resolvedUrl) ;
233225
234226 return RealmContentNetworkImage (
235227 width: size, height: size,
0 commit comments