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

Have a image placeholder while image size is being calculated. #13777

Merged
merged 3 commits into from
Feb 18, 2019

Conversation

SergioEstevao
Copy link
Contributor

Description

Adds an image placeholder while ImageSize is calculating the dimensions of the image.

Refs: wordpress-mobile/gutenberg-mobile#451
simulator screen shot - iphone xr - 2019-02-08 at 14 14 05

@SergioEstevao SergioEstevao added Mobile Web Viewport sizes for mobile and tablet devices Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) labels Feb 8, 2019
@hypest
Copy link
Contributor

hypest commented Feb 11, 2019

while ImageSize is calculating the dimensions

👋 @SergioEstevao , why do we care about the specific time the image size is being computed? I assume that that's taken as a proxy that the image is not yet downloaded but, not sure. I think I might be missing some context here and it's not intuitive to find out.

Can you expand the PR description with some info on why do we do this solution? Ideally, adding some inline comments in the code can also help.

<Dashicon icon={ 'format-image' } size={ width } />
</View>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Returning early is fine but can be tricky understanding the code when skimming through. I think the code outside is rather trivial and small and I'd suggest we put it in an else block to help with readability. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

The lint rules in GB complain about that :).

Ah, there's no-else-return in place, right!

if ( this.state.width === undefined ) {
const width = 300;
return (
<View onLayout={ this.onLayout } style={ { flex: 1, flexDirection: 'row', justifyContent: 'center' } }>
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT about moving the style definition in a style file? There's already the ./styles.native.scss we can use.

@hypest
Copy link
Contributor

hypest commented Feb 11, 2019

@SergioEstevao , can you elaborate on the rationale behind having the placeholder logic be inside the ImageSize component instead of the parent? Seems to me that we're making this component more complex if besides image sizes, we also alter the rendered children here. 🤔

@SergioEstevao
Copy link
Contributor Author

SergioEstevao commented Feb 11, 2019 via email

@SergioEstevao
Copy link
Contributor Author

SergioEstevao commented Feb 11, 2019 via email

@hypest
Copy link
Contributor

hypest commented Feb 11, 2019

So one thing that makes we see the white screen, is that before we show anything image size need to download the image, find its size, calculate the optimal size to display and then display the image. This code was already in place not changed by me. What I did is that while that action is happening we show a placeholder image.

OK, thanks for expanding @SergioEstevao. Then I think the only open question for me is whether we are forced to render the placeholder here in the ImageSize component or that can be done in its children here: https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/image/edit.native.js#L288-L322

@SergioEstevao
Copy link
Contributor Author

@hypest updated the code according to your commentaries. Can you please give it another look?

Copy link
Contributor

@hypest hypest left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the changes @SergioEstevao !

@SergioEstevao SergioEstevao merged commit d80e15b into master Feb 18, 2019
@SergioEstevao SergioEstevao deleted the rnmobile/image_placeholder branch February 18, 2019 11:50
@youknowriad youknowriad added this to the 5.2 (Gutenberg) milestone Mar 4, 2019
youknowriad pushed a commit that referenced this pull request Mar 6, 2019
* Have a image placeholder while image size is being calculated.

* Move placeholder image to image block code.
youknowriad pushed a commit that referenced this pull request Mar 6, 2019
* Have a image placeholder while image size is being calculated.

* Move placeholder image to image block code.
@gziolo gziolo removed the Mobile Web Viewport sizes for mobile and tablet devices label Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants