Refresh on scroll-to-top by active section press (#1807)

This commit is contained in:
Paul Frazee
2023-11-03 14:53:47 -07:00
committed by GitHub
parent 445f976881
commit 4de852ded8
2 changed files with 4 additions and 13 deletions
+2 -6
View File
@@ -393,12 +393,8 @@ const FeedSection = React.forwardRef<SectionRef, FeedSectionProps>(
const onScrollToTop = useCallback(() => { const onScrollToTop = useCallback(() => {
scrollElRef.current?.scrollToOffset({offset: -headerHeight}) scrollElRef.current?.scrollToOffset({offset: -headerHeight})
}, [scrollElRef, headerHeight])
const onPressLoadLatest = React.useCallback(() => {
onScrollToTop()
feed.refresh() feed.refresh()
}, [feed, onScrollToTop]) }, [feed, scrollElRef, headerHeight])
React.useImperativeHandle(ref, () => ({ React.useImperativeHandle(ref, () => ({
scrollToTop: onScrollToTop, scrollToTop: onScrollToTop,
@@ -420,7 +416,7 @@ const FeedSection = React.forwardRef<SectionRef, FeedSectionProps>(
/> />
{(isScrolledDown || hasNew) && ( {(isScrolledDown || hasNew) && (
<LoadLatestBtn <LoadLatestBtn
onPress={onPressLoadLatest} onPress={onScrollToTop}
label="Load new posts" label="Load new posts"
showIndicator={hasNew} showIndicator={hasNew}
/> />
+2 -7
View File
@@ -558,13 +558,8 @@ const FeedSection = React.forwardRef<SectionRef, FeedSectionProps>(
const onScrollToTop = useCallback(() => { const onScrollToTop = useCallback(() => {
scrollElRef.current?.scrollToOffset({offset: -headerHeight}) scrollElRef.current?.scrollToOffset({offset: -headerHeight})
}, [scrollElRef, headerHeight])
const onPressLoadLatest = React.useCallback(() => {
onScrollToTop()
feed.refresh() feed.refresh()
}, [feed, onScrollToTop]) }, [feed, scrollElRef, headerHeight])
React.useImperativeHandle(ref, () => ({ React.useImperativeHandle(ref, () => ({
scrollToTop: onScrollToTop, scrollToTop: onScrollToTop,
})) }))
@@ -586,7 +581,7 @@ const FeedSection = React.forwardRef<SectionRef, FeedSectionProps>(
/> />
{(isScrolledDown || hasNew) && ( {(isScrolledDown || hasNew) && (
<LoadLatestBtn <LoadLatestBtn
onPress={onPressLoadLatest} onPress={onScrollToTop}
label="Load new posts" label="Load new posts"
showIndicator={hasNew} showIndicator={hasNew}
/> />