11import React , { createElement } from 'react' ;
2+ import TweenOne from 'rc-tween-one' ;
23import EventListener from './EventDispatcher' ;
34import ScrollElement from './ScrollElement' ;
45import { toArrayChildren } from './util' ;
@@ -9,18 +10,19 @@ function noop() {
910class ScrollOverPack extends ScrollElement {
1011 constructor ( props ) {
1112 super ( props ) ;
12- this . children = toArrayChildren ( this . props . children ) ;
13+ this . children = toArrayChildren ( props . children ) ;
1314 this . oneEnter = false ;
1415 this . enter = false ;
1516 this . state = {
1617 show : false ,
17- children : toArrayChildren ( this . props . children ) ,
18+ children : toArrayChildren ( props . children ) ,
1819 } ;
1920 }
2021
2122 scrollEventListener = ( e ) => {
2223 this . getParam ( e ) ;
23- if ( this . enter ) {
24+ const isTop = this . elementShowHeight > this . clientHeight + this . leavePlayHeight ;
25+ if ( this . enter || ! this . props . replay && isTop ) {
2426 if ( ! this . state . show ) {
2527 this . setState ( {
2628 show : true ,
@@ -29,16 +31,16 @@ class ScrollOverPack extends ScrollElement {
2931 if ( ! this . props . always ) {
3032 EventListener . removeEventListener ( this . eventType , this . scrollEventListener ) ;
3133 }
32- }
33- const bottomLeave = this . elementShowHeight < this . playHeight ;
34- // 设置往上时的出场点...
35- const topLeave = this . props . replay ?
36- this . elementShowHeight > this . clientHeight + this . leavePlayHeight : null ;
37- if ( topLeave || bottomLeave ) {
38- if ( this . state . show ) {
39- this . setState ( {
40- show : false ,
41- } ) ;
34+ } else {
35+ const bottomLeave = this . elementShowHeight < this . playHeight ;
36+ // 设置往上时的出场点...
37+ const topLeave = this . props . replay ? isTop : null ;
38+ if ( topLeave || bottomLeave ) {
39+ if ( this . state . show ) {
40+ this . setState ( {
41+ show : false ,
42+ } ) ;
43+ }
4244 }
4345 }
4446 }
@@ -51,12 +53,13 @@ class ScrollOverPack extends ScrollElement {
5153 'component' ,
5254 'always' ,
5355 'scrollEvent' ,
54- 'hideProps ' ,
56+ 'appear ' ,
5557 'location' ,
5658 ] . forEach ( key => delete placeholderProps [ key ] ) ;
5759 let childToRender ;
58- if ( ! this . oneEnter && ! this . state . show ) {
59- childToRender = createElement ( this . props . component , { ...placeholderProps } , null ) ;
60+ if ( ! this . oneEnter ) {
61+ const children = ! this . props . appear && this . props . children ;
62+ childToRender = createElement ( this . props . component , { ...placeholderProps } , children ) ;
6063 this . oneEnter = true ;
6164 } else {
6265 if ( ! this . state . show ) {
@@ -65,9 +68,8 @@ class ScrollOverPack extends ScrollElement {
6568 return null ;
6669 }
6770 let element ;
68- const hideProps = this . props . hideProps [ item . key ] ;
69- if ( hideProps ) {
70- element = React . cloneElement ( item , { ...hideProps } ) ;
71+ if ( item . type === TweenOne ) {
72+ element = React . cloneElement ( item , { reverse : true } ) ;
7173 return element ;
7274 }
7375 element = React . cloneElement ( item , { } , null ) ;
@@ -91,7 +93,7 @@ ScrollOverPack.propTypes = {
9193 style : React . PropTypes . any ,
9294 replay : React . PropTypes . bool ,
9395 onChange : React . PropTypes . func ,
94- hideProps : React . PropTypes . object ,
96+ appear : React . PropTypes . bool ,
9597} ;
9698
9799ScrollOverPack . defaultProps = {
@@ -101,7 +103,7 @@ ScrollOverPack.defaultProps = {
101103 scrollEvent : noop ,
102104 replay : false ,
103105 onChange : noop ,
104- hideProps : { } ,
106+ appear : true ,
105107} ;
106108
107109export default ScrollOverPack ;
0 commit comments