Improve modal flow and back button handling (#16499)
* Refactor shouldUpdateScroll passing So far, shouldUpdateScroll has been manually passed down from the very top of the React component hierarchy even though it is a static function common to all ScrollContainer instances, so replaced that with a custom class extending ScrollContainer. * Generalize “press back to close modal” to any modal and to public pages * Fix boost confirmation modal closing media modal
This commit is contained in:
parent
a2ce7508c9
commit
d3791cca0c
35 changed files with 120 additions and 197 deletions
|
@ -10,8 +10,6 @@ import { hydrateStore } from '../actions/store';
|
|||
import { connectUserStream } from '../actions/streaming';
|
||||
import { IntlProvider, addLocaleData } from 'react-intl';
|
||||
import { getLocale } from '../locales';
|
||||
import { previewState as previewMediaState } from 'mastodon/features/ui/components/media_modal';
|
||||
import { previewState as previewVideoState } from 'mastodon/features/ui/components/video_modal';
|
||||
import initialState from '../initial_state';
|
||||
import ErrorBoundary from '../components/error_boundary';
|
||||
|
||||
|
@ -41,8 +39,8 @@ export default class Mastodon extends React.PureComponent {
|
|||
}
|
||||
}
|
||||
|
||||
shouldUpdateScroll (_, { location }) {
|
||||
return location.state !== previewMediaState && location.state !== previewVideoState;
|
||||
shouldUpdateScroll (prevRouterProps, { location }) {
|
||||
return !(location.state?.mastodonModalKey && location.state?.mastodonModalKey !== prevRouterProps?.location?.state?.mastodonModalKey);
|
||||
}
|
||||
|
||||
render () {
|
||||
|
|
18
app/javascript/mastodon/containers/scroll_container.js
Normal file
18
app/javascript/mastodon/containers/scroll_container.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { ScrollContainer as OriginalScrollContainer } from 'react-router-scroll-4';
|
||||
|
||||
// ScrollContainer is used to automatically scroll to the top when pushing a
|
||||
// new history state and remembering the scroll position when going back.
|
||||
// There are a few things we need to do differently, though.
|
||||
const defaultShouldUpdateScroll = (prevRouterProps, { location }) => {
|
||||
// If the change is caused by opening a modal, do not scroll to top
|
||||
return !(location.state?.mastodonModalKey && location.state?.mastodonModalKey !== prevRouterProps?.location?.state?.mastodonModalKey);
|
||||
};
|
||||
|
||||
export default
|
||||
class ScrollContainer extends OriginalScrollContainer {
|
||||
|
||||
static defaultProps = {
|
||||
shouldUpdateScroll: defaultShouldUpdateScroll,
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue