11import * as React from "react" ;
22import { Image , Text , StyleSheet , View } from "react-native" ;
3- import { Swiper , SwiperItem } from "@draftbit/ui" ;
3+ import { Swiper , SwiperItem , Button } from "@draftbit/ui" ;
44import Section , { Container } from "./Section" ;
55
66const style = StyleSheet . create ( {
@@ -10,8 +10,9 @@ const style = StyleSheet.create({
1010 } ,
1111} ) ;
1212
13- function SwiperExample ( { theme } ) {
13+ function SwiperExample ( ) {
1414 const [ data , setData ] = React . useState ( ) ;
15+ const swiperRef = React . useRef ( null ) ;
1516
1617 React . useEffect ( ( ) => {
1718 fetch ( "https://example-data.draftbit.com/properties?_limit=10" )
@@ -22,22 +23,26 @@ function SwiperExample({ theme }) {
2223 } , [ ] ) ;
2324
2425 if ( ! data ) {
25- return < Text > " Loading..." </ Text > ;
26+ return < Text > Loading...</ Text > ;
2627 }
2728
2829 return (
29- < Container >
30- < Section title = "Horizontal Example" >
30+ < Container style = { undefined } >
31+ < Section title = "Horizontal Example" style = { undefined } >
3132 < Swiper
3233 vertical = { false }
3334 loop = { true }
3435 prevTitle = "Previous"
3536 nextTitle = "Next"
3637 style = { { width : "100%" , height : 300 } }
37- onSwipe = { ( index ) => console . log ( "Swiped" , index ) }
38- onSwipedNext = { ( index ) => console . log ( "Swiped next" , index ) }
39- onSwipedPrevious = { ( index ) => console . log ( "Swiped previous" , index ) }
40- onIndexChanged = { ( index ) => console . log ( "onIndexChanged: " , index ) }
38+ onSwipe = { ( index : number ) => console . log ( "Swiped" , index ) }
39+ onSwipedNext = { ( index : number ) => console . log ( "Swiped next" , index ) }
40+ onSwipedPrevious = { ( index : number ) =>
41+ console . log ( "Swiped previous" , index )
42+ }
43+ onIndexChanged = { ( index : number ) =>
44+ console . log ( "onIndexChanged: " , index )
45+ }
4146 >
4247 < SwiperItem style = { [ style . item , { backgroundColor : "#fdd3d3" } ] } >
4348 < Text > Test Slide 1</ Text >
@@ -50,7 +55,7 @@ function SwiperExample({ theme }) {
5055 </ SwiperItem >
5156 </ Swiper >
5257 </ Section >
53- < Section title = "Vertical Example" >
58+ < Section title = "Vertical Example" style = { undefined } >
5459 < Swiper
5560 vertical = { true }
5661 style = { { width : "100%" , height : 300 } }
@@ -64,11 +69,11 @@ function SwiperExample({ theme }) {
6469 < Text > Test Slide 2</ Text >
6570 </ SwiperItem >
6671 < SwiperItem style = { [ style . item , { backgroundColor : "#c9fdd9" } ] } >
67- < Text > Test Slide 2 </ Text >
72+ < Text > Test Slide 3 </ Text >
6873 </ SwiperItem >
6974 </ Swiper >
7075 </ Section >
71- < Section title = "Data-Driven Example" >
76+ < Section title = "Data-Driven Example" style = { undefined } >
7277 < Swiper
7378 vertical = { false }
7479 loop = { true }
@@ -80,8 +85,8 @@ function SwiperExample({ theme }) {
8085 dotActiveColor = "black"
8186 style = { { width : "100%" , height : 300 } }
8287 data = { data }
83- keyExtractor = { ( item ) => item . id }
84- renderItem = { ( { item } ) => (
88+ keyExtractor = { ( item : any ) => item . id }
89+ renderItem = { ( { item } : { item : any } ) => (
8590 < SwiperItem style = { [ style . item , { backgroundColor : "#fdd3d3" } ] } >
8691 < View style = { { alignItems : "center" , justifyContent : "center" } } >
8792 < Image
@@ -95,6 +100,53 @@ function SwiperExample({ theme }) {
95100 ) }
96101 />
97102 </ Section >
103+ < Section title = "Interaction Example" style = { undefined } >
104+ < Swiper
105+ ref = { swiperRef }
106+ vertical = { false }
107+ loop = { true }
108+ style = { { width : "100%" , height : 300 } }
109+ onSwipe = { ( index : number ) => console . log ( "Swiped" , index ) }
110+ onSwipedNext = { ( index : number ) => console . log ( "Swiped next" , index ) }
111+ onSwipedPrevious = { ( index : number ) =>
112+ console . log ( "Swiped previous" , index )
113+ }
114+ onIndexChanged = { ( index : number ) =>
115+ console . log ( "onIndexChanged: " , index )
116+ }
117+ >
118+ < SwiperItem style = { [ style . item , { backgroundColor : "#fdd3d3" } ] } >
119+ < Text > Test Slide 1</ Text >
120+ </ SwiperItem >
121+ < SwiperItem style = { [ style . item , { backgroundColor : "#d6d3fd" } ] } >
122+ < Text > Test Slide 2</ Text >
123+ </ SwiperItem >
124+ < SwiperItem style = { [ style . item , { backgroundColor : "#c9fdd9" } ] } >
125+ < Text > Test Slide 3</ Text >
126+ </ SwiperItem >
127+ </ Swiper >
128+
129+ < View
130+ style = { {
131+ flexDirection : "row" ,
132+ justifyContent : "space-around" ,
133+ marginTop : 10 ,
134+ } }
135+ >
136+ < Button
137+ title = "Swipe Prev"
138+ onPress = { ( ) => swiperRef . current ?. swipePrev ( ) }
139+ />
140+ < Button
141+ title = "Swipe To 1"
142+ onPress = { ( ) => swiperRef . current ?. swipeTo ( 1 ) }
143+ />
144+ < Button
145+ title = "Swipe Next"
146+ onPress = { ( ) => swiperRef . current ?. swipeNext ( ) }
147+ />
148+ </ View >
149+ </ Section >
98150 </ Container >
99151 ) ;
100152}
0 commit comments