|
| 1 | +import 'package:flutter/foundation.dart'; |
| 2 | +import 'package:flutter/widgets.dart'; |
| 3 | + |
| 4 | +import '../model/emoji.dart'; |
| 5 | +import 'content.dart'; |
| 6 | + |
| 7 | +class ImageEmojiWidget extends StatelessWidget { |
| 8 | + const ImageEmojiWidget({ |
| 9 | + super.key, |
| 10 | + required this.emojiDisplay, |
| 11 | + required this.size, |
| 12 | + this.textScaler = TextScaler.noScaling, |
| 13 | + this.errorBuilder, |
| 14 | + }); |
| 15 | + |
| 16 | + final ImageEmojiDisplay emojiDisplay; |
| 17 | + |
| 18 | + /// The base width and height to use for the emoji. |
| 19 | + /// |
| 20 | + /// This will be scaled by [textScaler]. |
| 21 | + final double size; |
| 22 | + |
| 23 | + /// The text scaler to apply to [size]. |
| 24 | + /// |
| 25 | + /// Defaults to [TextScaler.noScaling]. |
| 26 | + final TextScaler textScaler; |
| 27 | + |
| 28 | + final ImageErrorWidgetBuilder? errorBuilder; |
| 29 | + |
| 30 | + @override |
| 31 | + Widget build(BuildContext context) { |
| 32 | + // Some people really dislike animated emoji. |
| 33 | + final doNotAnimate = |
| 34 | + // From reading code, this doesn't actually get set on iOS: |
| 35 | + // https://github.com/zulip/zulip-flutter/pull/410#discussion_r1408522293 |
| 36 | + MediaQuery.disableAnimationsOf(context) |
| 37 | + || (defaultTargetPlatform == TargetPlatform.iOS |
| 38 | + // TODO(upstream) On iOS 17+ (new in 2023), there's a more closely |
| 39 | + // relevant setting than "reduce motion". It's called "auto-play |
| 40 | + // animated images", and we should file an issue to expose it. |
| 41 | + // See GitHub comment linked above. |
| 42 | + && WidgetsBinding.instance.platformDispatcher.accessibilityFeatures.reduceMotion); |
| 43 | + |
| 44 | + final size = textScaler.scale(this.size); |
| 45 | + |
| 46 | + final resolvedUrl = doNotAnimate |
| 47 | + ? (emojiDisplay.resolvedStillUrl ?? emojiDisplay.resolvedUrl) |
| 48 | + : emojiDisplay.resolvedUrl; |
| 49 | + |
| 50 | + return RealmContentNetworkImage( |
| 51 | + width: size, height: size, |
| 52 | + errorBuilder: errorBuilder, |
| 53 | + resolvedUrl); |
| 54 | + } |
| 55 | +} |
0 commit comments