From c4c8327bbcdbfeb3ccb237e064c23bc6c4d941ea Mon Sep 17 00:00:00 2001 From: Batyr Date: Wed, 15 Mar 2023 02:53:51 +0100 Subject: [PATCH] [playground] `flash-list` added --- src/screens/playground/detailed-screen.tsx | 50 -------- src/screens/playground/flash-list.tsx | 127 +++++++++++++++++++++ 2 files changed, 127 insertions(+), 50 deletions(-) delete mode 100644 src/screens/playground/detailed-screen.tsx create mode 100644 src/screens/playground/flash-list.tsx diff --git a/src/screens/playground/detailed-screen.tsx b/src/screens/playground/detailed-screen.tsx deleted file mode 100644 index bb90834..0000000 --- a/src/screens/playground/detailed-screen.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import React, {useEffect} from 'react'; -import {ScrollView} from 'react-native'; -import {View} from 'react-native-ui-lib'; -import {observer} from 'mobx-react'; -import {useNavigation} from '@react-navigation/native'; -import {NavioScreen} from 'rn-navio'; - -import {services, useServices} from '@app/services'; -import {useAppearance} from '@app/utils/hooks'; -import {NavioSection} from '@app/components/sections/NavioSection'; - -export type Props = { - type?: 'push'; -}; - -export const Example: NavioScreen = observer(({type = 'push'}) => { - useAppearance(); // for Dark Mode - const navigation = useNavigation(); - const {t, navio} = useServices(); - // const {ui} = useStores(); - - // State - - // Methods - - // Start - useEffect(() => { - configureUI(); - }, []); - - // UI Methods - const configureUI = () => { - navigation.setOptions({}); - }; - - // UI Methods - - return ( - - - - - - ); -}); - -Example.options = props => ({ - headerBackTitleStyle: false, - title: `${services.t.do('example.title')} ${(props?.route?.params as Props)?.type ?? ''}`, -}); diff --git a/src/screens/playground/flash-list.tsx b/src/screens/playground/flash-list.tsx new file mode 100644 index 0000000..9a64093 --- /dev/null +++ b/src/screens/playground/flash-list.tsx @@ -0,0 +1,127 @@ +import React, {useEffect, useMemo} from 'react'; +import {Text, View} from 'react-native-ui-lib'; +import {observer} from 'mobx-react'; +import {useNavigation} from '@react-navigation/native'; +import {NavioScreen} from 'rn-navio'; + +import {services, useServices} from '@app/services'; +import {useAppearance} from '@app/utils/hooks'; +import {randomStr} from '@app/utils/help'; +import {FlashList} from '@shopify/flash-list'; +import {Image} from 'expo-image'; +import {Row} from '@app/components/row'; +import formatRelative from 'date-fns/formatRelative'; +import subDays from 'date-fns/subDays'; + +type RowData = { + title: string; + image: string; + description: string; + pics: string[]; +}; + +export type Props = {}; + +export const PlaygroundFlashList: NavioScreen = observer(() => { + useAppearance(); // for Dark Mode + const navigation = useNavigation(); + // const {t, navio} = useServices(); + // const {ui} = useStores(); + + const DATA: RowData[] = useMemo( + () => + Array.from({length: 1000}).map((v, ndx) => ({ + title: `Item ${ndx}`, + image: `https://picsum.photos/200?image=${ndx + 1}`, + description: randomStr(300), + pics: [ + `https://picsum.photos/200?image=${ndx * 89}`, + `https://picsum.photos/200?image=${ndx * 99}`, + ], + })), + [], + ); + + // State + + // Methods + + // Start + useEffect(() => { + configureUI(); + }, []); + + // UI Methods + const configureUI = () => { + navigation.setOptions({}); + }; + + // UI Methods + + return ( + + } + estimatedItemSize={300} + /> + + ); +}); +PlaygroundFlashList.options = { + headerBackTitleStyle: false, + title: `Flash List`, +}; + +const blurhash = + '|rF?hV%2WCj[ayj[a|j[az_NaeWBj@ayfRayfQfQM{M|azj[azf6fQfQfQIpWXofj[ayj[j[fQayWCoeoeaya}j[ayfQa{oLj?j[WVj[ayayj[fQoff7azayj[ayj[j[ayofayayayj[fQj[ayayj[ayfjj[j[ayjuayj['; +const ListItem = ({item}: {item: RowData}) => { + useAppearance(); + + return ( + + + + + + + {item.title} + + + + {formatRelative(subDays(new Date(), 3), new Date())} + + + + + + + {item.description} + + + + {item.pics.map((pic, ndx) => ( + + + + ))} + + + + ); +};