Added pull to refresh capability to StatusList, ScrollableList for HomeTimeline to start

• Added:
- pull to refresh capability to StatusList, ScrollableList for HomeTimeline to start

• Updated:
- PullToRefresher styles

• Todo:
- Will add to additional timelines soon
This commit is contained in:
mgabdev 2020-06-05 21:45:58 -04:00
parent 91a227913a
commit 67824bb5e1
4 changed files with 30 additions and 11 deletions

View File

@ -1,14 +1,17 @@
import { BREAKPOINT_EXTRA_SMALL } from '../constants' import { BREAKPOINT_EXTRA_SMALL } from '../constants'
import Responsive from '../features/ui//util/responsive_component' import Responsive from '../features/ui//util/responsive_component'
import Icon from './icon' import Icon from './icon'
import Text from './text'
export default class PullToRefresher extends PureComponent { export default class PullToRefresher extends PureComponent {
render() { render() {
return ( return (
<Responsive max={BREAKPOINT_EXTRA_SMALL}> <Responsive max={BREAKPOINT_EXTRA_SMALL}>
<div className={[_s.default, _s.alignItemsCenter, _s.posAbs, _s.left0, _s.right0, _s.topNeg80PX].join(' ')}> <div className={[_s.default, _s.height53PX, _s.width100PC, _s.alignItemsCenter, _s.posAbs, _s.left0, _s.right0, _s.topNeg50PX].join(' ')}>
<Icon id='loading' size='24px' /> <div className={[_s.default, _s.width100PC, _s.alignItemsCenter].join(' ')}>
<Icon id='loading' size='24px' />
</div>
</div> </div>
</Responsive> </Responsive>
) )

View File

@ -31,6 +31,7 @@ export default class ScrollableList extends PureComponent {
} }
state = { state = {
pullToRefreshTriggered: false,
cachedMediaWidth: 250, // Default media/card width using default Gab Social theme cachedMediaWidth: 250, // Default media/card width using default Gab Social theme
} }
@ -126,8 +127,11 @@ export default class ScrollableList extends PureComponent {
const { innerHeight } = this.window; const { innerHeight } = this.window;
const offset = scrollHeight - scrollTop - innerHeight; const offset = scrollHeight - scrollTop - innerHeight;
if (scrollTop < -60 && this.props.onReload) { if (scrollTop < -80 && this.props.onReload && !this.state.pullToRefreshTriggered) {
// reload this.setState({ pullToRefreshTriggered: true })
} else if (scrollTop > -10 && this.props.onReload && this.state.pullToRefreshTriggered) {
this.props.onReload()
this.setState({ pullToRefreshTriggered: false })
} }
if (600 > offset && this.props.onLoadMore && this.props.hasMore && !this.props.isLoading) { if (600 > offset && this.props.onLoadMore && this.props.hasMore && !this.props.isLoading) {

View File

@ -106,13 +106,20 @@ class StatusList extends ImmutablePureComponent {
} }
state = { state = {
refreshing: false,
fetchedContext: false, fetchedContext: false,
} }
componentDidMount() { componentDidMount() {
this.handleDequeueTimeline(); this.handleDequeueTimeline();
this.fetchPromotedStatus(); this.fetchPromotedStatus();
}; }
componentDidUpdate(prevProps, prevState) {
if (prevState.refreshing) {
this.setState({ refreshing: false })
}
}
fetchPromotedStatus() { fetchPromotedStatus() {
const { promotion, promotedStatus, fetchStatus } = this.props; const { promotion, promotedStatus, fetchStatus } = this.props;
@ -157,9 +164,13 @@ class StatusList extends ImmutablePureComponent {
this.props.onLoadMore(this.props.statusIds.size > 0 ? this.props.statusIds.last() : undefined) this.props.onLoadMore(this.props.statusIds.size > 0 ? this.props.statusIds.last() : undefined)
}, 300, { leading: true }) }, 300, { leading: true })
handleReload = debounce(() => { handleOnReload = debounce(() => {
this.props.onLoadMore() // Only pull to refresh on home timeline for now
}, 300, { leading: true }) if (this.props.scrollKey === 'home_timeline' && !this.state.refreshing) {
this.props.onLoadMore()
this.setState({ refreshing: true })
}
}, 300, { trailing: true })
_selectChild(index, align_top) { _selectChild(index, align_top) {
const container = this.node.node; const container = this.node.node;
@ -200,7 +211,7 @@ class StatusList extends ImmutablePureComponent {
promotedStatus, promotedStatus,
...other ...other
} = this.props } = this.props
const { fetchedContext } = this.state const { fetchedContext, refreshing } = this.state
if (isPartial) { if (isPartial) {
return <ColumnIndicator type='loading' /> return <ColumnIndicator type='loading' />
@ -262,8 +273,9 @@ class StatusList extends ImmutablePureComponent {
<ScrollableList <ScrollableList
ref={this.setRef} ref={this.setRef}
isLoading={isLoading} isLoading={isLoading}
showLoading={isLoading && statusIds.size === 0} showLoading={(isLoading && statusIds.size === 0) || refreshing}
onLoadMore={onLoadMore && this.handleLoadOlder} onLoadMore={onLoadMore && this.handleLoadOlder}
onReload={this.handleOnReload}
{...other} {...other}
> >
{scrollableContent} {scrollableContent}

View File

@ -420,7 +420,7 @@ body {
/* */ /* */
.topNeg80PX { top: -80px; } .topNeg50PX { top: -50px; }
.top0 { top: 0; } .top0 { top: 0; }
.top120PX { top: 120px; } .top120PX { top: 120px; }
.top60PC { top: 60%; } .top60PC { top: 60%; }