88 StyleSheet ,
99 Text ,
1010 TouchableNativeFeedback ,
11+ TouchableNativeFeedbackProps ,
1112 TouchableOpacity ,
13+ TouchableOpacityProps ,
1214 View
1315} from "react-native" ;
1416import { ButtonStyle , IntroScreenStyle } from "./ui/Styles" ;
@@ -43,10 +45,13 @@ interface SwipeableContainerProps {
4345 activeSlide ?: EditableValue < Big > ;
4446}
4547
48+ type TouchableProps = TouchableNativeFeedbackProps | TouchableOpacityProps ;
49+
4650declare type Option < T > = T | undefined ;
4751
4852const isAndroidRTL = I18nManager . isRTL && Platform . OS === "android" ;
49- const Touchable = Platform . OS === "android" ? TouchableNativeFeedback : TouchableOpacity ;
53+ const Touchable : React . ComponentType < TouchableProps > =
54+ Platform . OS === "android" ? TouchableNativeFeedback : TouchableOpacity ;
5055
5156const refreshActiveSlideAttribute = ( slides : SlidesType [ ] , activeSlide ?: EditableValue < Big > ) : number => {
5257 if ( activeSlide && activeSlide . status === ValueStatus . Available && slides && slides . length > 0 ) {
@@ -66,12 +71,10 @@ export const SwipeableContainer = (props: SwipeableContainerProps): ReactElement
6671 const [ activeIndex , setActiveIndex ] = useState ( 0 ) ;
6772 const flatList = useRef < FlatList < any > > ( null ) ;
6873
69- useEffect ( ( ) => {
70- const slide = refreshActiveSlideAttribute ( props . slides , props . activeSlide ) ;
71- if ( width && props . activeSlide && props . activeSlide . status === ValueStatus . Available && slide !== activeIndex ) {
72- goToSlide ( slide ) ;
73- }
74- } , [ props . activeSlide , activeIndex , width ] ) ;
74+ const rtlSafeIndex = useCallback (
75+ ( i : number ) : number => ( isAndroidRTL ? props . slides . length - 1 - i : i ) ,
76+ [ props . slides . length ]
77+ ) ;
7578
7679 const goToSlide = useCallback (
7780 ( pageNum : number ) => {
@@ -82,9 +85,16 @@ export const SwipeableContainer = (props: SwipeableContainerProps): ReactElement
8285 } ) ;
8386 }
8487 } ,
85- [ width , flatList ]
88+ [ rtlSafeIndex , width ]
8689 ) ;
8790
91+ useEffect ( ( ) => {
92+ const slide = refreshActiveSlideAttribute ( props . slides , props . activeSlide ) ;
93+ if ( width && props . activeSlide ?. status === ValueStatus . Available && slide !== activeIndex ) {
94+ goToSlide ( slide ) ;
95+ }
96+ } , [ props . activeSlide , activeIndex , width , props . slides , goToSlide ] ) ;
97+
8898 const onNextPress = ( ) : void => {
8999 goToSlide ( activeIndex + 1 ) ;
90100 onSlideChange ( activeIndex + 1 , activeIndex ) ;
@@ -278,11 +288,6 @@ export const SwipeableContainer = (props: SwipeableContainerProps): ReactElement
278288 ) ;
279289 } ;
280290
281- const rtlSafeIndex = useCallback (
282- ( i : number ) : number => ( isAndroidRTL ? props . slides . length - 1 - i : i ) ,
283- [ props . slides . length ]
284- ) ;
285-
286291 const onMomentumScrollEnd = useCallback (
287292 ( event : NativeSyntheticEvent < any > ) => {
288293 const offset = event . nativeEvent . contentOffset . x ;
@@ -314,6 +319,8 @@ export const SwipeableContainer = (props: SwipeableContainerProps): ReactElement
314319 < View style = { styles . flexOne } >
315320 < FlatList
316321 testID = { props . testID }
322+ initialScrollIndex = { refreshActiveSlideAttribute ( props . slides , props . activeSlide ) }
323+ getItemLayout = { ( _ , i ) => ( { length : width , offset : width * i , index : i } ) }
317324 ref = { flatList }
318325 data = { props . slides }
319326 horizontal
0 commit comments