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/Media library grid visually broken on mobile #53798

Conversation

richardkang112
Copy link
Contributor

Changes proposed in this Pull Request

  • Render only 3 or 1 media library list items per row on mobile viewport, regardless of the scale slider position.
  • Limit the maximum media scale value to 0.323 when the scale slider is visible.

Testing instructions

Please view http://calypso.localhost:3000/media/:domain on mobile width. The page should render 3 items per row on mobile viewport. You should be able to switch from 3 items per row to 1 item per row with the segmented control buttons. When you switch to a larger viewport (window screen width greater than 480) when the page was displaying 1 item per row on mobile viewport, the media scale value is set back to 0.323.

  • Before
    image

image

  • After
    image

image

Fixes #48227
Related to #8295

- Add the getMediaScalePreference selector to return default mobile viewport media scale value if needed
… on mobile viewport

- Use isMobile() function from @automattic/viewport to detect mobile viewport
- Use getMediaScalePreference selector instead of getPreference selector for fetching media scale value from Redux
@bluefuton bluefuton added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. [Feature] Media The media screen in Calypso, general media management, or integration with third party media. labels Jun 17, 2021
@griffbrad griffbrad requested a review from flootr June 18, 2021 14:35
client/state/preferences/selectors.js Outdated Show resolved Hide resolved
client/state/preferences/selectors.js Outdated Show resolved Hide resolved

if ( ( isMobile && mediaScale !== 1 ) || ( ! isMobile && mediaScale > SCALE_TOUCH_GRID ) ) {
return SCALE_TOUCH_GRID;
}
Copy link
Member

Choose a reason for hiding this comment

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

This condition deserves a comment that explains it. And maybe also being divided into two conditions:

  1. On mobile view, allow only 1 and 0.323 scales.
  2. On non-mobile view, don't allow the 1 scale: always show at least 3 columns.

And if the getMediaScalePreference selector ends up being called only at one place, let's inline it in that module. The selector is too specialized to be in the general-purpose state/preferences module.

};

static defaultProps = {
mediaValidationErrors: Object.freeze( {} ),
onAddMedia: noop,
source: '',
isMobile: isMobile(),
Copy link
Member

Choose a reason for hiding this comment

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

This default is not very useful in my opinion. It will be evaluated only once, when the app is loaded, and the result will be the default forever. And won't update when the window is resized.

Copy link
Member

Choose a reason for hiding this comment

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

The value of isMobile should be retrieved by wrapping the component with the withMobileBreakpoint HOC. It will observe window size changes and will automatically pass an always-up-to-date isBreakpointActive prop to the wrapped component.

@@ -364,6 +367,7 @@ export class MediaLibraryContent extends React.Component {
<MediaLibraryList
key="list-loading"
filterRequiresUpgrade={ this.props.filterRequiresUpgrade }
isMobile={ this.props.isMobile }
Copy link
Member

Choose a reason for hiding this comment

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

If we ended up drilling the isMobile prop from top down to the MediaLibraryScale component, can we use the mediaScale prop instead? That's the value we really want, isn't it?

That way, the mediaScale value will be computed only at one place, and passed down to all other components that need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we pass down mediaScale prop value to children components, I think they need to unsubscribe from the Redux Store because the mediaScale value from Redux would overwrite the value from the parent components. Would it be alright to unsubscribe?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what you mean by "unsubscribe". Do you mean that the MediaLibraryScale preference would no longer read the scale prop in Redux with getMediaScalePreference, but it would get the value in the regular scale prop from the parent component? Then yes, that's alright and desirable. Ideally, there would be only one getMediaScalePreference call at the top of the tree and scale would be passed down, exactly the same way as your patch currently does with the isMobile prop.

@richardkang112 richardkang112 force-pushed the fix/media-library-grid-visually-broken-on-mobile branch from 2de5556 to e1bf204 Compare June 22, 2021 03:35
@richardkang112 richardkang112 requested a review from a team June 22, 2021 03:41
@richardkang112 richardkang112 requested review from a team as code owners June 22, 2021 03:41
@richardkang112 richardkang112 requested a review from a team June 22, 2021 03:41
@richardkang112 richardkang112 force-pushed the fix/media-library-grid-visually-broken-on-mobile branch 2 times, most recently from 08b5869 to e3db3e6 Compare June 22, 2021 04:20
@richardkang112 richardkang112 force-pushed the fix/media-library-grid-visually-broken-on-mobile branch from e3db3e6 to d955c3c Compare June 22, 2021 04:25
@sirbrillig sirbrillig removed the request for review from a team June 22, 2021 14:52
@richardkang112
Copy link
Contributor Author

Sorry, I didn't mean to request review to bunch of people. I made some mistakes on Git.

@richardkang112 richardkang112 requested review from jsnajdr and removed request for a team June 24, 2021 01:07
Copy link
Member

@jsnajdr jsnajdr left a comment

Choose a reason for hiding this comment

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

Works great 👍 Thank you very much for a valuable contribution! ❤️

@jsnajdr jsnajdr merged commit 08e0bfb into Automattic:trunk Jun 24, 2021
@richardkang112 richardkang112 deleted the fix/media-library-grid-visually-broken-on-mobile branch June 24, 2021 15:08
@richardkang112
Copy link
Contributor Author

@jsnajdr Thank you very much for your feedback. They were crucial to solve the problem. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Media The media screen in Calypso, general media management, or integration with third party media. OSS Citizen [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Media library grid visually broken on mobile
3 participants