Skip to content

Commit 98a9a79

Browse files
committed
Update Carousel example screen
1 parent 0e539fc commit 98a9a79

File tree

1 file changed

+78
-32
lines changed

1 file changed

+78
-32
lines changed

demo/src/screens/componentScreens/CarouselScreen.js

Lines changed: 78 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import _ from 'lodash';
22
import React, {Component} from 'react';
33
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';
717

818
const INITIAL_PAGE = 2;
919
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'
1423
];
1524
const BACKGROUND_COLORS = [
1625
Colors.red50,
@@ -49,19 +58,22 @@ class CarouselScreen extends Component {
4958

5059
onOrientationChange = () => {
5160
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+
});
5365
}
5466
};
5567

5668
getWidth = () => {
5769
return Constants.windowWidth - Spacings.s5 * 2;
58-
}
70+
};
5971

60-
onChangePage = currentPage => {
72+
onChangePage = (currentPage) => {
6173
this.setState({currentPage});
6274
};
6375

64-
onPagePress = index => {
76+
onPagePress = (index) => {
6577
this.carousel.goToPage(index, true);
6678
};
6779

@@ -70,25 +82,36 @@ class CarouselScreen extends Component {
7082

7183
return (
7284
<ScrollView showsVerticalScrollIndicator={false}>
73-
<Text text30 margin-20>Carousel</Text>
85+
<Text h1 margin-20>
86+
Carousel
87+
</Text>
7488

7589
<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+
)}
84107
</View>
85108

86109
<Carousel
87110
key={numberOfPagesShown}
88111
migrate
89-
ref={r => (this.carousel = r)}
112+
ref={(r) => (this.carousel = r)}
90113
//loop
91-
autoplay={autoplay}
114+
autoplay={autoplay}
92115
onChangePage={this.onChangePage}
93116
pageWidth={width}
94117
itemSpacings={Spacings.s3}
@@ -101,26 +124,44 @@ class CarouselScreen extends Component {
101124
allowAccessibleLayout
102125
>
103126
{_.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+
>
105131
<Text margin-15>CARD {index}</Text>
106132
</Page>
107133
))}
108134
</Carousel>
109135

110-
<View marginB-30 center /*style={{...StyleSheet.absoluteFillObject}} */ pointerEvents="none">
136+
<View marginB-30 center pointerEvents="none">
111137
<Text text10>{this.state.currentPage}</Text>
112138
</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) => {
117156
return (
118-
<View key={index} flex padding-10 bottom>
157+
<View flex centerV key={i}>
119158
<Image
120-
style={StyleSheet.absoluteFillObject}
121-
source={{uri: image}}
159+
overlayType={Image.overlayTypes.BOTTOM}
160+
style={{flex: 1}}
161+
source={{
162+
uri: image
163+
}}
122164
/>
123-
<Text white text50>Image {index}</Text>
124165
</View>
125166
);
126167
})}
@@ -147,6 +188,11 @@ const styles = StyleSheet.create({
147188
flex: 1,
148189
borderWidth: 1,
149190
borderRadius: 8
191+
},
192+
loopCarousel: {
193+
position: 'absolute',
194+
bottom: 15,
195+
left: 10
150196
}
151197
});
152198

0 commit comments

Comments
 (0)