@@ -11,6 +11,10 @@ import {
1111 Platform ,
1212} from 'react-native' ;
1313import Swiper from 'react-native-swiper' ;
14+ import DoneButton from './components/DoneButton' ;
15+ import SkipButton from './components/SkipButton' ;
16+ import RenderDots from './components/Dots' ;
17+
1418const windowsWidth = Dimensions . get ( 'window' ) . width ;
1519const windowsHeight = Dimensions . get ( 'window' ) . height ;
1620
@@ -62,13 +66,6 @@ const defaulStyles = {
6266 } ,
6367 activeDotStyle : {
6468 backgroundColor : '#fff' ,
65- width : 13 ,
66- height : 13 ,
67- borderRadius : 7 ,
68- marginLeft : 7 ,
69- marginRight : 7 ,
70- marginTop : 7 ,
71- marginBottom : 7 ,
7269 } ,
7370 paginationContainer : {
7471 position : 'absolute' ,
@@ -189,21 +186,6 @@ export default class AppIntro extends Component {
189186 }
190187
191188 renderPagination = ( index , total , context ) => {
192- const { activeDotColor, dotColor, rightTextColor, leftTextColor } = this . props ;
193- const ActiveDot = (
194- < View
195- style = { [ this . styles . activeDotStyle , { backgroundColor : activeDotColor } ] }
196- />
197- ) ;
198- const Dot = < View style = { [ this . styles . dotStyle , { backgroundColor : dotColor } ] } /> ;
199- let dots = [ ] ;
200- for ( let i = 0 ; i < total ; i ++ ) {
201- dots . push ( i === index ?
202- React . cloneElement ( ActiveDot , { key : i } )
203- :
204- React . cloneElement ( Dot , { key : i } )
205- ) ;
206- }
207189 let isDoneBtnShow ;
208190 let isSkipBtnShow ;
209191 if ( index === total - 1 ) {
@@ -219,91 +201,27 @@ export default class AppIntro extends Component {
219201 isDoneBtnShow = false ;
220202 isSkipBtnShow = true ;
221203 }
222- let controllBts ;
223- if ( Platform . OS === 'ios' ) {
224- controllBts = (
225- < View style = { this . styles . paginationContainer } >
226- < Animated . View style = { [ this . styles . btnContainer , {
227- opacity : this . state . skipFadeOpacity ,
228- transform : [ {
229- translateX : this . state . skipFadeOpacity . interpolate ( {
230- inputRange : [ 0 , 1 ] ,
231- outputRange : [ 0 , 15 ] ,
232- } ) ,
233- } ] ,
234- } ] }
235- >
236- < TouchableOpacity
237- style = { this . styles . full }
238- onPress = { isSkipBtnShow ? ( ) => this . props . onSkipBtnClick ( index ) : null }
239- >
240- < Text style = { [ this . styles . controllText , { color : leftTextColor } ] } > { this . props . skipBtnLabel } </ Text >
241- </ TouchableOpacity >
242- </ Animated . View >
243- < View style = { this . styles . dotContainer } >
244- { dots }
245- </ View >
246- < View style = { this . styles . btnContainer } >
247- < Animated . View style = { [ this . styles . full , { height : 0 } , {
248- opacity : this . state . doneFadeOpacity ,
249- transform : [ {
250- translateX : this . state . skipFadeOpacity . interpolate ( {
251- inputRange : [ 0 , 1 ] ,
252- outputRange : [ 0 , 20 ] ,
253- } ) ,
254- } ] ,
255- } ] }
256- >
257- < View style = { this . styles . full } >
258- < Text style = { [ this . styles . controllText , {
259- color : rightTextColor , paddingRight : 30 ,
260- } ] }
261- > { this . props . doneBtnLabel } </ Text >
262- </ View >
263- </ Animated . View >
264- < Animated . View style = { [ this . styles . full , { height : 0 } , { opacity : this . state . nextOpacity } ] } >
265- < TouchableOpacity style = { this . styles . full }
266- onPress = { isDoneBtnShow ?
267- this . props . onDoneBtnClick : this . onNextBtnClick . bind ( this , context ) }
268- >
269- < Text style = { [ this . styles . nextButtonText , { color : rightTextColor } ] } > { this . props . nextBtnLabel } </ Text >
270- </ TouchableOpacity >
271- </ Animated . View >
272- </ View >
273- </ View >
274- ) ;
275- } else {
276- controllBts = (
277- < View style = { this . styles . paginationContainer } >
278- < View style = { [ this . styles . btnContainer , {
279- paddingBottom : 5 ,
280- opacity : isSkipBtnShow ? 1 : 0 ,
281- } ] }
282- >
283- < TouchableOpacity
284- style = { this . styles . full }
285- onPress = { isSkipBtnShow ? ( ) => this . props . onSkipBtnClick ( index ) : null }
286- >
287- < Text style = { [ this . styles . controllText , { color : leftTextColor } ] } > { this . props . skipBtnLabel } </ Text >
288- </ TouchableOpacity >
289- </ View >
290- < View style = { this . styles . dotContainer } >
291- { dots }
292- </ View >
293- < View style = { [ this . styles . btnContainer , { height : 0 , paddingBottom : 5 } ] } >
294- < TouchableOpacity style = { this . styles . full }
295- onPress = { isDoneBtnShow ?
296- this . props . onDoneBtnClick : this . onNextBtnClick . bind ( this , context ) }
297- >
298- < Text style = { [ this . styles . nextButtonText , { color : rightTextColor } ] } >
299- { isDoneBtnShow ? this . props . doneBtnLabel : this . props . nextBtnLabel }
300- </ Text >
301- </ TouchableOpacity >
302- </ View >
303- </ View >
304- ) ;
305- }
306- return controllBts ;
204+ return (
205+ < View style = { [ this . styles . paginationContainer ] } >
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+ } ) }
216+ { this . props . showDoneButton && < DoneButton
217+ { ...this . props }
218+ { ...this . state }
219+ isDoneBtnShow = { isDoneBtnShow }
220+ styles = { this . styles }
221+ onNextBtnClick = { this . onNextBtnClick . bind ( this , context ) }
222+ onDoneBtnClick = { this . props . onDoneBtnClick } /> }
223+ </ View >
224+ ) ;
307225 }
308226
309227 renderBasicSlidePage = ( index , {
@@ -396,6 +314,7 @@ export default class AppIntro extends Component {
396314 { androidPages }
397315 < Swiper
398316 loop = { false }
317+ index = { this . props . defaultIndex }
399318 renderPagination = { this . renderPagination }
400319 onMomentumScrollEnd = { ( e , state ) => {
401320 this . props . onSlideChange ( state . index , state . total ) ;
@@ -434,6 +353,12 @@ AppIntro.propTypes = {
434353 PropTypes . element ,
435354 ] ) ,
436355 customStyles : PropTypes . object ,
356+ defaultIndex : PropTypes . number ,
357+ showSkipButton : PropTypes . bool ,
358+ showDoneButton : PropTypes . bool ,
359+ showDots : PropTypes . bool ,
360+ renderDoneButton : PropTypes . element ,
361+ renderSkipButton : PropTypes . element
437362} ;
438363
439364AppIntro . defaultProps = {
@@ -449,4 +374,8 @@ AppIntro.defaultProps = {
449374 doneBtnLabel : 'Done' ,
450375 skipBtnLabel : 'Skip' ,
451376 nextBtnLabel : '›' ,
377+ defaultIndex : 0 ,
378+ showSkipButton : true ,
379+ showDoneButton : true ,
380+ showDots : true
452381} ;
0 commit comments