Skip to content

Commit 2078913

Browse files
committed
fix: img loading race condition and simplify profile view
1 parent 7693164 commit 2078913

File tree

2 files changed

+19
-44
lines changed

2 files changed

+19
-44
lines changed

mobile/components/OImageWithLoader/OImageWithLoader.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Color } from "@/GlobalStyles";
2-
import React, { useState } from "react";
2+
import React, { useCallback, useState } from "react";
33
import {
44
ActivityIndicator,
55
Image,
@@ -8,18 +8,33 @@ import {
88
View,
99
} from "react-native";
1010

11-
interface OImageWithLoaderProps extends ImageProps {}
11+
interface OImageWithLoaderProps extends ImageProps {
12+
fallbackSource?: ImageProps["source"];
13+
}
1214

1315
export const OImageWithLoader = (props: OImageWithLoaderProps) => {
1416
const [isLoading, setIsLoading] = useState(false);
1517

18+
const handleLoadStart = useCallback(() => {
19+
setIsLoading(true);
20+
}, []);
21+
22+
const handleLoadEnd = useCallback(() => {
23+
setIsLoading(false);
24+
}, []);
25+
26+
const handleError = useCallback(() => {
27+
setIsLoading(false);
28+
}, []);
29+
1630
return (
1731
<View style={[styles.container, props.style]}>
1832
<Image
1933
{...props}
2034
style={[styles.image, props.style]}
21-
onLoadStart={() => setIsLoading(true)}
22-
onLoadEnd={() => setIsLoading(false)}
35+
onLoadStart={handleLoadStart}
36+
onLoadEnd={handleLoadEnd}
37+
onError={handleError}
2338
/>
2439
{isLoading && (
2540
<View style={styles.loaderContainer}>

mobile/screens/main/ProfileView.tsx

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import React, { useEffect, useRef, useState } from "react";
1313
import {
1414
Dimensions,
1515
FlatList,
16-
Modal,
1716
StyleSheet,
1817
Text,
1918
TouchableOpacity,
@@ -32,10 +31,8 @@ const ProfileView = ({
3231
>) => {
3332
const progressValue = useSharedValue<number>(0);
3433
const width = Dimensions.get("window").width;
35-
const [fullScreenVisible, setFullScreenVisible] = useState(false);
3634
const [currentImageIndex, setCurrentImageIndex] = useState(0);
3735
const carouselRef = useRef<ICarouselInstance>(null);
38-
const fullScreenCarouselRef = useRef<ICarouselInstance>(null); // Ref for full-screen carousel
3936

4037
const renderPreviewImage = ({
4138
item,
@@ -49,7 +46,6 @@ const ProfileView = ({
4946
onPress={() => {
5047
setCurrentImageIndex(index);
5148
carouselRef.current?.scrollTo({ index: index });
52-
setFullScreenVisible(true);
5349
}}
5450
style={styles.previewImageContainer}
5551
>
@@ -109,7 +105,6 @@ const ProfileView = ({
109105
<TouchableOpacity
110106
onPress={() => {
111107
setCurrentImageIndex(index);
112-
setFullScreenVisible(true);
113108
}}
114109
>
115110
<OImageWithLoader
@@ -123,7 +118,6 @@ const ProfileView = ({
123118
<TouchableOpacity
124119
style={styles.touchableContainer}
125120
onPress={() => {
126-
setFullScreenVisible(true);
127121
setCurrentImageIndex(0);
128122
}}
129123
>
@@ -164,40 +158,6 @@ const ProfileView = ({
164158
style={styles.previewList}
165159
/>
166160
)}
167-
168-
<Modal
169-
animationType="fade"
170-
transparent={false}
171-
visible={fullScreenVisible}
172-
onRequestClose={() => setFullScreenVisible(false)}
173-
>
174-
<View style={styles.fullScreenContainer}>
175-
<TouchableOpacity
176-
style={styles.closeButton}
177-
onPress={() => setFullScreenVisible(false)}
178-
>
179-
<View style={styles.closeButtonInner}>
180-
<Text style={styles.closeButtonText}>×</Text>
181-
</View>
182-
</TouchableOpacity>
183-
<Carousel
184-
ref={fullScreenCarouselRef}
185-
loop={false}
186-
width={Dimensions.get("window").width}
187-
height={Dimensions.get("window").height}
188-
data={user.imageURIs}
189-
scrollAnimationDuration={1000}
190-
defaultIndex={currentImageIndex}
191-
renderItem={({ item }) => (
192-
<OImageWithLoader
193-
source={{ uri: item }}
194-
style={styles.fullScreenImage}
195-
resizeMode="contain"
196-
/>
197-
)}
198-
/>
199-
</View>
200-
</Modal>
201161
</OPageContainer>
202162
);
203163
};

0 commit comments

Comments
 (0)