Skip to content

Commit ddef678

Browse files
author
Jaap
committed
Merge branch 'master' of github.com:GetStream/stream-chat-react
2 parents 88b57c9 + 3eaafa3 commit ddef678

File tree

5 files changed

+39
-20
lines changed

5 files changed

+39
-20
lines changed

src/components/InfiniteScrollPaginator/InfiniteScroll.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,24 @@ const InfiniteScroll = ({
7878
el.scrollHeight - parentElement.scrollTop - parentElement.clientHeight;
7979
reverseOffset = parentElement.scrollTop;
8080
}
81-
if (listenToScroll) listenToScroll(offset, reverseOffset);
81+
if (listenToScroll) {
82+
listenToScroll(offset, reverseOffset, threshold);
83+
}
8284

8385
// Here we make sure the element is visible as well as checking the offset
8486
if (
8587
(isReverse ? reverseOffset : offset) < Number(threshold) &&
8688
el.offsetParent !== null &&
87-
typeof loadMore === 'function'
89+
typeof loadMore === 'function' &&
90+
hasMore
8891
) {
8992
loadMore();
9093
}
91-
}, [useWindow, isReverse, threshold, listenToScroll, loadMore]);
94+
}, [hasMore, useWindow, isReverse, threshold, listenToScroll, loadMore]);
9295

9396
useEffect(() => {
9497
const scrollEl = useWindow ? window : scrollComponent.current?.parentNode;
95-
if (!hasMore || isLoading || !scrollEl) {
98+
if (isLoading || !scrollEl) {
9699
return () => {};
97100
}
98101

@@ -107,7 +110,7 @@ const InfiniteScroll = ({
107110
scrollEl.removeEventListener('scroll', scrollListener, useCapture);
108111
scrollEl.removeEventListener('resize', scrollListener, useCapture);
109112
};
110-
}, [hasMore, initialLoad, isLoading, scrollListener, useCapture, useWindow]);
113+
}, [initialLoad, isLoading, scrollListener, useCapture, useWindow]);
111114

112115
useEffect(() => {
113116
const scrollEl = useWindow ? window : scrollComponent.current?.parentNode;

src/components/MessageList/MessageList.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,11 @@ class MessageList extends PureComponent {
165165
this.setState({ newMessagesNotification: false });
166166
};
167167

168-
userScrolledUp = () => this.scrollOffset > 310;
168+
userScrolledUp = () => this.scrollOffset > 200;
169169

170-
listenToScroll = (offset) => {
170+
listenToScroll = (offset, reverseOffset, threshold) => {
171171
this.scrollOffset = offset;
172+
this.closeToTop = reverseOffset < threshold;
172173
if (this.state.newMessagesNotification && !this.userScrolledUp()) {
173174
this.setState({ newMessagesNotification: false });
174175
}
@@ -206,7 +207,7 @@ class MessageList extends PureComponent {
206207
onMessageLoadCaptured = () => {
207208
// A load event (emitted by e.g. an <img>) was captured on a message.
208209
// In some cases, the loaded asset is larger than the placeholder, which means we have to scroll down.
209-
if (!this.userScrolledUp()) {
210+
if (!this.userScrolledUp() && !this.closeToTop) {
210211
this.scrollToBottom();
211212
}
212213
};

src/styles/DateSeparator.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.str-chat__date-separator {
22
display: flex;
3-
margin: 40px;
3+
padding: 40px;
44
align-items: center;
55

66
&-date {
@@ -25,7 +25,7 @@
2525

2626
.commerce.str-chat {
2727
.str-chat__date-separator {
28-
margin: 40px 0;
28+
padding: 40px 0;
2929
}
3030
}
3131

src/styles/MessageList.scss

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
overflow-x: hidden;
44
overflow-y: auto;
55
-webkit-overflow-scrolling: touch; /* enable smooth scrolling on ios */
6-
padding: 75px 0 0 0;
6+
padding: 0 0 0 0;
7+
.str-chat__reverse-infinite-scroll {
8+
padding-top: 75px;
9+
}
710

811
&-wrapper {
912
flex: 1;
@@ -30,9 +33,6 @@
3033
margin: 0;
3134
}
3235

33-
.str-chat__reverse-infinite-scroll {
34-
}
35-
3636
.str-chat__custom-notification {
3737
border-radius: 4px;
3838
font-size: 12px;
@@ -76,9 +76,11 @@
7676
&.str-chat {
7777
.str-chat {
7878
&__list {
79-
padding: 55px 40px 0;
79+
padding: 0 40px 0;
8080
background: white;
81-
81+
.str-chat__reverse-infinite-scroll {
82+
padding-top: 55px;
83+
}
8284
&-notifications {
8385
background: white;
8486
}
@@ -87,7 +89,10 @@
8789
@media screen and (max-width: 960px) {
8890
.str-chat {
8991
&__list {
90-
padding: 55px 10px 0;
92+
padding: 0 10px 0;
93+
.str-chat__reverse-infinite-scroll {
94+
padding-top: 55px;
95+
}
9196
&-notifications {
9297
padding: 0 10px;
9398
}
@@ -109,7 +114,10 @@
109114
&.str-chat {
110115
.str-chat {
111116
&__list {
112-
padding: 55px 10px;
117+
padding: 0 10px;
118+
.str-chat__reverse-infinite-scroll {
119+
padding-top: 55px;
120+
}
113121
}
114122
}
115123
}
@@ -119,7 +127,10 @@
119127
&.str-chat {
120128
.str-chat {
121129
&__list {
122-
padding: 75px 20px 0;
130+
padding: 0 20px 0;
131+
.str-chat__reverse-infinite-scroll {
132+
padding-top: 75px;
133+
}
123134
&-notifications {
124135
padding-left: 22px;
125136
padding-right: 22px;

types/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,11 @@ export interface InfiniteScrollProps {
10711071
loader?: React.ReactNode;
10721072
threshold?: number;
10731073
children?: any;
1074-
listenToScroll?: (offset: number, reverseOffset: number) => void;
1074+
listenToScroll?: (
1075+
offset: number,
1076+
reverseOffset: number,
1077+
threshold: number,
1078+
) => void;
10751079
}
10761080

10771081
export interface ModalImageProps {

0 commit comments

Comments
 (0)