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

[RNMobile] RangeControl markup #18036

Merged
merged 8 commits into from
Nov 6, 2019
Merged

[RNMobile] RangeControl markup #18036

merged 8 commits into from
Nov 6, 2019

Conversation

jbinda
Copy link
Contributor

@jbinda jbinda commented Oct 20, 2019

Description

PR is connected with #1449 in gutenberg-mobile.

Please also refer to:

Related gutenberg-mobile PR

It presents ability to select all parents in cascade way (according to the way how selecting in groups works on web version)

How has this been tested?

  • Add below range cell implementation inside InspectorControls in edit.native.js
Usage of RangeControl
<RangeControl
icon={ 'admin-settings' }
label={ __( 'Slider' ) }
value={ sliderVal }
initialPosition={ 25 }
min={ 20 }
max={ 100 }
separatorType={ 'fullWidth' }
onChange={ this.updateSlider }
/>
  • add handler to change slider value
Handler to change slider value
updateSlider( newVal ) {
    this.props.setAttributes( { sliderVal: newVal } );
}
  • reset sliderVal to null in onClearSettings() function

I have also test this feature by merging this PR changes and this branch into Gallery try feature.

After switch to Gallery branch I need to temporary comment some code in edit.js in block-library/gallery which produced error. See details below:

componentDidMount() {
	const { attributes, mediaUpload } = this.props;
	const { images } = attributes;
	if ( every( images, ( { url } ) => isBlobURL( url ) ) ) {
		const filesList = map( images, ( { url } ) => getBlobByURL( url ) );
		forEach( images, ( { url } ) => revokeBlobURL( url ) );
		// mediaUpload( {
		// 	filesList,
		// 	onFileChange: this.onSelectImages,
		// 	allowedTypes: [ 'image' ],
		// } );
	}
}

Then I was able to test if passing mobile specific props do not breaks anything in web and if web props do not break anything in mobile.

Screenshots

Types of changes

Adds new layer on top of BottomSheet.RangeCell to use it in the same way as Sidebar RangeContol slider in web version.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@jbinda jbinda added the [Status] In Progress Tracking issues with work in progress label Oct 20, 2019
@jbinda jbinda self-assigned this Oct 20, 2019
@jbinda jbinda requested review from pinarol and mkevins October 28, 2019 08:50
@jbinda jbinda added [Type] Enhancement A suggestion for improvement. and removed [Status] In Progress Tracking issues with work in progress labels Oct 28, 2019
Copy link
Contributor

@mkevins mkevins left a comment

Choose a reason for hiding this comment

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

One place where the behavior for RangeControl on mobile deviates from web is that the effects are immediate for web: https://github.com/WordPress/gutenberg/tree/03fe42e31bc3da8d2852dd6203219c1c97068cd9/packages/components/src/range-control#immediate-effects. I believe we introduced some changes to RangeCell to work around a "jumpiness" bug, which may be what is preventing the values from updating immediately in RangeControl (i.e. the mobile slider's onChangeValue only fires after the react-native slider's onSlidingComplete is invoked).

Is there another way to address the "jumpiness" in the underlying slider implementation which preserves the "immediate effects" described in the web implementation for RangeControl?

minimumValue={ min }
maximumValue={ max }
value={ value }
beforeIcon={ beforeIcon }
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that a few of these props (e.g. beforeIcon, afterIcon, etc.) are not used in RangeCell, and are thus passed along to the Cell wrapping them:

. Cell uses a prop called icon, but neither beforeIcon, nor afterIcon are supported there.

In the current draft PR for gallery, I'm using icon, but this won't work for web, since the props not used in the web implementation of RangeControl will be passed on to the input element: https://github.com/WordPress/gutenberg/tree/03fe42e31bc3da8d2852dd6203219c1c97068cd9/packages/components/src/range-control#props. (i.e. <input icon="some-icon">).

Note: I tried omitting icon, but this seems to break the layout of the slider. I believe that is an issue with the RangeCell mobile component, and not this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's ok when you are using separate edit.js and edit.native.js. Then you can pass different set of props and the problem is gone. I assume you are trying to use one common edit.js file both for web and mobile ? I wonder if it's the only prop that cause problems. I guess not ( I believe we are able to find more props e.g. separatorType={ 'fullWidth' } can be passed to mobile but I'm afraid it's not desirable to obtain it on the web)

Copy link
Contributor

@pinarol pinarol Oct 29, 2019

Choose a reason for hiding this comment

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

In the current draft PR for gallery, I'm using icon, but this won't work for web

