Skip to content

Commit b250e55

Browse files
mlist and clist cmpRef prop added.
1 parent 1f6d329 commit b250e55

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/ChatList/ChatList.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ export class ChatList extends Component {
2020

2121
render() {
2222
return (
23-
<div className={classNames('rce-container-clist', this.props.className)}>
23+
<div
24+
ref={this.props.cmpRef}
25+
className={classNames('rce-container-clist', this.props.className)}>
2426
{
2527
this.props.dataSource.map((x, i) => (
2628
<ChatItem

src/MessageList/MessageList.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export class MessageList extends Component {
1515
}
1616

1717
componentDidUpdate() {
18-
var e = this.refs.mlist;
18+
var e = this.mlistRef;
19+
if (!e)
20+
return;
21+
1922
var bottom = this.getBottom(e);
2023
if (this.props.toBottomHeight === '100%' || bottom < this.props.toBottomHeight) {
2124
// scroll to bottom
@@ -29,7 +32,7 @@ export class MessageList extends Component {
2932

3033
componentWillReceiveProps() {
3134
this.setState({
32-
scrollBottom: this.getBottom(this.refs.mlist),
35+
scrollBottom: this.getBottom(this.mlistRef),
3336
});
3437
}
3538

@@ -62,10 +65,16 @@ export class MessageList extends Component {
6265
this.props.onForwardClick(item, i, e);
6366
}
6467

68+
loadRef(ref) {
69+
this.mlistRef = ref;
70+
if (this.props.cmpRef instanceof Function)
71+
this.props.cmpRef(ref);
72+
}
73+
6574
render() {
6675
return (
6776
<div
68-
ref='mlist'
77+
ref={this.loadRef.bind(this)}
6978
onScroll={this.props.onScroll}
7079
className={classNames(['rce-container-mlist', this.props.className])}>
7180
{

0 commit comments

Comments
 (0)