-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
87 lines (80 loc) · 2.06 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import {NavigationContainer} from '@react-navigation/native';
import {
createStackNavigator,
StackScreenProps,
TransitionPresets,
} from '@react-navigation/stack';
import React from 'react';
import {useState} from 'react';
import {StyleSheet, Text, View} from 'react-native';
import {Image, SafeAreaView, TouchableOpacity} from 'react-native';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
const Stack = createStackNavigator<any>();
const BuggyImage = () => {
const [loaded, setLoaded] = useState(false);
return (
<>
{!loaded && <Text>Loading</Text>}
<Image
style={style.image}
onLoad={() => setLoaded(true)}
onLoadStart={() => setLoaded(false)} // replacing this line with: 'onError={()=>setLoaded(false)}' will fix the bug
source={{
uri: 'imageurl',
}}
/>
</>
);
};
const Profile = (props: StackScreenProps<any>) => {
return (
<TouchableOpacity
onPress={() => props.navigation.navigate('Settings')}
style={style.profile}>
<BuggyImage />
</TouchableOpacity>
);
};
const Settings = () => {
return <View style={style.settings} />;
};
const App = () => {
return (
<GestureHandlerRootView style={style.flex}>
<SafeAreaView style={style.flex}>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
gestureEnabled: true,
headerShown: false,
...TransitionPresets.SlideFromRightIOS,
}}>
<Stack.Screen name="Profile" component={Profile} />
<Stack.Screen name="Settings" component={Settings} />
</Stack.Navigator>
</NavigationContainer>
</SafeAreaView>
</GestureHandlerRootView>
);
};
const style = StyleSheet.create({
flex: {
flex: 1,
},
settings: {
flex: 1,
backgroundColor: 'blue',
},
profile: {
flex: 1,
backgroundColor: 'red',
alignItems: 'center',
justifyContent: 'center',
},
image: {
width: 50,
height: 50,
position: 'absolute',
},
});
export default App;