Skip to content

Commit

Permalink
fix scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
xcarpentier committed Jul 16, 2019
1 parent 808f5ba commit d827601
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-gifted-chat",
"version": "0.10.0-beta.web.9",
"version": "0.10.0-beta.web.10",
"description": "The most complete chat UI for React Native",
"main": "node_modules/expo/AppEntry.js",
"types": "lib/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/GiftedChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ class GiftedChat<TMessage extends IMessage = IMessage> extends React.Component<
this.props.onSend(newMessages)
}

setTimeout(() => this.scrollToBottom(), 100)
setTimeout(() => this.scrollToBottom(false), 100)

if (shouldResetInputToolbar === true) {
setTimeout(() => {
Expand All @@ -660,7 +660,7 @@ class GiftedChat<TMessage extends IMessage = IMessage> extends React.Component<
if (this.props.onQuickReply) {
this.props.onQuickReply(replies)
}
setTimeout(() => this.scrollToBottom(), 100)
setTimeout(() => this.scrollToBottom(false), 100)
}

resetInputToolbar() {
Expand Down
13 changes: 8 additions & 5 deletions src/MessageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ export default class MessageContainer<
}
}

scrollToBottom = () => {
scrollToBottom = (animated: boolean = true) => {
const { inverted } = this.props
if (inverted) {
this.scrollTo({ offset: 0, animated: true })
this.scrollTo({ offset: 0, animated })
} else {
this.props.forwardRef!.current!.scrollToEnd({ animated: true })
this.props.forwardRef!.current!.scrollToEnd({ animated })
}
}

Expand Down Expand Up @@ -310,7 +310,7 @@ export default class MessageContainer<
return (
<View style={styles.scrollToBottomStyle}>
<TouchableOpacity
onPress={this.scrollToBottom}
onPress={() => this.scrollToBottom()}
hitSlop={{ top: 5, left: 5, right: 5, bottom: 5 }}
>
{this.renderScrollBottomComponent()}
Expand All @@ -325,7 +325,10 @@ export default class MessageContainer<
!!this.props.messages &&
this.props.messages!.length
) {
setTimeout(this.scrollToBottom, 150)
setTimeout(
() => this.scrollToBottom(false),
15 * this.props.messages!.length,
)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/MessageImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
StyleProp,
ImageStyle,
} from 'react-native'
// TODO: support web
// @ts-ignore
import Lightbox from 'react-native-lightbox'
import { IMessage } from './types'
Expand Down

0 comments on commit d827601

Please sign in to comment.