Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix column swiping #4211

Merged
merged 1 commit into from
Jul 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion app/javascript/mastodon/features/ui/components/columns_area.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,22 @@ export default class ColumnsArea extends ImmutablePureComponent {
children: PropTypes.node,
};

state = {
shouldAnimate: false,
}

componentWillReceiveProps() {
this.setState({ shouldAnimate: false });
}

componentDidMount() {
this.lastIndex = getIndex(this.context.router.history.location.pathname);
this.setState({ shouldAnimate: true });
}

componentDidUpdate() {
this.lastIndex = getIndex(this.context.router.history.location.pathname);
this.setState({ shouldAnimate: true });
}

handleSwipe = (index) => {
Expand Down Expand Up @@ -74,9 +88,10 @@ export default class ColumnsArea extends ImmutablePureComponent {

render () {
const { columns, children, singleColumn } = this.props;
const { shouldAnimate } = this.state;

const columnIndex = getIndex(this.context.router.history.location.pathname);
const shouldAnimate = Math.abs(this.lastIndex - columnIndex) === 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we animate if we move to the previous / next tab? Might help with discoverability of the feature and - subjective - I think it looks nice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also feel that it improves perceived performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we use animation for location change based transition, columnIndex is already new one before transition, whereas it's old one on swiping based transition. So destination column will be rendered before animated transition.

I don't feel it improves perceived performance so much, on my (slow) device which takes some freeze time anyway. Also transition to rendering looks not bad, but different from behavior on swiping.

Well...I wonder that if we make same behavior as swiping, i.e. render destination while/after transition.

this.pendingIndex = null;

if (singleColumn) {
return columnIndex !== -1 ? (
Expand Down