import {useEffect, useRef, useState} from 'react' import {View} from 'react-native' import PagerView from 'react-native-pager-view' import {type PagerViewOnPageSelectedEvent} from 'react-native-pager-view' import {Image} from 'expo-image' import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' import {atoms as a, tokens, useTheme} from '#/alf' import {Text} from '#/components/Typography' import {PROP_1, PROP_2, PROP_3} from './images' import { Dot, useValuePropText, type ValuePropositionPagerProps, } from './ValuePropositionPager.shared' export function ValuePropositionPager({ step, setStep, avatarUri, }: ValuePropositionPagerProps) { const t = useTheme() const [activePage, setActivePage] = useState(step) const ref = useRef(null) if (step !== activePage) { setActivePage(step) } /* * In an effect rather than inline above: driving the pager is a side effect, * and reading a ref during render is a Rules of React violation. `initialPage` * already covers the first render, so the mount run is a no-op. */ useEffect(() => { ref.current?.setPage(step) }, [step]) const images = [PROP_1[t.name], PROP_2[t.name], PROP_3[t.name]] return ( { const page = evt.nativeEvent.position as 0 | 1 | 2 if (step !== page) { setActivePage(page) setStep(page) } }}> {([0, 1, 2] as const).map(page => ( ))} ) } function Page({ page, image, avatarUri, }: { page: 0 | 1 | 2 image: string avatarUri?: string }) { const {_} = useLingui() const t = useTheme() const {title, description, alt} = useValuePropText(page) return ( {alt} {page === 1 && ( {_(msg`Your )} {title} {description} ) }