mirror of
https://github.com/zhigang1992/react-native-gifted-chat.git
synced 2026-04-28 20:25:43 +08:00
fix MessageContainer-Pure (#1101)
This commit is contained in:
committed by
GitHub
parent
b4259bd5fe
commit
efc19b1456
@@ -16,11 +16,11 @@ import LoadEarlier from './LoadEarlier';
|
||||
import Message from './Message';
|
||||
import Color from './Color';
|
||||
|
||||
export default class MessageContainer extends React.Component {
|
||||
export default class MessageContainer extends React.PureComponent {
|
||||
|
||||
state = {
|
||||
showScrollBottom: false,
|
||||
}
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.messages.length === 0) {
|
||||
@@ -28,14 +28,6 @@ export default class MessageContainer extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
shouldComponentUpdate(nextProps) {
|
||||
const next = nextProps.messages;
|
||||
const current = this.props.messages;
|
||||
return (
|
||||
next.length !== current.length || next.extraData !== current.extraData || next.loadEarlier !== current.loadEarlier
|
||||
);
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (this.props.messages.length === 0 && nextProps.messages.length > 0) {
|
||||
this.detachKeyboardListeners();
|
||||
@@ -91,7 +83,7 @@ export default class MessageContainer extends React.Component {
|
||||
|
||||
scrollToBottom = () => {
|
||||
this.scrollTo({ offset: 0, animated: 'true' });
|
||||
}
|
||||
};
|
||||
|
||||
handleOnScroll = (event) => {
|
||||
if (event.nativeEvent.contentOffset.y > this.props.scrollToBottomOffset) {
|
||||
@@ -99,7 +91,7 @@ export default class MessageContainer extends React.Component {
|
||||
} else {
|
||||
this.setState({ showScrollBottom: false });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
renderRow = ({ item, index }) => {
|
||||
if (!item._id && item._id !== 0) {
|
||||
@@ -145,7 +137,8 @@ export default class MessageContainer extends React.Component {
|
||||
return (
|
||||
<TouchableOpacity onPress={this.scrollToBottom} hitSlop={{ top: 5, left: 5, right: 5, bottom: 5 }}>
|
||||
{this.props.scrollToBottomComponent}
|
||||
</TouchableOpacity>);
|
||||
</TouchableOpacity>
|
||||
);
|
||||
}
|
||||
return scrollToBottomComponent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user