Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scroll to bottom cb #2260

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ interface QuickReplies {
* **`scrollToBottomComponent`** _(Function)_ - Custom Scroll To Bottom Component container
* **`scrollToBottomOffset`** _(Integer)_ - Custom Height Offset upon which to begin showing Scroll To Bottom Component (Default is 200)
* **`scrollToBottomStyle`** _(Object)_ - Custom style for Bottom Component container
- **`onScrolledToBottom`** _(Function)_ - Callback when the scroll to bottom component toggles visibility, must be used with `scrollToBottom`
* **`alignTop`** _(Boolean)_ Controls whether or not the message bubbles appear at the top of the chat (Default is false - bubbles align to bottom)
* **`onQuickReply`** _(Function)_ - Callback when sending a quick reply (to backend server)
* **`renderQuickReplies`** _(Function)_ - Custom all quick reply view
Expand Down
5 changes: 5 additions & 0 deletions src/GiftedChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export interface GiftedChatProps<TMessage extends IMessage = IMessage> {
onSend?(messages: TMessage[]): void
/*Callback when loading earlier messages*/
onLoadEarlier?(): void
/*Callback when scroll to bottom*/
onScrolledToBottom?(atBottom: boolean): void
/* Render a loading view when initializing */
renderLoading?(): React.ReactNode
/* Custom "Load earlier messages" button */
Expand Down Expand Up @@ -250,6 +252,7 @@ class GiftedChat<TMessage extends IMessage = IMessage> extends React.Component<
dateFormat: DATE_FORMAT,
loadEarlier: false,
onLoadEarlier: () => {},
onScrolledToBottom: () => {},
isLoadingEarlier: false,
renderLoading: null,
renderLoadEarlier: null,
Expand Down Expand Up @@ -321,6 +324,7 @@ class GiftedChat<TMessage extends IMessage = IMessage> extends React.Component<
isKeyboardInternallyHandled: PropTypes.bool,
loadEarlier: PropTypes.bool,
onLoadEarlier: PropTypes.func,
onScrolledToBottom: PropTypes.func,
isLoadingEarlier: PropTypes.bool,
renderLoading: PropTypes.func,
renderLoadEarlier: PropTypes.func,
Expand Down Expand Up @@ -694,6 +698,7 @@ class GiftedChat<TMessage extends IMessage = IMessage> extends React.Component<
>
<MessageContainer<TMessage>
{...messagesContainerProps}
onScrolledToBottom={this.props.onScrolledToBottom}
invertibleScrollViewProps={this.invertibleScrollViewProps}
messages={this.getMessages()}
forwardRef={this._messageContainerRef}
Expand Down
16 changes: 16 additions & 0 deletions src/MessageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export interface MessageContainerProps<TMessage extends IMessage> {
renderLoadEarlier?(props: LoadEarlierProps): React.ReactNode
scrollToBottomComponent?(): React.ReactNode
onLoadEarlier?(): void
onScrolledToBottom?(atBottom: boolean): void
onQuickReply?(replies: Reply[]): void
infiniteScroll?: boolean
isLoadingEarlier?: boolean
Expand All @@ -107,6 +108,7 @@ export default class MessageContainer<
renderFooter: null,
renderMessage: null,
onLoadEarlier: () => {},
onScrolledToBottom: () => {},
onQuickReply: () => {},
inverted: true,
loadEarlier: false,
Expand All @@ -130,6 +132,7 @@ export default class MessageContainer<
renderMessage: PropTypes.func,
renderLoadEarlier: PropTypes.func,
onLoadEarlier: PropTypes.func,
onScrolledToBottom: PropTypes.func,
listViewProps: PropTypes.object,
inverted: PropTypes.bool,
loadEarlier: PropTypes.bool,
Expand All @@ -148,6 +151,19 @@ export default class MessageContainer<
hasScrolled: false,
}

componentDidUpdate = (
_: MessageContainerProps<TMessage>,
prevState: State,
) => {
if (
this.props.onScrolledToBottom &&
prevState.showScrollBottom !== this.state.showScrollBottom
) {
if (this.props.onScrolledToBottom)
this.props.onScrolledToBottom(!this.state.showScrollBottom)
}
}

renderTypingIndicator = () => {
if (Platform.OS === 'web') {
return null
Expand Down