1
1
import * as React from "react" ;
2
2
import { Image , Text , StyleSheet , View } from "react-native" ;
3
- import { Swiper , SwiperItem } from "@draftbit/ui" ;
3
+ import { Swiper , SwiperItem , Button } from "@draftbit/ui" ;
4
4
import Section , { Container } from "./Section" ;
5
5
6
6
const style = StyleSheet . create ( {
@@ -10,8 +10,9 @@ const style = StyleSheet.create({
10
10
} ,
11
11
} ) ;
12
12
13
- function SwiperExample ( { theme } ) {
13
+ function SwiperExample ( ) {
14
14
const [ data , setData ] = React . useState ( ) ;
15
+ const swiperRef = React . useRef ( null ) ;
15
16
16
17
React . useEffect ( ( ) => {
17
18
fetch ( "https://example-data.draftbit.com/properties?_limit=10" )
@@ -22,22 +23,26 @@ function SwiperExample({ theme }) {
22
23
} , [ ] ) ;
23
24
24
25
if ( ! data ) {
25
- return < Text > " Loading..." </ Text > ;
26
+ return < Text > Loading...</ Text > ;
26
27
}
27
28
28
29
return (
29
- < Container >
30
- < Section title = "Horizontal Example" >
30
+ < Container style = { undefined } >
31
+ < Section title = "Horizontal Example" style = { undefined } >
31
32
< Swiper
32
33
vertical = { false }
33
34
loop = { true }
34
35
prevTitle = "Previous"
35
36
nextTitle = "Next"
36
37
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
+ }
41
46
>
42
47
< SwiperItem style = { [ style . item , { backgroundColor : "#fdd3d3" } ] } >
43
48
< Text > Test Slide 1</ Text >
@@ -50,7 +55,7 @@ function SwiperExample({ theme }) {
50
55
</ SwiperItem >
51
56
</ Swiper >
52
57
</ Section >
53
- < Section title = "Vertical Example" >
58
+ < Section title = "Vertical Example" style = { undefined } >
54
59
< Swiper
55
60
vertical = { true }
56
61
style = { { width : "100%" , height : 300 } }
@@ -64,11 +69,11 @@ function SwiperExample({ theme }) {
64
69
< Text > Test Slide 2</ Text >
65
70
</ SwiperItem >
66
71
< SwiperItem style = { [ style . item , { backgroundColor : "#c9fdd9" } ] } >
67
- < Text > Test Slide 2 </ Text >
72
+ < Text > Test Slide 3 </ Text >
68
73
</ SwiperItem >
69
74
</ Swiper >
70
75
</ Section >
71
- < Section title = "Data-Driven Example" >
76
+ < Section title = "Data-Driven Example" style = { undefined } >
72
77
< Swiper
73
78
vertical = { false }
74
79
loop = { true }
@@ -80,8 +85,8 @@ function SwiperExample({ theme }) {
80
85
dotActiveColor = "black"
81
86
style = { { width : "100%" , height : 300 } }
82
87
data = { data }
83
- keyExtractor = { ( item ) => item . id }
84
- renderItem = { ( { item } ) => (
88
+ keyExtractor = { ( item : any ) => item . id }
89
+ renderItem = { ( { item } : { item : any } ) => (
85
90
< SwiperItem style = { [ style . item , { backgroundColor : "#fdd3d3" } ] } >
86
91
< View style = { { alignItems : "center" , justifyContent : "center" } } >
87
92
< Image
@@ -95,6 +100,53 @@ function SwiperExample({ theme }) {
95
100
) }
96
101
/>
97
102
</ 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 >
98
150
</ Container >
99
151
) ;
100
152
}
0 commit comments