Skip to content

Commit 3beb1d7

Browse files
Changes before error encountered
Co-authored-by: kesha-antonov <11584712+kesha-antonov@users.noreply.github.com>
1 parent 816a6dc commit 3beb1d7

File tree

7 files changed

+366
-10
lines changed

7 files changed

+366
-10
lines changed

src/GiftedChat/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ export interface GiftedChatProps<TMessage extends IMessage> extends Partial<Mess
168168
renderCustomView?(props: BubbleProps<TMessage>): React.ReactNode
169169
/* Custom day above a message */
170170
renderDay?(props: DayProps): React.ReactNode
171+
/* Controls whether to show the floating sticky date; default is true */
172+
showStickyDate?: boolean
171173
/* Custom time inside a message */
172174
renderTime?(props: TimeProps<TMessage>): React.ReactNode
173175
/* Custom footer component on the ListView, e.g. 'User is typing...' */

src/MessageContainer/index.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function MessageContainer<TMessage extends IMessage = IMessage> (props: MessageC
5454
handleOnScroll: handleOnScrollProp,
5555
scrollToBottomComponent: scrollToBottomComponentProp,
5656
renderDay: renderDayProp,
57+
showStickyDate = true,
5758
} = props
5859

5960
const scrollToBottomOpacity = useSharedValue(0)
@@ -376,14 +377,18 @@ function MessageContainer<TMessage extends IMessage = IMessage> (props: MessageC
376377
{isScrollToBottomEnabled
377378
? renderScrollToBottomWrapper()
378379
: null}
379-
<DayAnimated
380-
scrolledY={scrolledY}
381-
daysPositions={daysPositions}
382-
listHeight={listHeight}
383-
renderDay={renderDayProp}
384-
messages={messages}
385-
isLoadingEarlier={isLoadingEarlier}
386-
/>
380+
{showStickyDate
381+
? (
382+
<DayAnimated
383+
scrolledY={scrolledY}
384+
daysPositions={daysPositions}
385+
listHeight={listHeight}
386+
renderDay={renderDayProp}
387+
messages={messages}
388+
isLoadingEarlier={isLoadingEarlier}
389+
/>
390+
)
391+
: null}
387392
</View>
388393
)
389394
}

src/MessageContainer/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77

88
import { LoadEarlierProps } from '../LoadEarlier'
99
import { MessageProps } from '../Message'
10-
import {User, IMessage, Reply, DayProps} from '../types'
10+
import { User, IMessage, Reply, DayProps } from '../types'
1111
import { ReanimatedScrollEvent } from 'react-native-reanimated/lib/typescript/hook/commonTypes'
1212
import { FlatList } from 'react-native-reanimated/lib/typescript/Animated'
1313
import { AnimateProps } from 'react-native-reanimated'
@@ -34,6 +34,7 @@ export interface MessageContainerProps<TMessage extends IMessage = IMessage> {
3434
renderFooter?(props: MessageContainerProps<TMessage>): React.ReactNode
3535
renderMessage?(props: MessageProps<TMessage>): React.ReactElement
3636
renderDay?(props: DayProps): React.ReactNode
37+
showStickyDate?: boolean
3738
renderLoadEarlier?(props: LoadEarlierProps): React.ReactNode
3839
renderTypingIndicator?(): React.ReactNode
3940
scrollToBottomComponent?(): React.ReactNode

src/__tests__/GiftedChat.test.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const messages = [
99
{
1010
_id: 1,
1111
text: 'Hello developer',
12-
createdAt: new Date(),
12+
createdAt: new Date('2023-01-01T12:00:00.000Z'),
1313
user: {
1414
_id: 2,
1515
name: 'React Native',
@@ -40,3 +40,28 @@ it('should render <GiftedChat/> and compare with snapshot', () => {
4040

4141
expect(tree.toJSON()).toMatchSnapshot()
4242
})
43+
44+
it('should render <GiftedChat/> with showStickyDate=false and compare with snapshot', () => {
45+
let tree
46+
47+
renderer.act(() => {
48+
(useReanimatedKeyboardAnimation as jest.Mock).mockReturnValue({
49+
height: {
50+
value: 0,
51+
},
52+
})
53+
54+
tree = renderer.create(
55+
<GiftedChat
56+
messages={messages}
57+
onSend={() => {}}
58+
user={{
59+
_id: 1,
60+
}}
61+
showStickyDate={false}
62+
/>
63+
)
64+
})
65+
66+
expect(tree.toJSON()).toMatchSnapshot()
67+
})

src/__tests__/MessageContainer.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,32 @@ import renderer from 'react-test-renderer'
44

55
import { MessageContainer } from '../GiftedChat'
66

7+
const messages = [
8+
{
9+
_id: 1,
10+
text: 'Hello developer',
11+
createdAt: new Date('2023-01-01T12:00:00.000Z'),
12+
user: {
13+
_id: 2,
14+
name: 'React Native',
15+
},
16+
},
17+
]
18+
719
it('should render <MessageContainer /> and compare with snapshot', () => {
820
const tree = renderer.create(<MessageContainer />).toJSON()
921

1022
expect(tree).toMatchSnapshot()
1123
})
24+
25+
it('should render <MessageContainer /> with showStickyDate=true (default)', () => {
26+
const tree = renderer.create(<MessageContainer messages={messages} />).toJSON()
27+
28+
expect(tree).toMatchSnapshot()
29+
})
30+
31+
it('should render <MessageContainer /> with showStickyDate=false', () => {
32+
const tree = renderer.create(<MessageContainer messages={messages} showStickyDate={false} />).toJSON()
33+
34+
expect(tree).toMatchSnapshot()
35+
})

src/__tests__/__snapshots__/GiftedChat.test.tsx.snap

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,30 @@ exports[`should render <GiftedChat/> and compare with snapshot 1`] = `
2626
</View>
2727
</KeyboardProvider>
2828
`;
29+
30+
exports[`should render <GiftedChat/> with showStickyDate=false and compare with snapshot 1`] = `
31+
<KeyboardProvider>
32+
<View
33+
style={
34+
{
35+
"flex": 1,
36+
}
37+
}
38+
>
39+
<View
40+
onLayout={[Function]}
41+
style={
42+
[
43+
{
44+
"flex": 1,
45+
},
46+
{
47+
"overflow": "hidden",
48+
},
49+
]
50+
}
51+
testID="GC_WRAPPER"
52+
/>
53+
</View>
54+
</KeyboardProvider>
55+
`;

0 commit comments

Comments
 (0)