11import * as React from "react" ;
2- import { View } from "react-native" ;
2+ import { ScrollView } from "react-native-gesture-handler " ;
33import type { ICarouselInstance } from "react-native-reanimated-carousel" ;
44import Carousel from "react-native-reanimated-carousel" ;
5+ import { SafeAreaView } from "react-native-safe-area-context" ;
56
67import { SBItem } from "../../components/SBItem" ;
78import SButton from "../../components/SButton" ;
@@ -30,7 +31,7 @@ function Index() {
3031 } as const ) ;
3132
3233 return (
33- < View style = { { flex : 1 } } >
34+ < SafeAreaView edges = { [ "bottom" ] } style = { { flex : 1 } } >
3435 < Carousel
3536 { ...baseOptions }
3637 loop
@@ -44,81 +45,83 @@ function Index() {
4445 onSnapToItem = { index => console . log ( "current index:" , index ) }
4546 renderItem = { ( { index } ) => < SBItem key = { index } index = { index } /> }
4647 />
47- < SButton
48- onPress = { ( ) => {
49- setData ( [ ...new Array ( 5 ) . keys ( ) ] ) ;
50- } }
51- >
52- { "Change the data length to 5" }
53- </ SButton >
54- < SButton
55- onPress = { ( ) => {
56- setData ( [ ...new Array ( 3 ) . keys ( ) ] ) ;
57- } }
58- >
59- { "Change the data length to 3" }
60- </ SButton >
61- < SButton
62- onPress = { ( ) => {
63- setIsVertical ( ! isVertical ) ;
64- } }
65- >
66- { isVertical ? "Set horizontal" : "Set Vertical" }
67- </ SButton >
68- < SButton
69- onPress = { ( ) => {
70- setIsFast ( ! isFast ) ;
71- } }
72- >
73- { isFast ? "NORMAL" : "FAST" }
74- </ SButton >
75- < SButton
76- onPress = { ( ) => {
77- setIsPagingEnabled ( ! isPagingEnabled ) ;
78- } }
79- >
48+ < ScrollView style = { { flex : 1 } } >
49+ < SButton
50+ onPress = { ( ) => {
51+ setData ( [ ...new Array ( 5 ) . keys ( ) ] ) ;
52+ } }
53+ >
54+ { "Change the data length to 5" }
55+ </ SButton >
56+ < SButton
57+ onPress = { ( ) => {
58+ setData ( [ ...new Array ( 3 ) . keys ( ) ] ) ;
59+ } }
60+ >
61+ { "Change the data length to 3" }
62+ </ SButton >
63+ < SButton
64+ onPress = { ( ) => {
65+ setIsVertical ( ! isVertical ) ;
66+ } }
67+ >
68+ { isVertical ? "Set horizontal" : "Set Vertical" }
69+ </ SButton >
70+ < SButton
71+ onPress = { ( ) => {
72+ setIsFast ( ! isFast ) ;
73+ } }
74+ >
75+ { isFast ? "NORMAL" : "FAST" }
76+ </ SButton >
77+ < SButton
78+ onPress = { ( ) => {
79+ setIsPagingEnabled ( ! isPagingEnabled ) ;
80+ } }
81+ >
8082 PagingEnabled:{ isPagingEnabled . toString ( ) }
81- </ SButton >
82- < SButton
83- onPress = { ( ) => {
84- setIsAutoPlay ( ! isAutoPlay ) ;
85- } }
86- >
87- { ElementsText . AUTOPLAY } :{ `${ isAutoPlay } ` }
88- </ SButton >
89- < SButton
90- onPress = { ( ) => {
91- console . log ( ref . current ?. getCurrentIndex ( ) ) ;
92- } }
93- >
83+ </ SButton >
84+ < SButton
85+ onPress = { ( ) => {
86+ setIsAutoPlay ( ! isAutoPlay ) ;
87+ } }
88+ >
89+ { ElementsText . AUTOPLAY } :{ `${ isAutoPlay } ` }
90+ </ SButton >
91+ < SButton
92+ onPress = { ( ) => {
93+ console . log ( ref . current ?. getCurrentIndex ( ) ) ;
94+ } }
95+ >
9496 Log current index
95- </ SButton >
96- < SButton
97- onPress = { ( ) => {
98- setData (
99- data . length === 6
100- ? [ ...new Array ( 8 ) . keys ( ) ]
101- : [ ...new Array ( 6 ) . keys ( ) ] ,
102- ) ;
103- } }
104- >
97+ </ SButton >
98+ < SButton
99+ onPress = { ( ) => {
100+ setData (
101+ data . length === 6
102+ ? [ ...new Array ( 8 ) . keys ( ) ]
103+ : [ ...new Array ( 6 ) . keys ( ) ] ,
104+ ) ;
105+ } }
106+ >
105107 Change data length to:{ data . length === 6 ? 8 : 6 }
106- </ SButton >
107- < SButton
108- onPress = { ( ) => {
109- ref . current ?. scrollTo ( { count : - 1 , animated : true } ) ;
110- } }
111- >
108+ </ SButton >
109+ < SButton
110+ onPress = { ( ) => {
111+ ref . current ?. scrollTo ( { count : - 1 , animated : true } ) ;
112+ } }
113+ >
112114 prev
113- </ SButton >
114- < SButton
115- onPress = { ( ) => {
116- ref . current ?. scrollTo ( { count : 1 , animated : true } ) ;
117- } }
118- >
115+ </ SButton >
116+ < SButton
117+ onPress = { ( ) => {
118+ ref . current ?. scrollTo ( { count : 1 , animated : true } ) ;
119+ } }
120+ >
119121 next
120- </ SButton >
121- </ View >
122+ </ SButton >
123+ </ ScrollView >
124+ </ SafeAreaView >
122125 ) ;
123126}
124127
0 commit comments