Skip to content

Commit 44e19e3

Browse files
feat: migrate to expo-image (RocketChat#5996)
Co-authored-by: Diego Mello <diegolmello@gmail.com>
1 parent 2439a93 commit 44e19e3

File tree

29 files changed

+295
-271
lines changed

29 files changed

+295
-271
lines changed

android/app/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ dependencies {
196196
}
197197

198198
implementation project(':@react-native-community_viewpager')
199-
// implementation "androidx.core:core-splashscreen:1.0.0"
200199
playImplementation project(':react-native-notifications')
201200
playImplementation "com.google.firebase:firebase-messaging:23.3.1"
202201
playImplementation project(':@react-native-firebase_app')
@@ -205,14 +204,10 @@ dependencies {
205204
implementation project(':watermelondb-jsi')
206205

207206
implementation "com.google.code.gson:gson:2.8.9"
208-
implementation "com.github.bumptech.glide:glide:4.9.0"
209-
annotationProcessor "com.github.bumptech.glide:compiler:4.9.0"
210207
implementation "com.tencent:mmkv-static:1.2.10"
211208
androidTestImplementation('com.wix:detox:+')
212209
implementation 'androidx.appcompat:appcompat:1.1.0'
213210
implementation 'com.facebook.soloader:soloader:0.10.4'
214-
implementation("com.facebook.fresco:animated-gif:2.5.0")
215-
implementation "com.facebook.fresco:imagepipeline-okhttp3:3.1.3"
216211
}
217212

218213
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

android/app/src/main/java/chat/rocket/reactnative/networking/SSLPinningModule.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@
3636

3737
import com.reactnativecommunity.webview.RNCWebViewManager;
3838

39-
import com.dylanvann.fastimage.FastImageOkHttpUrlLoader;
40-
4139
import expo.modules.av.player.datasource.SharedCookiesDataSourceFactory;
4240
import expo.modules.filesystem.FileSystemModule;
41+
import expo.modules.image.okhttp.ExpoImageOkHttpClientGlideModule;
4342

4443
public class SSLPinningModule extends ReactContextBaseJavaModule implements KeyChainAliasCallback {
4544

@@ -98,24 +97,26 @@ public void alias(String alias) {
9897
@ReactMethod
9998
public void setCertificate(String data, Promise promise) {
10099
this.alias = data;
100+
OkHttpClient client = getOkHttpClient();
101101

102102
// HTTP Fetch react-native layer
103103
NetworkingModule.setCustomClientBuilder(new CustomClient());
104104
// Websocket react-native layer
105105
WebSocketModule.setCustomClientBuilder(new CustomClient());
106106
// Image networking react-native layer
107107
ImagePipelineConfig config = OkHttpImagePipelineConfigFactory
108-
.newBuilder(this.reactContext, getOkHttpClient())
108+
.newBuilder(this.reactContext, client)
109109
.build();
110110
Fresco.initialize(this.reactContext, config);
111111
// RNCWebView onReceivedClientCertRequest
112112
RNCWebViewManager.setCertificateAlias(data);
113-
// FastImage Glide network layer
114-
FastImageOkHttpUrlLoader.setOkHttpClient(getOkHttpClient());
113+
115114
// Expo AV network layer
116-
SharedCookiesDataSourceFactory.setOkHttpClient(getOkHttpClient());
115+
SharedCookiesDataSourceFactory.setOkHttpClient(client);
117116
// Expo File System network layer
118-
FileSystemModule.setOkHttpClient(getOkHttpClient());
117+
FileSystemModule.setOkHttpClient(client);
118+
// Expo Image network layer
119+
ExpoImageOkHttpClientGlideModule.Companion.setOkHttpClient(client);
119120

120121
promise.resolve(null);
121122
}

app/containers/Avatar/Avatar.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { View } from 'react-native';
3-
import FastImage from 'react-native-fast-image';
3+
import { Image } from 'expo-image';
44
import Touchable from 'react-native-platform-touchable';
55
import { settings as RocketChatSettings } from '@rocket.chat/sdk';
66

@@ -79,13 +79,13 @@ const Avatar = React.memo(
7979
}
8080

8181
image = (
82-
<FastImage
82+
<Image
8383
style={avatarStyle}
8484
source={{
8585
uri,
86-
headers: RocketChatSettings.customHeaders,
87-
priority: FastImage.priority.high
86+
headers: RocketChatSettings.customHeaders
8887
}}
88+
priority='high'
8989
/>
9090
);
9191
}

app/containers/EmojiPicker/CustomEmoji.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { StyleProp } from 'react-native';
3-
import FastImage, { ImageStyle } from 'react-native-fast-image';
3+
import { Image, ImageStyle } from 'expo-image';
44

55
import { useAppSelector } from '../../lib/hooks';
66
import { ICustomEmoji } from '../../definitions';
@@ -14,13 +14,12 @@ const CustomEmoji = React.memo(
1414
({ emoji, style }: ICustomEmojiProps) => {
1515
const baseUrl = useAppSelector(state => state.server.server);
1616
return (
17-
<FastImage
17+
<Image
1818
style={style}
1919
source={{
20-
uri: `${baseUrl}/emoji-custom/${encodeURIComponent(emoji.name)}.${emoji.extension}`,
21-
priority: FastImage.priority.high
20+
uri: `${baseUrl}/emoji-custom/${encodeURIComponent(emoji.name)}.${emoji.extension}`
2221
}}
23-
resizeMode={FastImage.resizeMode.contain}
22+
contentFit='contain'
2423
/>
2524
);
2625
},

app/containers/ImageViewer/ImageViewer.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { useState } from 'react';
2-
import { LayoutChangeEvent, StyleSheet, StyleProp, ViewStyle, ImageStyle, View } from 'react-native';
2+
import { LayoutChangeEvent, StyleSheet, StyleProp, ViewStyle, View } from 'react-native';
33
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
44
import Animated, { withTiming, useSharedValue, useAnimatedStyle, withSpring } from 'react-native-reanimated';
5-
import FastImage from 'react-native-fast-image';
5+
import { Image, ImageStyle } from 'expo-image';
66

77
import { useTheme } from '../../theme';
88

@@ -114,10 +114,10 @@ export const ImageViewer = ({ uri = '', width, height, ...props }: ImageViewerPr
114114
<View style={[styles.flex, { width, height, backgroundColor: colors.surfaceNeutral }]}>
115115
<GestureDetector gesture={gesture}>
116116
<Animated.View onLayout={onLayout} style={[styles.flex, style]}>
117-
<FastImage
117+
<Image
118118
// @ts-ignore
119119
style={styles.image}
120-
resizeMode='contain'
120+
contentFit='contain'
121121
source={{ uri }}
122122
{...props}
123123
/>

app/containers/Loading/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Animated, {
1010
withSequence,
1111
withTiming
1212
} from 'react-native-reanimated';
13+
import { Image } from 'expo-image';
1314

1415
import { useTheme } from '../../theme';
1516
import EventEmitter from '../../lib/methods/helpers/events';
@@ -19,6 +20,8 @@ export const LOADING_TEST_ID = 'loading';
1920
export const LOADING_BUTTON_TEST_ID = 'loading-button';
2021
export const LOADING_IMAGE_TEST_ID = 'loading-image';
2122

23+
const AnimatedImage = Animated.createAnimatedComponent(Image);
24+
2225
const styles = StyleSheet.create({
2326
container: {
2427
flex: 1,
@@ -27,8 +30,7 @@ const styles = StyleSheet.create({
2730
},
2831
image: {
2932
width: PixelRatio.get() * 40,
30-
height: PixelRatio.get() * 40,
31-
resizeMode: 'contain'
33+
height: PixelRatio.get() * 40
3234
}
3335
});
3436

@@ -114,10 +116,11 @@ const Loading = (): React.ReactElement | null => {
114116
animatedOpacity
115117
]}
116118
/>
117-
<Animated.Image
119+
<AnimatedImage
118120
source={require('../../static/images/logo.png')}
119121
style={[styles.image, animatedScale]}
120122
testID={LOADING_IMAGE_TEST_ID}
123+
contentFit='contain'
121124
/>
122125
</View>
123126
</TouchableWithoutFeedback>

app/containers/MessageComposer/components/Autocomplete/AutocompletePreview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { RectButton } from 'react-native-gesture-handler';
3-
import FastImage from 'react-native-fast-image';
3+
import { Image } from 'expo-image';
44

55
import { IAutocompleteItemProps } from '../../interfaces';
66
import { CustomIcon } from '../../../CustomIcon';
@@ -17,7 +17,7 @@ export const AutocompletePreview = ({ item, onPress }: IAutocompleteItemProps) =
1717
if (item.type === '/preview') {
1818
content =
1919
item.preview.type === 'image' ? (
20-
<FastImage style={styles.previewImage} source={{ uri: item.preview.value }} resizeMode={FastImage.resizeMode.cover} />
20+
<Image style={styles.previewImage} source={{ uri: item.preview.value }} contentFit='cover' />
2121
) : (
2222
<CustomIcon name='attach' size={36} />
2323
);

app/containers/ServerItem/index.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { Pressable, Text, View } from 'react-native';
3-
import FastImage from 'react-native-fast-image';
3+
import { Image } from 'expo-image';
44

55
import Check from '../Check';
66
import styles, { ROW_HEIGHT } from './styles';
@@ -37,18 +37,17 @@ const ServerItem = React.memo(({ item, onPress, onLongPress, hasCheck }: IServer
3737
})}>
3838
<View style={styles.serverItemContainer}>
3939
{item.iconURL ? (
40-
<FastImage
40+
<Image
4141
source={{
42-
uri: item.iconURL,
43-
priority: FastImage.priority.high
42+
uri: item.iconURL
4443
}}
45-
// @ts-ignore TODO: Remove when updating FastImage
46-
defaultSource={defaultLogo}
44+
placeholder={defaultLogo}
4745
style={styles.serverIcon}
4846
onError={() => console.log('err_loading_server_icon')}
47+
contentFit='contain'
4948
/>
5049
) : (
51-
<FastImage source={defaultLogo} style={styles.serverIcon} />
50+
<Image source={defaultLogo} style={styles.serverIcon} contentFit='contain' />
5251
)}
5352
<View style={styles.serverTextContainer}>
5453
<Text numberOfLines={1} style={[styles.serverName, { color: themes[theme].fontTitlesLabels }]}>

app/containers/ServerItem/styles.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ export default StyleSheet.create({
1313
serverIcon: {
1414
width: 44,
1515
height: 44,
16-
borderRadius: 4,
17-
resizeMode: 'contain'
16+
borderRadius: 4
1817
},
1918
serverTextContainer: {
2019
flex: 1,

app/containers/UIKit/Image.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { StyleSheet, View } from 'react-native';
3-
import FastImage from 'react-native-fast-image';
3+
import { Image as ExpoImage } from 'expo-image';
44
import { BlockContext } from '@rocket.chat/ui-kit';
55

66
import ImageContainer from '../message/Components/Attachments/Image';
@@ -24,7 +24,7 @@ const ThumbContext = (args: IThumb) => (
2424
);
2525

2626
export const Thumb = ({ element, size = 88 }: IThumb) => (
27-
<FastImage style={[{ width: size, height: size }, styles.image]} source={{ uri: element?.imageUrl }} />
27+
<ExpoImage style={[{ width: size, height: size }, styles.image]} source={{ uri: element?.imageUrl }} />
2828
);
2929

3030
export const Media = ({ element }: IImage) => {

0 commit comments

Comments
 (0)