@@ -20,20 +20,7 @@ export class MessageList extends Component {
2020 } ;
2121
2222 this . loadRef = this . loadRef . bind ( this ) ;
23- this . createReferenceOfMessage = this . createReferenceOfMessage . bind ( this ) ;
2423 this . onScroll = this . onScroll . bind ( this ) ;
25- this . messageRefs = [ ] ;
26- }
27-
28- scrollIntoMessage ( focusedMessage ) {
29- var message = this . messageRefs . find ( x => x . messageId === focusedMessage ) ;
30- if ( message !== undefined ) {
31- this . setState ( {
32- messageFocus : true ,
33- } , ( ) => {
34- message . ref . scrollIntoView ( { block : this . props . scrollBlock , behavior : 'smooth' , } ) ;
35- } ) ;
36- }
3724 }
3825
3926 checkScroll ( ) {
@@ -54,12 +41,11 @@ export class MessageList extends Component {
5441 componentWillReceiveProps ( nextProps ) {
5542 if ( ! this . mlistRef )
5643 return ;
57- this . setState ( {
58- scrollBottom : this . getBottom ( this . mlistRef ) ,
59- } , this . checkScroll . bind ( this ) ) ;
60-
61- if ( nextProps . focusedMessage )
62- this . scrollIntoMessage ( nextProps . focusedMessage ) ;
44+ if ( nextProps . dataSource . length !== this . props . dataSource . length ) {
45+ this . setState ( {
46+ scrollBottom : this . getBottom ( this . mlistRef ) ,
47+ } , this . checkScroll . bind ( this ) ) ;
48+ }
6349 }
6450
6551 getBottom ( e ) {
@@ -96,28 +82,17 @@ export class MessageList extends Component {
9682 this . props . onContextMenu ( item , i , e ) ;
9783 }
9884
85+ onMessageFocused ( item , i , e ) {
86+ if ( this . props . onMessageFocused instanceof Function )
87+ this . props . onMessageFocused ( item , i , e ) ;
88+ }
89+
9990 loadRef ( ref ) {
10091 this . mlistRef = ref ;
10192 if ( this . props . cmpRef instanceof Function )
10293 this . props . cmpRef ( ref ) ;
10394 }
10495
105- createReferenceOfMessage ( ref , messageId ) {
106- var check = this . messageRefs . find ( res => res . messageId === messageId ) ;
107-
108- if ( check !== undefined ) {
109- var index = this . messageRefs . indexOf ( check ) ;
110- if ( index !== - 1 ) {
111- this . messageRefs . splice ( index , 1 ) ;
112- }
113- }
114-
115- this . messageRefs . push ( {
116- ref : ref ,
117- messageId : messageId ,
118- } ) ;
119- }
120-
12196 onScroll ( e ) {
12297 var bottom = this . getBottom ( e . target ) ;
12398 this . state . scrollBottom = bottom ;
@@ -163,22 +138,18 @@ export class MessageList extends Component {
163138 className = 'rce-mlist' >
164139 {
165140 this . props . dataSource . map ( ( x , i ) => (
166- < div
167- ref = { ref => this . createReferenceOfMessage ( ref , x . id ) } >
168- < MessageBox
169- key = { i }
170- { ...x }
171- focusedMessage = { this . props . focusedMessage }
172- messageFocus = { x . id === this . props . focusedMessage && this . state . messageFocus }
173- onOpen = { this . props . onOpen && ( ( e ) => this . onOpen ( x , i , e ) ) }
174- onFocus = { this . props . onFocus && ( ( e ) => this . onFocus ( x , i , e ) ) }
175- onDownload = { this . props . onDownload && ( ( e ) => this . onDownload ( x , i , e ) ) }
176- onTitleClick = { this . props . onTitleClick && ( ( e ) => this . onTitleClick ( x , i , e ) ) }
177- onForwardClick = { this . props . onForwardClick && ( ( e ) => this . onForwardClick ( x , i , e ) ) }
178- onClick = { this . props . onClick && ( ( e ) => this . onClick ( x , i , e ) ) }
179- onContextMenu = { this . props . onContextMenu && ( ( e ) => this . onContextMenu ( x , i , e ) ) }
180- />
181- </ div >
141+ < MessageBox
142+ key = { i }
143+ { ...x }
144+ onMessageFocused = { this . props . onMessageFocused && ( ( e ) => this . onMessageFocused ( x , i , e ) ) }
145+ onOpen = { this . props . onOpen && ( ( e ) => this . onOpen ( x , i , e ) ) }
146+ onFocus = { this . props . onFocus && ( ( e ) => this . onFocus ( x , i , e ) ) }
147+ onDownload = { this . props . onDownload && ( ( e ) => this . onDownload ( x , i , e ) ) }
148+ onTitleClick = { this . props . onTitleClick && ( ( e ) => this . onTitleClick ( x , i , e ) ) }
149+ onForwardClick = { this . props . onForwardClick && ( ( e ) => this . onForwardClick ( x , i , e ) ) }
150+ onClick = { this . props . onClick && ( ( e ) => this . onClick ( x , i , e ) ) }
151+ onContextMenu = { this . props . onContextMenu && ( ( e ) => this . onContextMenu ( x , i , e ) ) }
152+ />
182153 ) )
183154 }
184155 </ div >
@@ -216,8 +187,6 @@ MessageList.defaultProps = {
216187 toBottomHeight : 300 ,
217188 downButton : true ,
218189 downButtonBadge : null ,
219- focusedMessage : null ,
220- scrollBlock : 'center' ,
221190} ;
222191
223192export default MessageList ;
0 commit comments