Skip to content

Commit da01774

Browse files
feat(example): add large image list example (#1145)
1 parent ea42c3e commit da01774

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

examples/default/src/navigation/HomeStack.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { FlatListScreen } from '../screens/user-steps/FlatListScreen';
1515
import { ComplexViewsScreen } from '../screens/user-steps/ComplexViewsScreen';
1616
import { SectionListScreen } from '../screens/user-steps/SectionListScreen';
1717
import { GesturesScreen } from '../screens/user-steps/GesturesScreen';
18+
import { LargeImageListScreen } from '../screens/user-steps/LargeImageListScreen';
1819
import { SessionReplayScreen } from '../screens/SessionReplayScreen';
1920

2021
export type HomeStackParamList = {
@@ -31,6 +32,7 @@ export type HomeStackParamList = {
3132
ComplexViews: undefined;
3233
SectionList: undefined;
3334
Gestures: undefined;
35+
LargeImageList: undefined;
3436
SessionReplay: undefined;
3537
};
3638

@@ -93,6 +95,11 @@ export const HomeStackNavigator: React.FC = () => {
9395
component={SectionListScreen}
9496
options={{ title: 'Section List' }}
9597
/>
98+
<HomeStack.Screen
99+
name="LargeImageList"
100+
component={LargeImageListScreen}
101+
options={{ title: 'Large Image List' }}
102+
/>
96103
<HomeStack.Screen name="Gestures" component={GesturesScreen} />
97104
</HomeStack.Navigator>
98105
);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React, { useState } from 'react';
2+
import { FlatList, RefreshControl } from 'react-native';
3+
import { Screen } from '../../components/Screen';
4+
import { useDelayedRefresh } from '../../utils/useDelayedRefresh';
5+
import { AspectRatio, Skeleton, Image, Box } from 'native-base';
6+
7+
type ImageItemProps = { link: string };
8+
9+
const LargeImageListItem: React.FC<ImageItemProps> = ({ link }: ImageItemProps) => {
10+
const [isLoading, setLoading] = useState<boolean>(true);
11+
return (
12+
<Box my="2">
13+
<Skeleton h="80" isLoaded={!isLoading} />
14+
<AspectRatio w="100%" ratio={16 / 9}>
15+
<Image
16+
onLoadStart={() => setLoading(true)}
17+
onLoadEnd={() => setLoading(false)}
18+
source={{
19+
uri: link,
20+
}}
21+
alt="image"
22+
/>
23+
</AspectRatio>
24+
</Box>
25+
);
26+
};
27+
28+
export const LargeImageListScreen: React.FC = () => {
29+
const { refreshing, onRefresh } = useDelayedRefresh();
30+
31+
return (
32+
<Screen>
33+
<FlatList<string>
34+
refreshControl={<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />}
35+
data={Array.from(
36+
{ length: 100 },
37+
() =>
38+
`https://picsum.photos/${Math.floor(Math.random() * 200) + 300}/${
39+
Math.floor(Math.random() * 200) + 600
40+
}`,
41+
)}
42+
keyExtractor={(item) => item.toString()}
43+
renderItem={({ item }) => <LargeImageListItem link={item} />}
44+
/>
45+
</Screen>
46+
);
47+
};

examples/default/src/screens/user-steps/UserStepsScreen.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const UserStepsScreen: React.FC<NativeStackScreenProps<HomeStackParamList
1616
<ListTile title="Section List" onPress={() => navigation.navigate('SectionList')} />
1717
<ListTile title="Complex Views" onPress={() => navigation.navigate('ComplexViews')} />
1818
<ListTile title="Gestures" onPress={() => navigation.navigate('Gestures')} />
19+
<ListTile title="Large Image List" onPress={() => navigation.navigate('LargeImageList')} />
1920
</Screen>
2021
);
2122
};

0 commit comments

Comments
 (0)