1
1
import _ from 'lodash' ;
2
2
import React , { Component } from 'react' ;
3
3
import { StyleSheet , ScrollView } from 'react-native' ;
4
- import { Constants , Spacings , View , Text , Carousel , Image , Colors } from 'react-native-ui-lib' ;
5
- import { renderBooleanOption , renderSliderOption } from '../ExampleScreenPresenter' ;
6
-
4
+ import {
5
+ Constants ,
6
+ Spacings ,
7
+ View ,
8
+ Text ,
9
+ Carousel ,
10
+ Image ,
11
+ Colors
12
+ } from 'react-native-ui-lib' ;
13
+ import {
14
+ renderBooleanOption ,
15
+ renderSliderOption
16
+ } from '../ExampleScreenPresenter' ;
7
17
8
18
const INITIAL_PAGE = 2 ;
9
19
const IMAGES = [
10
- 'https://images.pexels.com/photos/1212487/pexels-photo-1212487.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260' ,
11
- 'https://images.pexels.com/photos/1366630/pexels-photo-1366630.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500' ,
12
- 'https://images.pexels.com/photos/1477459/pexels-photo-1477459.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260' ,
13
- 'https://images.pexels.com/photos/60597/dahlia-red-blossom-bloom-60597.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260'
20
+ 'https://images.pexels.com/photos/2529159/pexels-photo-2529159.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500' ,
21
+ 'https://images.pexels.com/photos/2529146/pexels-photo-2529146.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500' ,
22
+ 'https://images.pexels.com/photos/2529158/pexels-photo-2529158.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500'
14
23
] ;
15
24
const BACKGROUND_COLORS = [
16
25
Colors . red50 ,
@@ -49,19 +58,22 @@ class CarouselScreen extends Component {
49
58
50
59
onOrientationChange = ( ) => {
51
60
if ( this . state . orientation !== Constants . orientation ) {
52
- this . setState ( { orientation : Constants . orientation , width : this . getWidth ( ) } ) ;
61
+ this . setState ( {
62
+ orientation : Constants . orientation ,
63
+ width : this . getWidth ( )
64
+ } ) ;
53
65
}
54
66
} ;
55
67
56
68
getWidth = ( ) => {
57
69
return Constants . windowWidth - Spacings . s5 * 2 ;
58
- }
70
+ } ;
59
71
60
- onChangePage = currentPage => {
72
+ onChangePage = ( currentPage ) => {
61
73
this . setState ( { currentPage} ) ;
62
74
} ;
63
75
64
- onPagePress = index => {
76
+ onPagePress = ( index ) => {
65
77
this . carousel . goToPage ( index , true ) ;
66
78
} ;
67
79
@@ -70,25 +82,36 @@ class CarouselScreen extends Component {
70
82
71
83
return (
72
84
< ScrollView showsVerticalScrollIndicator = { false } >
73
- < Text text30 margin-20 > Carousel</ Text >
85
+ < Text h1 margin-20 >
86
+ Carousel
87
+ </ Text >
74
88
75
89
< View marginH-20 marginB-20 >
76
- { renderBooleanOption . call ( this , 'Limit number of pages shown in page control' , 'limitShownPages' ) }
77
- { renderBooleanOption . call ( this , 'autoplay' , 'autoplay' ) }
78
- { renderSliderOption . call ( this , 'Number of pages shown' , 'numberOfPagesShown' , {
79
- min : 5 ,
80
- max : 10 ,
81
- step : 1 ,
82
- initial : 7
83
- } ) }
90
+ { renderBooleanOption . call (
91
+ this ,
92
+ 'Limit number of pages shown in page control' ,
93
+ 'limitShownPages'
94
+ ) }
95
+ { renderBooleanOption . call ( this , 'autoplay' , 'autoplay' ) }
96
+ { renderSliderOption . call (
97
+ this ,
98
+ 'Number of pages shown' ,
99
+ 'numberOfPagesShown' ,
100
+ {
101
+ min : 5 ,
102
+ max : 10 ,
103
+ step : 1 ,
104
+ initial : 7
105
+ }
106
+ ) }
84
107
</ View >
85
108
86
109
< Carousel
87
110
key = { numberOfPagesShown }
88
111
migrate
89
- ref = { r => ( this . carousel = r ) }
112
+ ref = { ( r ) => ( this . carousel = r ) }
90
113
//loop
91
- autoplay = { autoplay }
114
+ autoplay = { autoplay }
92
115
onChangePage = { this . onChangePage }
93
116
pageWidth = { width }
94
117
itemSpacings = { Spacings . s3 }
@@ -101,26 +124,44 @@ class CarouselScreen extends Component {
101
124
allowAccessibleLayout
102
125
>
103
126
{ _ . map ( [ ...Array ( numberOfPagesShown ) ] , ( item , index ) => (
104
- < Page style = { { backgroundColor : BACKGROUND_COLORS [ index ] } } key = { index } >
127
+ < Page
128
+ style = { { backgroundColor : BACKGROUND_COLORS [ index ] } }
129
+ key = { index }
130
+ >
105
131
< Text margin-15 > CARD { index } </ Text >
106
132
</ Page >
107
133
) ) }
108
134
</ Carousel >
109
135
110
- < View marginB-30 center /*style={{...StyleSheet.absoluteFillObject}} */ pointerEvents = "none" >
136
+ < View marginB-30 center pointerEvents = "none" >
111
137
< Text text10 > { this . state . currentPage } </ Text >
112
138
</ View >
113
-
114
- < View padding-20 >
115
- < Carousel containerStyle = { { height : 160 } } initialPage = { INITIAL_PAGE } loop allowAccessibleLayout autoplay = { autoplay } >
116
- { _ . map ( IMAGES , ( image , index ) => {
139
+
140
+ < View paddingH-page >
141
+ < Text h3 marginB-s4 >
142
+ Looping Carousel
143
+ </ Text >
144
+ < Carousel
145
+ containerStyle = { {
146
+ height : 200
147
+ } }
148
+ loop
149
+ pageControlProps = { {
150
+ size : 10 ,
151
+ containerStyle : styles . loopCarousel
152
+ } }
153
+ pageControlPosition = { Carousel . pageControlPositions . OVER }
154
+ >
155
+ { IMAGES . map ( ( image , i ) => {
117
156
return (
118
- < View key = { index } flex padding-10 bottom >
157
+ < View flex centerV key = { i } >
119
158
< Image
120
- style = { StyleSheet . absoluteFillObject }
121
- source = { { uri : image } }
159
+ overlayType = { Image . overlayTypes . BOTTOM }
160
+ style = { { flex : 1 } }
161
+ source = { {
162
+ uri : image
163
+ } }
122
164
/>
123
- < Text white text50 > Image { index } </ Text >
124
165
</ View >
125
166
) ;
126
167
} ) }
@@ -147,6 +188,11 @@ const styles = StyleSheet.create({
147
188
flex : 1 ,
148
189
borderWidth : 1 ,
149
190
borderRadius : 8
191
+ } ,
192
+ loopCarousel : {
193
+ position : 'absolute' ,
194
+ bottom : 15 ,
195
+ left : 10
150
196
}
151
197
} ) ;
152
198
0 commit comments