Skip to content

Commit d16166e

Browse files
committed
Broken everything out into components
1 parent 0f6a056 commit d16166e

File tree

4 files changed

+120
-70
lines changed

4 files changed

+120
-70
lines changed

AppIntro.js

+12-70
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
} from 'react-native';
1313
import Swiper from 'react-native-swiper';
1414
import DoneButton from './components/DoneButton';
15+
import SkipButton from './components/SkipButton';
16+
import RenderDots from './components/Dots';
1517

1618
const windowsWidth = Dimensions.get('window').width;
1719
const windowsHeight = Dimensions.get('window').height;
@@ -183,75 +185,7 @@ export default class AppIntro extends Component {
183185
};
184186
}
185187

186-
renderSkipButton = (isSkipBtnShow, index) => {
187-
if (Platform.OS === 'ios') {
188-
return (
189-
<Animated.View style={[this.styles.btnContainer, {
190-
opacity: this.state.skipFadeOpacity,
191-
transform: [{
192-
translateX: this.state.skipFadeOpacity.interpolate({
193-
inputRange: [0, 1],
194-
outputRange: [0, 15],
195-
}),
196-
}],
197-
}]}
198-
>
199-
<TouchableOpacity
200-
style={this.styles.full}
201-
onPress={isSkipBtnShow ? () => this.props.onSkipBtnClick(index) : null}
202-
>
203-
<Text style={[this.styles.controllText, { color: this.props.rightTextColor }]}>{this.props.skipBtnLabel}</Text>
204-
</TouchableOpacity>
205-
</Animated.View>
206-
)
207-
} else {
208-
return (
209-
<View style={[this.styles.btnContainer, {
210-
paddingBottom: 5,
211-
opacity: isSkipBtnShow ? 1 : 0,
212-
}]}
213-
>
214-
<TouchableOpacity
215-
style={this.styles.full}
216-
onPress={isSkipBtnShow ? () => this.props.onSkipBtnClick(index) : null}
217-
>
218-
<Text style={[this.styles.controllText, { color: this.props.leftTextColor }]}>{this.props.skipBtnLabel}</Text>
219-
</TouchableOpacity>
220-
</View>
221-
)
222-
}
223-
}
224-
225-
renderDots = (dots) => {
226-
if (this.props.showDots) {
227-
return (
228-
<View style={this.styles.dotContainer}>
229-
{dots}
230-
</View>
231-
)
232-
}
233-
}
234-
235188
renderPagination = (index, total, context) => {
236-
const { activeDotColor, dotColor, rightTextColor, leftTextColor } = this.props;
237-
const ActiveDot = (
238-
<View
239-
style={[this.styles.dotStyle, this.styles.activeDotStyle, { backgroundColor: activeDotColor }]}
240-
/>
241-
);
242-
const Dot = (
243-
<View
244-
style={[this.styles.dotStyle, { backgroundColor: dotColor }]} />
245-
);
246-
247-
let dots = [];
248-
for (let i = 0; i < total; i++) {
249-
dots.push(i === index ?
250-
React.cloneElement(ActiveDot, { key: i })
251-
:
252-
React.cloneElement(Dot, { key: i })
253-
);
254-
}
255189
let isDoneBtnShow;
256190
let isSkipBtnShow;
257191
if (index === total - 1) {
@@ -269,8 +203,16 @@ export default class AppIntro extends Component {
269203
}
270204
return (
271205
<View style={[this.styles.paginationContainer]}>
272-
{this.props.showSkipButton && this.renderSkipButton(isSkipBtnShow, index)}
273-
{this.renderDots(dots)}
206+
{this.props.showSkipButton && <SkipButton
207+
{...this.props}
208+
{...this.state}
209+
isSkipBtnShow={isSkipBtnShow}
210+
styles={this.styles}
211+
onSkipBtnClick={() => this.props.onSkipBtnClick(index)} />}
212+
{this.props.showDots && RenderDots(index, total, {
213+
...this.props,
214+
styles: this.styles
215+
})}
274216
{this.props.showDoneButton && <DoneButton
275217
{...this.props}
276218
{...this.state}

components/Dots.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react'
2+
import {
3+
Text,
4+
View
5+
} from 'react-native';
6+
7+
export const Dot = ({
8+
styles, dotColor, activeDotColor, active
9+
}) => {
10+
if (active) {
11+
return (
12+
<View
13+
style={[styles.dotStyle, styles.activeDotStyle, {
14+
backgroundColor: activeDotColor
15+
}]}
16+
/>
17+
);
18+
} else {
19+
return (
20+
<View
21+
style={[styles.dotStyle, {
22+
backgroundColor: dotColor
23+
}]} />
24+
);
25+
}
26+
}
27+
28+
export const RenderDots = (index, total, props) => {
29+
let dots = [];
30+
for (let i = 0; i < total; i++) {
31+
dots.push(React.createElement(Dot, {
32+
...props,
33+
key: i,
34+
active: i === index
35+
}));
36+
}
37+
return dots;
38+
}
39+
40+
export default RenderDots;

components/SkipButton.android.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react'
2+
import {
3+
Text,
4+
View,
5+
TouchableOpacity,
6+
Animated
7+
} from 'react-native';
8+
9+
export const SkipButton = ({
10+
styles, onSkipBtnClick, isSkipBtnShow,
11+
leftTextColor,
12+
skipBtnLabel,
13+
skipFadeOpacity
14+
}) => {
15+
return (
16+
<View style={[styles.btnContainer, {
17+
paddingBottom: 5,
18+
opacity: isSkipBtnShow ? 1 : 0,
19+
}]}>
20+
<TouchableOpacity
21+
style={styles.full}
22+
onPress={isSkipBtnShow ? () => onSkipBtnClick(index) : null}>
23+
<Text style={[styles.controllText, { color: leftTextColor }]}>
24+
{skipBtnLabel}
25+
</Text>
26+
</TouchableOpacity>
27+
</View>
28+
)
29+
}
30+
31+
export default SkipButton

components/SkipButton.ios.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react'
2+
import {
3+
Text,
4+
View,
5+
TouchableOpacity,
6+
Animated
7+
} from 'react-native';
8+
9+
export const SkipButton = ({
10+
styles, onSkipBtnClick, isSkipBtnShow,
11+
rightTextColor,
12+
skipBtnLabel,
13+
skipFadeOpacity
14+
}) => {
15+
return (
16+
<Animated.View style={[styles.btnContainer, {
17+
opacity: skipFadeOpacity,
18+
transform: [{
19+
translateX: skipFadeOpacity.interpolate({
20+
inputRange: [0, 1],
21+
outputRange: [0, 15],
22+
}),
23+
}],
24+
}]}
25+
>
26+
<TouchableOpacity
27+
style={styles.full}
28+
onPress={isSkipBtnShow ? () => onSkipBtnClick(index) : null}>
29+
<Text style={[styles.controllText, { color: rightTextColor }]}>
30+
{skipBtnLabel}
31+
</Text>
32+
</TouchableOpacity>
33+
</Animated.View>
34+
)
35+
}
36+
37+
export default SkipButton

0 commit comments

Comments
 (0)