What’s that icon for? Does it have the same purpose with either beforeIcon or afterIcon? @mkevins

@jbinda right we have 1 edit.js. And we want to make components library cross platform, thus, we should be able to use same props for both platforms. Ofc there can be platform specific props but it should be necessary only when the actual behavior behimd that prop is different and platform specific. I was wondering, Is it possible to hide separatorType inside RangeControl native.js? If we’ll use the same separator type for every case I think we can do that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Btw, we have a tech debt to get rid of separatorType somehow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @pinarol 👋

What’s that icon for? Does it have the same purpose with either beforeIcon or afterIcon?

That icon prop is used by Cell, and it seems to be similar to beforeIcon. RangeControl does not have this prop, though. I'm currently using it in the draft PR to prevent the slider layout from breaking (in the BottomSheet).

Copy link
Contributor

Choose a reason for hiding this comment

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

That's the plan for separatorType, but we couldn't get to start working on that yet. And we don't need to do this as a part of this PR.

For these ones:

accessibilityLabel,
accessibilityHint,
accessibilityRole,

I'd check if they crash web and make a fix accordingly but I wouldn't necessarily document them in README as they are available for all react-native components in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pinarol ok so I will:

  1. Document mentioned props in README file
  2. Make sure passing extra props specific to one platform do not break anything in other platform

Is there anything else that we should address in this PR ?

I also saw that Spacer feature was merged so I hope shortly we will also merge latest changes related to RangeCell made by Luke which was targeting Spacer branch

Copy link
Contributor

@pinarol pinarol Nov 4, 2019

Choose a reason for hiding this comment

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

  1. Document mentioned props in README file

Yes, and it'd be enough if we only document icon, separatorType as new props. But we should be adding proper Platform attributes for all props as we did on ..../media-placeholder/README.md

  1. Make sure passing extra props specific to one platform do not break anything in other platform

👍

Is there anything else that we should address in this PR ?

Not anything else that I can think of.

I also saw that Spacer feature was merged so I hope shortly we will also merge latest changes related to RangeCell made by Luke which was targeting Spacer branch

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have update README (can you take a look if the description make sense ?), CI passed after sync latest gutenberg/gutenberg-mobile repo changes.

Now I'm testing if passing platform specific props do not break mobile/web app

Copy link
Contributor

@pinarol pinarol Nov 4, 2019

Choose a reason for hiding this comment

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

Thanks commented

@jbinda
Copy link
Contributor Author

jbinda commented Oct 29, 2019

@mkevins thanks for comments.

You're right. I have noticed that calling setAttributes method to change the value pin to slider continuously when moving slider is causing the "jumpiness" bug. Trigger state change after slide complete event helps to solve it. Maybe we need more investigation on it to see if there is another way to deal with both things.

However we still working on styling with @lukewalczak so we should be able to cover the beforeIcon and afterIcon as well as broken layout when you did not pass icon prop to slider.

- Type: `String Enum`
- Values: `none` | `fullWidth` | `topFullWidth`
- Required: No
- Platform: Only Mobile
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be better:

Platform: Mobile

Let's also add Platform attribute to other props similar to what we did in media-placeholder/README.md
And add these where suitable:

Platform: Web | Mobile

Platform: Web

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. You would like me to do this in current PR or open new one ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Current one would be fine.

@mkevins mkevins mentioned this pull request Nov 6, 2019
@jbinda
Copy link
Contributor Author

jbinda commented Nov 6, 2019

@pinarol I have update README.md and update PR description on how I have been testing it according to passing extra props

I have used @mkevins gallery try branch and also @lukewalczak RangeCell styling. I think at this moment it is ready to ship.

I have also noticed this but I think at this moment we're fine and can refactor with separate PR after we get final conclusion from this thread.

@jbinda jbinda requested review from mkevins and pinarol November 6, 2019 11:49
Copy link
Contributor

@pinarol pinarol left a comment

Choose a reason for hiding this comment

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

I think this is looking/working good 👍

Mobile part is tested with the code snippet provided

Web part is tested by passing some mobile specific props to RangeControl and verifying that they don't break anything.

@jbinda jbinda merged commit 1d8ccc5 into master Nov 6, 2019
@jbinda jbinda deleted the rnmobile/range-control-markup branch November 6, 2019 13:16
@jbinda
Copy link
Contributor Author

jbinda commented Nov 6, 2019

Great ! Merged 🎉

@youknowriad youknowriad added this to the Gutenberg 6.9 milestone Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants