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