Skip to content

RNMobile: image block vol 03 (sizes)#9975

Closed
etoledom wants to merge 25 commits intomasterfrom
rnmobile/image-block-vol-03
Closed

RNMobile: image block vol 03 (sizes)#9975
etoledom wants to merge 25 commits intomasterfrom
rnmobile/image-block-vol-03

Conversation

@etoledom
Copy link
Copy Markdown
Contributor

@etoledom etoledom commented Sep 17, 2018

Description

This PR adds the ability to the image block of interpreting size changes made by the user.

I added a temporal size setting UI for testing purposes, but this should be replaced later with the definitive block settings UI.

I keep following closely the logic used on the web version, so (hopefully) anybody can later on check it out and understand it easily.

The visual resizing of the image currently doesn't behave exactly as on the web version, but this PR is intended to add the basics of resizing. Layer on we can decide how do we want this to behave exactly on mobile.

This is not supposed to handle image updates (change of images) either.

Screenshots

image_block_resizing

To test:

  • Checkout the mobile-gutenberg PR for this feature.
  • Run the project.
  • Check that the image is displaying.
  • Select the image block.
  • Check that it shows the size controls at the top with the default image size.
  • Change the size of the image using the controls.
  • Check that the image resizes accordingly.
  • Check that the image never grows bigger than the block canvas.
  • Switch to HTML output view.
  • Check that the size changes are reflected on the HTML code (as shown on the screenshot)

@etoledom etoledom added the Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) label Sep 17, 2018
@etoledom etoledom self-assigned this Sep 17, 2018
@etoledom etoledom requested a review from hypest September 18, 2018 00:31
@daniloercoli
Copy link
Copy Markdown
Contributor

I keep following closely the logic used on the web version, so (hopefully) anybody can later on check it out and understand it easily.

Do you think there is way to make one single ImageSize component, or make common some of the image resizing logic in a utils.js file used by both web and native implementation of ImageSize? (I think we can do that in another PR if you prefer).

@daniloercoli daniloercoli self-requested a review September 18, 2018 15:41
@etoledom
Copy link
Copy Markdown
Contributor Author

I thought about it:

The math part could easily be shared. But since this is client related code, and clients are different (mobile-web), it might be a good idea to let those calculations be updated separately. So, for example, if the way these sizes are calculated had to change on the web side for any reason, it doesn't affect mobile.

If that's true, we are not repeating code, but the fact that they look like the same is a temporal coincidence.

Anyway, we can decide to share the code if we are sure it will be always the same for all the platforms.

If that's the case, I'd agree on doing it on a future PR. 👍

@hypest
Copy link
Copy Markdown
Contributor

hypest commented Sep 18, 2018

Can we extract the computation code to its own function and in a dedicated module? The idea here is to then have a .native.js counterpart to nativize stuff. For example, I'm looking at the componentDidMount() method and I think that could be identical between the platforms and the difference could be inside the fetchImageSize method if it makes sense.

@etoledom
Copy link
Copy Markdown
Contributor Author

Thanks @hypest !

I made the change we talked about:
Now the ImageSize component is shared between web and mobile, and the platform specific parts were extracted into utils.js and utils.native.js.

The mobile version is working as before, and the web tests are all passing (locally at least).
I'm still not 100% confident that the web version is working as it was before.

@etoledom etoledom requested a review from a team September 21, 2018 14:22
Copy link
Copy Markdown
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.

👋 @etoledom ! I only left one minor comment but, in general I think the implementation of ImageSize and utils.js is in the right direction but still feels kinda awkward. Perhaps having the util functions become a class that ImageSize can then extend could help clarify the code? I'm not too sure about it though and I think I could use a GB web dev's opinion here so, I'll leave that for others to review.

*/
import { noop } from 'lodash';

import { Component } from '@wordpress/element';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's reinstate the WordPress dependencies section header here.

@etoledom
Copy link
Copy Markdown
Contributor Author

etoledom commented Sep 24, 2018

@hypest - Maybe implementing that in the way @daniloercoli suggested would be less invasive?
We still will be sharing most of the non-platform specific code.

@hypest
Copy link
Copy Markdown
Contributor

hypest commented Sep 26, 2018

Maybe implementing that in the way @daniloercoli suggested would be less invasive?

Hmm, not sure what exactly is different right now, compared to Danilo's sugegstion. Perhaps I didn't understand Danilo's suggestion.

In any case, the code doesn't seem to be too invasive. It's OK to refactor web-side code to help group the platform agnostic code from the platform specific so, as far as I can tell, we're good so far. I still think that we could use an eye from a web side colleague so, let's wait. @gziolo , maybe you can have a look here?

There's a chance my "... is the right direction but still feels kinda awkward" comment needs some explaining. I was looking at the code and noticed this pattern:

onLayout( event ) {
	onLayout( event, ( container ) => {
		this.container = container;
		this.calculateSize();
	} );
}

Now, it seems that in ImageSize we have a onLayout method that calls onLayout from utils, passing a "callback" to actually continue the original onLayout call. This is what feels awkward. Can't we just call utils.onLayout(), returning the container directly? Similar with fetchImageSize. Chances are I'm missing some point/detail here so, please feel free to elaborate. Thanks!

@etoledom
Copy link
Copy Markdown
Contributor Author

etoledom commented Oct 10, 2018

@hypest - @daniloercoli idea was (and please correct me if I'm wrong) actually the opposite:

We would keep the image-size.js and image-size.native.js, extracting all the shared maths into a common utils.js.

I believe that, in this way, the implementation of the shared code would be simpler and less invasive on the web part, but reduced to just a couple of functions.


You are right, I believe that, in the case of utils.onLayout() we can return the container directly, but that's not the case with utils.fetchImageSize() where something similar happens.

I'll push an update with this change.

@etoledom etoledom mentioned this pull request Dec 25, 2018
@etoledom
Copy link
Copy Markdown
Contributor Author

This PR was replaced by #13096

@etoledom etoledom closed this Jan 18, 2019
@aduth aduth deleted the rnmobile/image-block-vol-03 branch January 25, 2019 21:37
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