Skip to content

Commit 8c508a1

Browse files
committed
Initial
1 parent 5f3856e commit 8c508a1

5 files changed

+201
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
### 0.1.0
2+
- Initial component

README.md

+72-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,73 @@
1-
# react-native-fading-slides
1+
## React Native FadingSlides Component
2+
23
Simple looped fading slides carousel for React Native.
4+
5+
### Installation
6+
7+
```bash
8+
npm install react-native-fading-slides
9+
```
10+
11+
### Properties
12+
13+
```
14+
fadeDuration={500} // Milliseconds for slide fade
15+
stillDuration={1000} // Milliseconds for slide still
16+
height={1000} // Set the slides component height
17+
slides={slidesList} // Set the slides list
18+
```
19+
20+
### Slides Properties
21+
22+
```
23+
title={"Title"} // Slide's title
24+
titleColor={"#fff"} // Slide's title color
25+
subtitle={"Subtitle"} // Slide's subtitle
26+
subtitleColor={"#fff"} // Slide's subtitle color
27+
image={require('image!filename')} // Slide's image
28+
imageWidth={1000} // Slide's image width
29+
imageHeight={1000} // Slide's image height
30+
```
31+
32+
### Usage Example
33+
34+
```javascript
35+
'use strict';
36+
37+
var FadingSlides = require('react-native-fading-slides');
38+
39+
var slides = [
40+
{
41+
image: require('image!squared-image'),
42+
imageWidth: 100,
43+
imageHeight: 100,
44+
title: 'Hello World',
45+
subtitle: 'This is a beautiful world',
46+
titleColor: '#fff',
47+
subtitleColor: '#fff'
48+
},
49+
{
50+
image: require('image!wide-image'),
51+
imageWidth: 200,
52+
imageHeight: 100,
53+
title: 'Bye World',
54+
subtitle: 'This is a see you soon',
55+
titleColor: '#fff',
56+
subtitleColor: '#fff'
57+
}
58+
];
59+
60+
//...
61+
62+
render: function() {
63+
return (
64+
<View>
65+
<FadingSlides
66+
slides={slides}
67+
fadeDuration={1200}
68+
stillDuration={2000}
69+
height={500}/>
70+
</View>
71+
);
72+
};
73+
```

fading-slides.component.js

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
'use strict';
2+
3+
var React = require('react-native');
4+
var TimerMixin = require('react-timer-mixin');
5+
var tweenState = require('react-tween-state');
6+
7+
var {
8+
Animated,
9+
StyleSheet,
10+
View,
11+
Text
12+
} = React;
13+
14+
let MINIMUM_DELAY = 100;
15+
16+
var FadingSlides = React.createClass({
17+
mixins: [TimerMixin, tweenState.Mixin],
18+
19+
getInitialState: function () {
20+
return {
21+
opacity: 0,
22+
currentIndex: 0
23+
};
24+
},
25+
26+
componentDidMount: function () {
27+
this._fadeOpacity();
28+
},
29+
30+
_fadeOpacity: function () {
31+
this.tweenState('opacity', {
32+
easing: tweenState.easingTypes.easeInCirc,
33+
duration: this.props.fadeDuration,
34+
beginValue: this.state.opacity === 0 ? 0 : 1,
35+
onEnd: this._getNextSlide,
36+
endValue: this.state.opacity === 0 ? 1 : 0
37+
});
38+
},
39+
40+
_getNextSlide: function () {
41+
if (this.state.opacity === 0) {
42+
var index = this.state.currentIndex + 1;
43+
index = index < this.props.slides.length ? index: 0;
44+
this.setState({ currentIndex: index });
45+
this.setTimeout(() => { this._fadeOpacity(); }, MINIMUM_DELAY);
46+
} else {
47+
this.setTimeout(() => { this._fadeOpacity(); },
48+
this.props.stillDuration || MINIMUM_DELAY);
49+
}
50+
},
51+
52+
render: function () {
53+
var slide = this.props.slides[this.state.currentIndex];
54+
return (
55+
<View style={[styles.slide, { height: this.props.height, opacity: this.getTweeningValue('opacity') }]}>
56+
<View style={styles.info} />
57+
<Animated.Image
58+
style={{ width: slide.imageWidth, height: slide.imageHeight }}
59+
source={slide.image}
60+
/>
61+
<View style={styles.info}>
62+
<Text style={[styles.title, { color: slide.titleColor }]}>
63+
{slide.title}
64+
</Text>
65+
<Text style={[styles.subtitle, { color: slide.subtitleColor }]}>
66+
{slide.subtitle}
67+
</Text>
68+
</View>
69+
</View>
70+
);
71+
},
72+
});
73+
74+
75+
var styles = StyleSheet.create({
76+
slide: {
77+
flex: 1,
78+
justifyContent: 'center',
79+
alignItems: 'center',
80+
flexDirection: 'column'
81+
},
82+
info: {
83+
flex: 1,
84+
justifyContent: 'flex-end',
85+
alignItems: 'center',
86+
flexDirection: 'column'
87+
},
88+
title: {
89+
fontSize: 22,
90+
fontWeight: '700',
91+
},
92+
subtitle: {
93+
fontSize: 20,
94+
paddingBottom: 30
95+
}
96+
});
97+
98+
module.exports = FadingSlides;

package.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "react-native-fading-slides",
3+
"version": "0.1.0",
4+
"description": "Simple looped fading slides carousel for React Native",
5+
"main": "fading-slides.component.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/chagasaway/react-native-fading-slides.git"
12+
},
13+
"keywords": [
14+
"react-native",
15+
"slides",
16+
"intro",
17+
"carousel"
18+
],
19+
"author": "Fellipe Chagas <chagas.0@gmail.com> (https://github.com/chagasaway)",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/chagasaway/react-native-fading-slides/issues"
23+
},
24+
"homepage": "https://github.com/chagasaway/react-native-fading-slides",
25+
"peerDependencies": {
26+
"react-native": ">=0.4 <1.0"
27+
}
28+
}

0 commit comments

Comments
 (0)