Skip to content

Commit bebbb6c

Browse files
authored
hide overflow for gif images on Android (#589)
1 parent 13a8c15 commit bebbb6c

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

android/app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ dependencies {
7878
implementation "com.facebook.react:react-native:+" // From node_modules
7979
implementation project(':react-native-navigation')
8080
implementation project(':react-native-ui-lib')
81-
81+
implementation 'com.facebook.fresco:fresco:2.0.0'
82+
implementation 'com.facebook.fresco:animated-gif:2.0.0'
8283

8384
if (enableHermes) {
8485
def hermesPath = "../../node_modules/hermes-engine/android/";

demo/src/screens/componentScreens/AvatarsScreen.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ const examples = [
7070
iconStyle: {backgroundColor: Colors.yellow20},
7171
},
7272
},
73+
{
74+
title: 'GIF',
75+
size: 48,
76+
imageSource: {
77+
uri: 'https://media.giphy.com/media/3oEdv8elIVRa3daNl6/giphy.gif'
78+
}
79+
},
7380
{
7481
title: 'Invalid Gravatar (see logs)',
7582
label: '🤦',

src/components/image/index.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Image extends PureBaseComponent {
4646
*/
4747
aspectRatio: PropTypes.number,
4848
/**
49-
* The type of overly to place on top of the image. Note: the image MUST have proper size, see examples in:
49+
* The type of overly to place on top of the image. Note: the image MUST have proper size, see examples in:
5050
* https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/OverlaysScreen.js
5151
*/
5252
overlayType: Overlay.propTypes.type
@@ -64,6 +64,20 @@ class Image extends PureBaseComponent {
6464
this.sourceTransformer = this.getThemeProps().sourceTransformer;
6565
}
6666

67+
isGif() {
68+
if (Constants.isAndroid) {
69+
const {source} = this.props;
70+
const url = _.get(source, 'uri');
71+
const isGif = /(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|gif|png)/.test(url);
72+
return isGif;
73+
}
74+
}
75+
76+
shouldUseImageBackground() {
77+
const {overlayType} = this.props;
78+
return !!overlayType || this.isGif();
79+
}
80+
6781
getImageSource() {
6882
const {assetName, assetGroup} = this.props;
6983
if (!_.isUndefined(assetName)) {
@@ -86,14 +100,15 @@ class Image extends PureBaseComponent {
86100
const source = this.getImageSource();
87101
const {tintColor, style, supportRTL, cover, aspectRatio, overlayType, ...others} = this.getThemeProps();
88102
const shouldFlipRTL = supportRTL && Constants.isRTL;
89-
const ImageView = overlayType ? ImageBackground : RNImage;
103+
const ImageView = this.shouldUseImageBackground() ? ImageBackground : RNImage;
90104

91105
return (
92106
<ImageView
93107
style={[
94108
{tintColor},
95109
shouldFlipRTL && styles.rtlFlipped,
96110
cover && styles.coverImage,
111+
this.isGif() && styles.gifImage,
97112
aspectRatio && {aspectRatio},
98113
style
99114
]}
@@ -115,6 +130,9 @@ const styles = StyleSheet.create({
115130
coverImage: {
116131
width: Constants.screenWidth,
117132
aspectRatio: 16 / 8
133+
},
134+
gifImage: {
135+
overflow: 'hidden'
118136
}
119137
});
120138

0 commit comments

Comments
 (0)