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 } from 'react-native-ui-lib' ; // eslint-disable-line
5
-
4
+ import { Constants , Spacings , View , Text , Carousel , Image , Colors } from 'react-native-ui-lib' ;
5
+ import { renderBooleanOption , renderSliderOption } from '../ExampleScreenPresenter' ;
6
6
7
7
const INITIAL_PAGE = 2 ;
8
- const WIDTH = Constants . screenWidth - ( Spacings . s5 * 2 ) ;
8
+ const WIDTH = Constants . screenWidth - Spacings . s5 * 2 ;
9
9
const IMAGES = [
10
10
'https://images.pexels.com/photos/1212487/pexels-photo-1212487.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260' ,
11
11
'https://images.pexels.com/photos/1366630/pexels-photo-1366630.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500' ,
12
12
'https://images.pexels.com/photos/1477459/pexels-photo-1477459.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260' ,
13
13
'https://images.pexels.com/photos/60597/dahlia-red-blossom-bloom-60597.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260'
14
14
] ;
15
15
16
+ const BACKGROUND_COLORS = [
17
+ Colors . red50 ,
18
+ Colors . yellow20 ,
19
+ Colors . purple50 ,
20
+ Colors . green50 ,
21
+ Colors . cyan50 ,
22
+ Colors . purple20 ,
23
+ Colors . blue60 ,
24
+ Colors . red10 ,
25
+ Colors . green20 ,
26
+ Colors . purple60
27
+ ] ;
28
+
16
29
class CarouselScreen extends Component {
17
30
state = {
31
+ limitShownPages : false ,
32
+ numberOfPagesShown : 7 ,
18
33
currentPage : INITIAL_PAGE
19
34
} ;
20
35
21
- onChangePage ( index ) {
22
- this . setState ( { currentPage : index } ) ;
23
- }
36
+ onChangePage = currentPage => {
37
+ this . setState ( { currentPage} ) ;
38
+ } ;
24
39
25
40
onPagePress = index => {
26
41
this . carousel . goToPage ( index , true ) ;
27
42
} ;
28
43
44
+ toggleLimitShownPages = limitShownPages => {
45
+ this . setState ( { limitShownPages} ) ;
46
+ } ;
47
+
48
+ setNumberOfPagesShown = ( { value : numberOfPagesShown } ) => {
49
+ this . setState ( { numberOfPagesShown, currentPage : INITIAL_PAGE } ) ;
50
+ } ;
51
+
29
52
render ( ) {
53
+ const { limitShownPages, numberOfPagesShown} = this . state ;
54
+
30
55
return (
31
56
< ScrollView >
32
- < Text text30 margin-20 > Carousel</ Text >
57
+ < Text text30 margin-20 >
58
+ Carousel
59
+ </ Text >
60
+ < View marginH-20 >
61
+ { renderBooleanOption . call ( this , 'Limit number of pages shown in page control' , 'limitShownPages' ) }
62
+ { renderSliderOption . call ( this , 'Number of pages shown' , 'numberOfPagesShown' , {
63
+ min : 5 ,
64
+ max : 10 ,
65
+ step : 1 ,
66
+ initial : 7
67
+ } ) }
68
+ </ View >
33
69
34
70
< Carousel
71
+ key = { numberOfPagesShown }
35
72
migrate
36
73
ref = { r => ( this . carousel = r ) }
37
74
// loop
38
- onChangePage = { index => this . onChangePage ( index ) }
75
+ onChangePage = { this . onChangePage }
39
76
pageWidth = { WIDTH }
40
77
// itemSpacings={Spacings.s3}
41
78
initialPage = { INITIAL_PAGE }
42
- containerStyle = { { height : 160 /* , flex: 1 */ } }
79
+ containerStyle = { { height : 160 } }
43
80
pageControlPosition = { 'under' }
44
- pageControlProps = { { onPagePress : this . onPagePress } }
81
+ pageControlProps = { { onPagePress : this . onPagePress , limitShownPages } }
45
82
// showCounter
46
83
>
47
- < Page bg-red50 >
48
- < Text margin-15 > PAGE 0</ Text >
49
- </ Page >
50
- < Page bg-yellow20 >
51
- < Text margin-15 > PAGE 1</ Text >
52
- </ Page >
53
- < Page bg-purple50 >
54
- < Text margin-15 > PAGE 2</ Text >
55
- </ Page >
56
- < Page bg-green50 >
57
- < Text margin-15 > PAGE 3</ Text >
58
- </ Page >
59
- < Page bg-cyan50 >
60
- < Text margin-15 > PAGE 4</ Text >
61
- </ Page >
62
- < Page bg-purple20 >
63
- < Text margin-15 > PAGE 5</ Text >
64
- </ Page >
65
- < Page bg-blue60 >
66
- < Text margin-15 > PAGE 6</ Text >
67
- </ Page >
84
+ { _ . map ( [ ...Array ( numberOfPagesShown ) ] , ( item , index ) => (
85
+ < Page style = { { backgroundColor : BACKGROUND_COLORS [ index ] } } key = { index } >
86
+ < Text margin-15 > PAGE { index } </ Text >
87
+ </ Page >
88
+ ) ) }
68
89
</ Carousel >
69
90
70
91
< View margin-20 center /*style={{...StyleSheet.absoluteFillObject}} */ pointerEvents = "none" >
@@ -82,7 +103,9 @@ class CarouselScreen extends Component {
82
103
uri : image
83
104
} }
84
105
/>
85
- < Text white text50 > Image { index } </ Text >
106
+ < Text white text50 >
107
+ Image { index }
108
+ </ Text >
86
109
</ View >
87
110
) ;
88
111
} ) }
@@ -93,15 +116,18 @@ class CarouselScreen extends Component {
93
116
}
94
117
}
95
118
96
- const Page = ( { children, ...others } ) => {
119
+ const Page = ( { children, style , ...others } ) => {
97
120
return (
98
- < View { ...others } style = { styles . page } >
121
+ < View { ...others } style = { [ styles . page , style ] } >
99
122
{ children }
100
123
</ View >
101
124
) ;
102
125
} ;
103
126
104
127
const styles = StyleSheet . create ( {
128
+ picker : {
129
+ marginHorizontal : 20
130
+ } ,
105
131
page : {
106
132
flex : 1 ,
107
133
borderWidth : 1 ,
0 commit comments