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] - Gallery Block: Columns Control #20231

Merged
merged 1 commit into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/block-library/src/gallery/columns-control/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* WordPress dependencies
*/
import { RangeControl } from '@wordpress/components';

const ColumnsControl = ( { label, value, onChange, min, max } ) => (
<RangeControl
label={ label }
max={ max }
min={ min }
onChange={ onChange }
required
value={ value }
/>
);

export default ColumnsControl;
17 changes: 17 additions & 0 deletions packages/block-library/src/gallery/columns-control/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* WordPress dependencies
*/
import { StepperControl } from '@wordpress/components';

const ColumnsControl = ( { label, value, onChange, min, max } ) => (
<StepperControl
label={ label }
max={ max }
min={ min }
onChange={ onChange }
separatorType="fullWidth"
value={ value }
/>
);

export default ColumnsControl;
5 changes: 1 addition & 4 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import {
import { compose } from '@wordpress/compose';
import {
PanelBody,
RangeControl,
SelectControl,
StepperControl,
ToggleControl,
withNotices,
} from '@wordpress/components';
Expand All @@ -39,8 +37,8 @@ import { withViewportMatch } from '@wordpress/viewport';
import { sharedIcon } from './shared-icon';
import { defaultColumnsNumber, pickRelevantMediaFiles } from './shared';
import Gallery from './gallery';
import ColumnsControl from './columns-control';

const ColumnsControl = Platform.OS === 'web' ? RangeControl : StepperControl;
const MAX_COLUMNS = 8;
const linkOptions = [
{ value: 'attachment', label: __( 'Attachment Page' ) },
Expand Down Expand Up @@ -384,7 +382,6 @@ class GalleryEdit extends Component {
{ images.length > 1 && (
<ColumnsControl
label={ __( 'Columns' ) }
{ ...MOBILE_CONTROL_PROPS }
Copy link
Member

Choose a reason for hiding this comment

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

The problem with this sort of spread is that it makes it unclear to me now in this moment of refactoring whether we can remove the MOBILE_CONTROL_PROPS object or any of its properties. I see that it is spread into other components, but I have no idea what (or if any) of the properties are being used in those components.

I would have preferred that each prop were individually listed, even if that is more verbose, to make it clearer what is needed and where.

Or better yet, and to the same point as #20231 (comment), we aim to avoid any differences in the component API, so that we don't need to do this at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @aduth 👋

This current implementation with the MOBILE_CONTROL_PROPS object (as well as the even uglier MOBILE_CONTROL_PROPS_SEPARATOR_NONE object introduced here) is admittedly a pretty hacky workaround. This in part arises from differences in how controls are displayed on web and native (on native, PanelBody is in the bottomsheet).

There are at least two areas of technical debt that prompt this awkwardness:

  1. Native implementations of various control components have different default separatorTypes.
  2. The responsibility of rendering (or not) the separator currently belongs to the Cell component, from which all mobile control components are composed.

Proposed solutions:

Due to 1., we must "manually" specify the separator types to ensure consistency in a group of controls (not ideal). Instead, the controls should have a common default separatorType obviating the need for this hack. Due to 2., the responsibility of handling fence-post issues for the separators is left to the parent components. It might make more sense to shift this responsibility to the native implementation of PanelBody, or if not there, a container component to abstract it away and avoid fence-post logic "leaking" into the parent views.

In the current implementation, these spreadables were extracted to the top per this discussion: #18265 (comment), however, you raise an interesting point about the "painfulness" signalling. Having each prop verbosely listed (with appropriate comments included) could serve to amplify the existence of the underlying technical debt (which is currently signaled only by the code comment).

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I don't exactly understand how this needs to behave in mobile with showing in the bottom card, but it does not seem to me that this separator ought to be a concern of the *Control components, which are otherwise labeled input controls agnostic to where they occur in the page. If it's a consequence of how these are rendered within PanelBody, then I would agree this should be managed by PanelBody (either by styling, or perhaps in its render behavior in inspecting/iterating its props.children).

value={ columns }
onChange={ this.setColumnsNumber }
min={ 1 }
Expand Down