@@ -3,6 +3,8 @@ import './MessageList.css';
33
44import MessageBox from '../MessageBox/MessageBox' ;
55
6+ import FaChevronDown from 'react-icons/lib/fa/chevron-down' ;
7+
68const classNames = require ( 'classnames' ) ;
79
810export class MessageList extends Component {
@@ -11,16 +13,16 @@ export class MessageList extends Component {
1113 super ( props ) ;
1214 this . state = {
1315 scrollBottom : 0 ,
16+ downButton : false ,
1417 } ;
1518 }
1619
17- componentDidUpdate ( ) {
20+ checkScroll ( ) {
1821 var e = this . mlistRef ;
1922 if ( ! e )
2023 return ;
2124
22- var bottom = this . getBottom ( e ) ;
23- if ( this . props . toBottomHeight === '100%' || bottom < this . props . toBottomHeight ) {
25+ if ( this . props . toBottomHeight === '100%' || this . state . scrollBottom < this . props . toBottomHeight ) {
2426 // scroll to bottom
2527 e . scrollTop = e . scrollHeight ;
2628 } else {
@@ -35,7 +37,7 @@ export class MessageList extends Component {
3537 return ;
3638 this . setState ( {
3739 scrollBottom : this . getBottom ( this . mlistRef ) ,
38- } ) ;
40+ } , this . checkScroll . bind ( this ) ) ;
3941 }
4042
4143 getBottom ( e ) {
@@ -73,23 +75,74 @@ export class MessageList extends Component {
7375 this . props . cmpRef ( ref ) ;
7476 }
7577
78+ onScroll ( e ) {
79+ var bottom = this . getBottom ( e . target ) ;
80+ this . state . scrollBottom = bottom ;
81+ if ( this . props . toBottomHeight === '100%' || bottom > this . props . toBottomHeight ) {
82+ if ( this . state . downButton !== true ) {
83+ this . state . downButton = true ;
84+ this . setState ( {
85+ downButton : true ,
86+ scrollBottom : bottom ,
87+ } )
88+ }
89+ } else {
90+ if ( this . state . downButton !== false ) {
91+ this . state . downButton = false ;
92+ this . setState ( {
93+ downButton : false ,
94+ scrollBottom : bottom ,
95+ } )
96+ }
97+ }
98+ }
99+
100+ toBottom ( e ) {
101+ if ( ! this . mlistRef )
102+ return ;
103+ this . mlistRef . scrollTop = this . mlistRef . scrollHeight ;
104+ if ( this . props . onDownButtonClick instanceof Function ) {
105+ this . props . onDownButtonClick ( e ) ;
106+ }
107+ }
108+
76109 render ( ) {
77110 return (
78111 < div
79- ref = { this . loadRef . bind ( this ) }
80- onScroll = { this . props . onScroll }
81112 className = { classNames ( [ 'rce-container-mlist' , this . props . className ] ) } >
113+ < div
114+ ref = { this . loadRef . bind ( this ) }
115+ onScroll = { this . onScroll . bind ( this ) }
116+ className = 'rce-mlist' >
117+ {
118+ this . props . dataSource . map ( ( x , i ) => (
119+ < MessageBox
120+ key = { i }
121+ { ...x }
122+ onOpen = { this . props . onOpen && ( ( e ) => this . onOpen ( x , i , e ) ) }
123+ onDownload = { this . props . onDownload && ( ( e ) => this . onDownload ( x , i , e ) ) }
124+ onTitleClick = { this . props . onDownload && ( ( e ) => this . onTitleClick ( x , i , e ) ) }
125+ onForwardClick = { this . props . onForwardClick && ( ( e ) => this . onForwardClick ( x , i , e ) ) }
126+ onClick = { this . props . onClick && ( ( e ) => this . onClick ( x , i , e ) ) } />
127+ ) )
128+ }
129+ </ div >
82130 {
83- this . props . dataSource . map ( ( x , i ) => (
84- < MessageBox
85- key = { i }
86- { ...x }
87- onOpen = { this . props . onOpen && ( ( e ) => this . onOpen ( x , i , e ) ) }
88- onDownload = { this . props . onDownload && ( ( e ) => this . onDownload ( x , i , e ) ) }
89- onTitleClick = { this . props . onDownload && ( ( e ) => this . onTitleClick ( x , i , e ) ) }
90- onForwardClick = { this . props . onForwardClick && ( ( e ) => this . onForwardClick ( x , i , e ) ) }
91- onClick = { this . props . onClick && ( ( e ) => this . onClick ( x , i , e ) ) } />
92- ) )
131+ this . props . downButton === true &&
132+ this . state . downButton &&
133+ this . props . toBottomHeight !== '100%' &&
134+ < div
135+ className = 'rce-mlist-down-button'
136+ onClick = { this . toBottom . bind ( this ) } >
137+ < FaChevronDown />
138+ {
139+ this . props . downButtonBadge &&
140+ < span
141+ className = 'rce-mlist-down-button--badge' >
142+ { this . props . downButtonBadge }
143+ </ span >
144+ }
145+ </ div >
93146 }
94147 </ div >
95148 ) ;
@@ -100,11 +153,14 @@ MessageList.defaultProps = {
100153 onClick : null ,
101154 onTitleClick : null ,
102155 onForwardClick : null ,
156+ onDownButtonClick : null ,
103157 onOpen : null ,
104158 onDownload : null ,
105159 dataSource : [ ] ,
106160 lockable : false ,
107161 toBottomHeight : 300 ,
162+ downButton : true ,
163+ downButtonBadge : null ,
108164} ;
109165
110166export default MessageList ;
0 commit comments