Don't reset scroll position when opening a modal

pull/614/head
Thibaut Girka 2018-07-27 17:59:52 +02:00 committed by ThibG
parent 5d060cb6e4
commit b02bfe86ce
15 changed files with 75 additions and 5 deletions

View File

@ -89,6 +89,10 @@ export default class AccountGallery extends ImmutablePureComponent {
this.handleScrollToBottom();
}
shouldUpdateScroll = (prevRouterProps, { location }) => {
return !(location.state && location.state.mastodonModalOpen)
}
render () {
const { medias, isLoading, hasMore } = this.props;
@ -110,7 +114,7 @@ export default class AccountGallery extends ImmutablePureComponent {
<Column>
<ColumnBackButton />
<ScrollContainer scrollKey='account_gallery'>
<ScrollContainer scrollKey='account_gallery' shouldUpdateScroll={this.shouldUpdateScroll}>
<div className='scrollable' onScroll={this.handleScroll}>
<HeaderContainer accountId={this.props.params.accountId} />

View File

@ -60,6 +60,10 @@ export default class AccountTimeline extends ImmutablePureComponent {
this.props.dispatch(expandAccountTimeline(this.props.params.accountId, { maxId, withReplies: this.props.withReplies }));
}
shouldUpdateScroll = (prevRouterProps, { location }) => {
return !(location.state && location.state.mastodonModalOpen)
}
render () {
const { statusIds, featuredStatusIds, isLoading, hasMore } = this.props;
@ -83,6 +87,7 @@ export default class AccountTimeline extends ImmutablePureComponent {
isLoading={isLoading}
hasMore={hasMore}
onLoadMore={this.handleLoadMore}
shouldUpdateScroll={this.shouldUpdateScroll}
/>
</Column>
);

View File

@ -42,6 +42,10 @@ export default class Blocks extends ImmutablePureComponent {
}
}
shouldUpdateScroll = (prevRouterProps, { location }) => {
return !(location.state && location.state.mastodonModalOpen)
}
render () {
const { intl, accountIds } = this.props;
@ -56,7 +60,7 @@ export default class Blocks extends ImmutablePureComponent {
return (
<Column name='blocks' icon='ban' heading={intl.formatMessage(messages.heading)}>
<ColumnBackButtonSlim />
<ScrollContainer scrollKey='blocks'>
<ScrollContainer scrollKey='blocks' shouldUpdateScroll={this.shouldUpdateScroll}>
<div className='scrollable' onScroll={this.handleScroll}>
{accountIds.map(id =>
<AccountContainer key={id} id={id} />

View File

@ -66,6 +66,10 @@ export default class Bookmarks extends ImmutablePureComponent {
this.props.dispatch(expandBookmarkedStatuses());
}, 300, { leading: true })
shouldUpdateScroll = (prevRouterProps, { location }) => {
return !(location.state && location.state.mastodonModalOpen)
}
render () {
const { intl, statusIds, columnId, multiColumn, hasMore, isLoading } = this.props;
const pinned = !!columnId;
@ -87,6 +91,7 @@ export default class Bookmarks extends ImmutablePureComponent {
trackScroll={!pinned}
statusIds={statusIds}
scrollKey={`bookmarked_statuses-${columnId}`}
shouldUpdateScroll={this.shouldUpdateScroll}
hasMore={hasMore}
isLoading={isLoading}
onLoadMore={this.handleLoadMore}

View File

@ -71,6 +71,10 @@ export default class CommunityTimeline extends React.PureComponent {
this.props.dispatch(expandCommunityTimeline({ maxId }));
}
shouldUpdateScroll = (prevRouterProps, { location }) => {
return !(location.state && location.state.mastodonModalOpen)
}
render () {
const { intl, hasUnread, columnId, multiColumn } = this.props;
const pinned = !!columnId;
@ -93,6 +97,7 @@ export default class CommunityTimeline extends React.PureComponent {
<StatusListContainer
trackScroll={!pinned}
scrollKey={`community_timeline-${columnId}`}
shouldUpdateScroll={this.shouldUpdateScroll}
timelineId='community'
onLoadMore={this.handleLoadMore}
emptyMessage={<FormattedMessage id='empty_column.community' defaultMessage='The local timeline is empty. Write something publicly to get the ball rolling!' />}

View File

@ -71,6 +71,10 @@ export default class DirectTimeline extends React.PureComponent {
this.props.dispatch(expandDirectTimeline({ maxId }));
}
shouldUpdateScroll = (prevRouterProps, { location }) => {
return !(location.state && location.state.mastodonModalOpen)
}
render () {
const { intl, hasUnread, columnId, multiColumn } = this.props;
const pinned = !!columnId;
@ -93,6 +97,7 @@ export default class DirectTimeline extends React.PureComponent {
<StatusListContainer
trackScroll={!pinned}
scrollKey={`direct_timeline-${columnId}`}
shouldUpdateScroll={this.shouldUpdateScroll}
timelineId='direct'
onLoadMore={this.handleLoadMore}
emptyMessage={<FormattedMessage id='empty_column.direct' defaultMessage="You don't have any direct messages yet. When you send or receive one, it will show up here." />}

View File

@ -40,6 +40,10 @@ export default class Blocks extends ImmutablePureComponent {
this.props.dispatch(expandDomainBlocks());
}, 300, { leading: true });
shouldUpdateScroll = (prevRouterProps, { location }) => {
return !(location.state && location.state.mastodonModalOpen)
}
render () {
const { intl, domains } = this.props;
@ -54,7 +58,7 @@ export default class Blocks extends ImmutablePureComponent {
return (
<Column icon='minus-circle' heading={intl.formatMessage(messages.heading)}>
<ColumnBackButtonSlim />
<ScrollableList scrollKey='domain_blocks' onLoadMore={this.handleLoadMore}>
<ScrollableList scrollKey='domain_blocks' onLoadMore={this.handleLoadMore} shouldUpdateScroll={this.shouldUpdateScroll}>
{domains.map(domain =>
<DomainContainer key={domain} domain={domain} />
)}

View File

@ -66,6 +66,10 @@ export default class Favourites extends ImmutablePureComponent {
this.props.dispatch(expandFavouritedStatuses());
}, 300, { leading: true })
shouldUpdateScroll = (prevRouterProps, { location }) => {
return !(location.state && location.state.mastodonModalOpen)
}
render () {
const { intl, statusIds, columnId, multiColumn, hasMore, isLoading } = this.props;
const pinned = !!columnId;
@ -87,6 +91,7 @@ export default class Favourites extends ImmutablePureComponent {
trackScroll={!pinned}
statusIds={statusIds}
scrollKey={`favourited_statuses-${columnId}`}
shouldUpdateScroll={this.shouldUpdateScroll}
hasMore={hasMore}
isLoading={isLoading}
onLoadMore={this.handleLoadMore}

View File

@ -56,6 +56,10 @@ export default class Following extends ImmutablePureComponent {
this.props.dispatch(expandFollowing(this.props.params.accountId));
}
shouldUpdateScroll = (prevRouterProps, { location }) => {
return !(location.state && location.state.mastodonModalOpen)
}
render () {
const { accountIds, hasMore } = this.props;
@ -77,7 +81,7 @@ export default class Following extends ImmutablePureComponent {
<Column>
<ColumnBackButton />
<ScrollContainer scrollKey='following'>
<ScrollContainer scrollKey='following' shouldUpdateScroll={this.shouldUpdateScroll}>
<div className='scrollable' onScroll={this.handleScroll}>
<div className='following'>
<HeaderContainer accountId={this.props.params.accountId} hideTabs />

View File

@ -82,6 +82,10 @@ export default class HashtagTimeline extends React.PureComponent {
this.props.dispatch(expandHashtagTimeline(this.props.params.id, { maxId }));
}
shouldUpdateScroll = (prevRouterProps, { location }) => {
return !(location.state && location.state.mastodonModalOpen)
}
render () {
const { hasUnread, columnId, multiColumn } = this.props;
const { id } = this.props.params;
@ -106,6 +110,7 @@ export default class HashtagTimeline extends React.PureComponent {
scrollKey={`hashtag_timeline-${columnId}`}
timelineId={`hashtag:${id}`}
onLoadMore={this.handleLoadMore}
shouldUpdateScroll={this.shouldUpdateScroll}
emptyMessage={<FormattedMessage id='empty_column.hashtag' defaultMessage='There is nothing in this hashtag yet.' />}
/>
</Column>

View File

@ -41,6 +41,10 @@ export default class PinnedStatuses extends ImmutablePureComponent {
this.column = c;
}
shouldUpdateScroll = (prevRouterProps, { location }) => {
return !(location.state && location.state.mastodonModalOpen)
}
render () {
const { intl, statusIds, hasMore } = this.props;
@ -50,6 +54,7 @@ export default class PinnedStatuses extends ImmutablePureComponent {
<StatusList
statusIds={statusIds}
scrollKey='pinned_statuses'
shouldUpdateScroll={this.shouldUpdateScroll}
hasMore={hasMore}
/>
</Column>

View File

@ -71,6 +71,10 @@ export default class PublicTimeline extends React.PureComponent {
this.props.dispatch(expandPublicTimeline({ maxId }));
}
shouldUpdateScroll = (prevRouterProps, { location }) => {
return !(location.state && location.state.mastodonModalOpen)
}
render () {
const { intl, columnId, hasUnread, multiColumn } = this.props;
const pinned = !!columnId;
@ -95,6 +99,7 @@ export default class PublicTimeline extends React.PureComponent {
onLoadMore={this.handleLoadMore}
trackScroll={!pinned}
scrollKey={`public_timeline-${columnId}`}
shouldUpdateScroll={this.shouldUpdateScroll}
emptyMessage={<FormattedMessage id='empty_column.public' defaultMessage='There is nothing here! Write something publicly, or manually follow users from other instances to fill it up' />}
/>
</Column>

View File

@ -47,6 +47,10 @@ export default class CommunityTimeline extends React.PureComponent {
this.props.dispatch(expandCommunityTimeline({ maxId }));
}
shouldUpdateScroll = (prevRouterProps, { location }) => {
return !(location.state && location.state.mastodonModalOpen)
}
render () {
const { intl } = this.props;
@ -62,6 +66,7 @@ export default class CommunityTimeline extends React.PureComponent {
timelineId='community'
onLoadMore={this.handleLoadMore}
scrollKey='standalone_public_timeline'
shouldUpdateScroll={this.shouldUpdateScroll}
trackScroll={false}
/>
</Column>

View File

@ -41,6 +41,10 @@ export default class HashtagTimeline extends React.PureComponent {
this.props.dispatch(expandHashtagTimeline(this.props.hashtag, { maxId }));
}
shouldUpdateScroll = (prevRouterProps, { location }) => {
return !(location.state && location.state.mastodonModalOpen)
}
render () {
const { hashtag } = this.props;
@ -55,6 +59,7 @@ export default class HashtagTimeline extends React.PureComponent {
<StatusListContainer
trackScroll={false}
scrollKey='standalone_hashtag_timeline'
shouldUpdateScroll={this.shouldUpdateScroll}
timelineId={`hashtag:${hashtag}`}
onLoadMore={this.handleLoadMore}
/>

View File

@ -342,6 +342,10 @@ export default class Status extends ImmutablePureComponent {
this.setState({ fullscreen: isFullscreen() });
}
shouldUpdateScroll = (prevRouterProps, { location }) => {
return !(location.state && location.state.mastodonModalOpen)
}
render () {
let ancestors, descendants;
const { setExpansion } = this;
@ -385,7 +389,7 @@ export default class Status extends ImmutablePureComponent {
)}
/>
<ScrollContainer scrollKey='thread'>
<ScrollContainer scrollKey='thread' shouldUpdateScroll={this.shouldUpdateScroll}>
<div className={classNames('scrollable', 'detailed-status__wrapper', { fullscreen })} ref={this.setRef}>
{ancestors}