Skip to content

Commit

Permalink
expose renderTypingIndicator and handleOnScroll which are already pas…
Browse files Browse the repository at this point in the history
…sed props
  • Loading branch information
NoodleOfDeath committed Dec 7, 2024
1 parent ca4466e commit 60c27a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/GiftedChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context'

dayjs.extend(localizedFormat)

export interface GiftedChatProps<TMessage extends IMessage = IMessage> {
export interface GiftedChatProps<TMessage extends IMessage = IMessage> extends Partial<Omit<MessageContainer<TMessage>, 'scrollToBottom'>> {
/* Message container ref */
messageContainerRef?: React.RefObject<FlatList<IMessage>>
/* text input ref */
Expand Down
11 changes: 8 additions & 3 deletions src/MessageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ export interface MessageContainerProps<TMessage extends IMessage> {
renderFooter?(props: MessageContainerProps<TMessage>): React.ReactNode
renderMessage?(props: Message['props']): React.ReactElement
renderLoadEarlier?(props: LoadEarlierProps): React.ReactNode
renderTypingIndicator?(): React.ReactNode
scrollToBottomComponent?(): React.ReactNode
onLoadEarlier?(): void
onQuickReply?(replies: Reply[]): void
infiniteScroll?: boolean
isLoadingEarlier?: boolean
handleOnScroll?(event: NativeSyntheticEvent<NativeScrollEvent>): void
}

interface State {
Expand Down Expand Up @@ -148,6 +150,8 @@ export default class MessageContainer<
}

renderTypingIndicator = () => {
if (this.props.renderTypingIndicator)
return this.props.renderTypingIndicator()
return <TypingIndicator isTyping={this.props.isTyping || false} />
}

Expand All @@ -158,7 +162,7 @@ export default class MessageContainer<
return this.renderTypingIndicator()
}

renderLoadEarlier = () => {
renderLoadEarlier = (props: LoadEarlierProps) => {
if (this.props.loadEarlier === true) {
const loadEarlierProps = {
...this.props,
Expand All @@ -168,7 +172,7 @@ export default class MessageContainer<

return <LoadEarlier {...loadEarlierProps} />
}
return null
return this.props.renderLoadEarlier?.(props)
}

scrollTo (options: { animated?: boolean, offset: number }) {
Expand All @@ -185,6 +189,7 @@ export default class MessageContainer<
}

handleOnScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
this.props.handleOnScroll?.(event)
const {
nativeEvent: {
contentOffset: { y: contentOffsetY },
Expand Down Expand Up @@ -261,7 +266,7 @@ export default class MessageContainer<
}

renderHeaderWrapper = () => (
<View style={styles.headerWrapper}>{this.renderLoadEarlier()}</View>
<View style={styles.headerWrapper}>{this.renderLoadEarlier(this.props)}</View>
)

renderScrollBottomComponent () {
Expand Down

0 comments on commit 60c27a3

Please sign in to comment.