Skip to content

Commit f963c75

Browse files
authored
fix: Applied scroll after rendering DOM using setTimeout (#1237)
[CLNP-5487](https://sendbird.atlassian.net/browse/CLNP-5487) [SBISSUE-17529](https://sendbird.atlassian.net/browse/SBISSUE-17529) #### Issue - OpenChannel scroll doesn't move when fetching the initial messages on mobile(iPhone) #### Fix - Applied scroll after rendering DOM using `setTimeout` [CLNP-5487]: https://sendbird.atlassian.net/browse/CLNP-5487?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ [SBISSUE-17529]: https://sendbird.atlassian.net/browse/SBISSUE-17529?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 2aa8288 commit f963c75

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/modules/OpenChannel/context/utils.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,29 @@ export const shouldFetchMore = (messageLength: number, maxMessages?: number): bo
2121
};
2222

2323
/* eslint-disable default-param-last */
24-
export const scrollIntoLast = (initialTry = 0, scrollRef: React.RefObject<HTMLElement>): void => {
24+
export const scrollIntoLast = (
25+
initialTry = 0,
26+
scrollRef: React.RefObject<HTMLElement>,
27+
): void => {
2528
const MAX_TRIES = 10;
26-
const currentTry = initialTry;
27-
if (currentTry > MAX_TRIES) {
29+
30+
if (initialTry > MAX_TRIES) {
2831
return;
2932
}
30-
try {
31-
const scrollDOM = scrollRef?.current || document.querySelector('.sendbird-openchannel-conversation-scroll__container__item-container');
32-
// eslint-disable-next-line no-multi-assign
33-
if (scrollDOM) {
33+
34+
const scrollDOM = scrollRef?.current
35+
|| document.querySelector('.sendbird-openchannel-conversation-scroll__container__item-container');
36+
37+
if (scrollDOM) {
38+
const applyScroll = () => {
39+
scrollDOM.style.overflow = 'auto';
3440
scrollDOM.scrollTop = scrollDOM.scrollHeight;
35-
}
36-
} catch (error) {
41+
};
42+
setTimeout(applyScroll);
43+
} else {
3744
setTimeout(() => {
38-
scrollIntoLast(currentTry + 1, scrollRef);
39-
}, 500 * currentTry);
45+
scrollIntoLast(initialTry + 1, scrollRef);
46+
}, 500 * initialTry);
4047
}
4148
};
4249

0 commit comments

Comments
 (0)