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] Color settings #21326

Merged
merged 77 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
ed821f9
First color picker implementation
lukewalczak Mar 9, 2020
f3eb7c9
Rename context provider and consumer
lukewalczak Mar 9, 2020
073650a
Export BottomSheetConsumer
lukewalczak Mar 9, 2020
ea04b22
Add first animation
lukewalczak Mar 10, 2020
3e11cf2
Add second animation - layout animation
lukewalczak Mar 11, 2020
67c7892
Add SegmentedControls component
lukewalczak Mar 11, 2020
e521c27
Add ColorPalette
lukewalczak Mar 13, 2020
e3e9b13
Create ColorIndicator
lukewalczak Mar 13, 2020
a11712d
Correct styles file
lukewalczak Mar 13, 2020
f20ec02
First main refactor
lukewalczak Mar 16, 2020
e4ce3a5
Make SegmentedControls platform specific
lukewalczak Mar 16, 2020
3f124b0
Extract ColorPicker to separate file, update NavigationHeader
lukewalczak Mar 17, 2020
b682139
Connect Text color settings
lukewalczak Mar 17, 2020
298dc71
Extract ColorSettings to separate file
lukewalczak Mar 18, 2020
3df7536
Support dark mode in SegmentedControls
lukewalczak Mar 18, 2020
d55cbef
Implement CustomSwatch
lukewalczak Mar 19, 2020
badf276
Handle closing bottom sheet from picker
lukewalczak Mar 19, 2020
2436753
Theme tweaks
lukewalczak Mar 19, 2020
ec94046
Correct palette scroll, some styling fixes, correct isSelected condit…
lukewalczak Mar 20, 2020
c37ae2f
Design adjustments
lukewalczak Mar 24, 2020
4726ff3
Animate swatch press
lukewalczak Mar 24, 2020
29c8f8d
Add wrapper for bottom sheet children
lukewalczak Mar 24, 2020
88478fd
Correct animation, bottom sheet, make scrollable area taller
lukewalczak Mar 25, 2020
6933353
Color hex text next to swatch
lukewalczak Mar 25, 2020
8ede0b5
Correct segmented controls
lukewalczak Mar 25, 2020
e4c8757
Animate segemented controls
lukewalczak Mar 26, 2020
f0f8dd5
Remove hex next to swatch, small improvements
lukewalczak Mar 26, 2020
b571fd0
Support hex color copying, change animation duration, fix scrollview
lukewalczak Mar 27, 2020
6581e6e
Adjustments for the largest font sizes
lukewalczak Mar 30, 2020
fbb2874
Unblock maxHeight for bottom sheet with color picker
lukewalczak Mar 30, 2020
ad5d6a7
Correct impementation to correct transition
lukewalczak Mar 31, 2020
5c7692e
Support android hardware back button in subsheet navigation
lukewalczak Apr 1, 2020
eb39721
Remove selecting swatch
lukewalczak Apr 1, 2020
f003b34
Merge branch 'master' into rnmobile/settings-color-picker
lukewalczak Apr 1, 2020
9e17587
Correct scrolling, border width issue
lukewalczak Apr 2, 2020
8eaccfa
Merge branch 'master' into rnmobile/settings-color-picker
lukewalczak Apr 2, 2020
3ded391
Fix lint issues
lukewalczak Apr 2, 2020
1922e9d
Merge branch 'master' into rnmobile/settings-color-picker
lukewalczak Apr 2, 2020
c4757a5
Add new lib to test setup
lukewalczak Apr 2, 2020
a065d33
Merge branch 'master' into rnmobile/settings-color-picker
lukewalczak Apr 2, 2020
0f019e6
Colors and outline refactor, creating gradient hoc
lukewalczak Apr 3, 2020
7040712
Navigation refactor, segemented controls refactor
lukewalczak Apr 6, 2020
8eaf90a
ColorPalette fix, correct swatches border color
lukewalczak Apr 8, 2020
c127ea1
Move onReplaceSubsheet function to BottomSheet
lukewalczak Apr 14, 2020
28fdfac
Revert UnsupportedFooterControl
lukewalczak Apr 14, 2020
4e682f2
First refactor part
lukewalczak Apr 16, 2020
1c7b7be
Merge branch 'master' into rnmobile/settings-color-picker
lukewalczak Apr 16, 2020
15082b9
Small cleanup after merging
lukewalczak Apr 16, 2020
ffd5b07
Set colors workaround
lukewalczak Apr 16, 2020
de340b3
Correct if-else in setColor
lukewalczak Apr 16, 2020
56b07bc
Refactor footer buttons
lukewalczak Apr 17, 2020
142b0ad
Merge branch 'master' into rnmobile/settings-color-picker
lukewalczak Apr 17, 2020
2922555
move color settings to color hook
dratwas Apr 17, 2020
0ca7159
remove separator from last control
dratwas Apr 17, 2020
0311932
Correct animation on Android, remove default color, render text when …
lukewalczak Apr 20, 2020
ec16422
Disable flag __experimentalColor in native block which are not suppor…
lukewalczak Apr 20, 2020
5d6d97e
Merge branch 'master' into rnmobile/settings-color-picker
lukewalczak Apr 20, 2020
f33310d
Remove hoc related to setting gradient
lukewalczak Apr 20, 2020
a80f03a
Code clean up
lukewalczak Apr 21, 2020
623163c
Make supporting colors dependent on platform
lukewalczak Apr 21, 2020
bfe38fb
Revert changes from button index
lukewalczak Apr 21, 2020
836ca75
Use styles button destructuring
lukewalczak Apr 21, 2020
31fcfec
Merge branch 'master' into rnmobile/settings-color-picker
lukewalczak Apr 22, 2020
0c8c886
Another code clean up
lukewalczak Apr 22, 2020
6ab1081
Refactor button styles
lukewalczak Apr 22, 2020
b4f3cca
Documented bottom sheet context content
lukewalczak Apr 22, 2020
d04348f
Another code clean up
lukewalczak Apr 22, 2020
67b0134
Remove redundant provider export
lukewalczak Apr 23, 2020
84e0331
Refactor color palette
lukewalczak Apr 23, 2020
7cd1875
Refactor: use usePreferredColorSchemeStyle, move subsheets and segmen…
lukewalczak Apr 27, 2020
e56bb60
Move default BottomSheet context to separate file
lukewalczak Apr 27, 2020
9e8ba7f
Move function isGradient to utils
lukewalczak Apr 27, 2020
03b69f9
Refactor colorsUtils, unify colors label
lukewalczak May 4, 2020
3a674b4
Merge branch 'master' into rnmobile/settings-color-picker
lukewalczak May 4, 2020
fa36fc3
Correct using colors in reverted Button block
lukewalczak May 4, 2020
4c49765
Correct button colors
lukewalczak May 4, 2020
92e2c6c
Remove redundant check
lukewalczak May 5, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ const BlockMobileToolbar = ( {

<View style={ styles.spacer } />

<BlockSettingsButton.Slot />
<BlockSettingsButton.Slot>
{ /* Render only one settings icon even if we have more than one fill - need for hooks with controls */ }
{ ( fills = [ null ] ) => fills[ 0 ] }
</BlockSettingsButton.Slot>

<ToolbarButton
title={ sprintf(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
/**
* WordPress dependencies
*/
import { BottomSheet } from '@wordpress/components';
import {
BottomSheet,
BottomSheetConsumer,
ColorSettings,
} from '@wordpress/components';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { InspectorControls } from '@wordpress/block-editor';
import {
InspectorControls,
SETTINGS_DEFAULTS as defaultSettings,
} from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -24,7 +31,23 @@ function BottomSheetSettings( {
contentStyle={ styles.content }
{ ...props }
>
<InspectorControls.Slot />
<BottomSheetConsumer>
{ ( { currentScreen, extraProps, ...bottomSheetProps } ) => {
switch ( currentScreen ) {
case 'Color':
lukewalczak marked this conversation as resolved.
Show resolved Hide resolved
return (
<ColorSettings
defaultSettings={ defaultSettings }
{ ...bottomSheetProps }
{ ...extraProps }
/>
);
case 'Settings':
default:
return <InspectorControls.Slot />;
}
} }
</BottomSheetConsumer>
</BottomSheet>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,51 @@
/**
* WordPress dependencies
*/
import { PanelBody, UnsupportedFooterControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import {
ColorControl,
BottomSheetConsumer,
PanelBody,
} from '@wordpress/components';

const PanelColorGradientSettings = () => {
export default function PanelColorGradientSettings( { settings, title } ) {
return (
<PanelBody>
<UnsupportedFooterControl
label={ __( 'Color settings are coming soon.' ) }
separatorType="none"
/>
<PanelBody title={ title }>
<BottomSheetConsumer>
{ ( { onReplaceSubsheet } ) =>
settings.map(
(
{
onColorChange,
colorValue,
onGradientChange,
gradientValue,
label,
},
index
) => (
<ColorControl
onPress={ () => {
onReplaceSubsheet( 'Color', {
geriux marked this conversation as resolved.
Show resolved Hide resolved
onColorChange,
colorValue: gradientValue || colorValue,
gradientValue,
onGradientChange,
label,
} );
} }
key={ `color-setting-${ label }` }
label={ label }
color={ gradientValue || colorValue }
separatorType={
index !== settings.length - 1
? 'fullWidth'
: 'none'
}
/>
)
)
}
</BottomSheetConsumer>
</PanelBody>
);
};
export default PanelColorGradientSettings;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
* External dependencies
*/
import React from 'react';

import { View } from 'react-native';
/**
* WordPress dependencies
*/
import { createSlotFill } from '@wordpress/components';

import { createSlotFill, BottomSheetConsumer } from '@wordpress/components';
/**
* Internal dependencies
*/
Expand All @@ -19,7 +18,13 @@ const { Fill, Slot } = createSlotFill( 'InspectorControls' );
const FillWithSettingsButton = ( { children, ...props } ) => {
return (
<>
<Fill { ...props }>{ children }</Fill>
<Fill { ...props }>
{
<BottomSheetConsumer>
{ () => <View>{ children }</View> }
lukewalczak marked this conversation as resolved.
Show resolved Hide resolved
</BottomSheetConsumer>
}
</Fill>
{ React.Children.count( children ) > 0 && <BlockSettingsButton /> }
</>
);
Expand Down
3 changes: 0 additions & 3 deletions packages/block-editor/src/hooks/color-panel.native.js

This file was deleted.

17 changes: 13 additions & 4 deletions packages/block-editor/src/hooks/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { addFilter } from '@wordpress/hooks';
import { hasBlockSupport, getBlockSupport } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { useRef, useEffect } from '@wordpress/element';
import { useRef, useEffect, Platform } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -243,11 +243,17 @@ export function ColorEdit( props ) {

return (
<ColorPanel
enableContrastChecking={ ! gradient && ! style?.color?.gradient }
enableContrastChecking={
// Turn on contrast checker for web only since it's not supported on mobile yet.
Platform.OS === 'web' && ! gradient && ! style?.color?.gradient
}
clientId={ props.clientId }
settings={ [
{
label: __( 'Text Color' ),
label:
Platform.OS === 'web'
geriux marked this conversation as resolved.
Show resolved Hide resolved
? __( 'Text Color' )
: __( 'Text' ),
onColorChange: onChangeColor( 'text' ),
colorValue: getColorObjectByAttributeValues(
colors,
Expand All @@ -256,7 +262,10 @@ export function ColorEdit( props ) {
).color,
},
{
label: __( 'Background Color' ),
label:
Platform.OS === 'web'
? __( 'Background Color' )
: __( 'Background' ),
onColorChange: onChangeColor( 'background' ),
colorValue: getColorObjectByAttributeValues(
colors,
Expand Down
7 changes: 3 additions & 4 deletions packages/block-library/src/button/color-background.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { View } from 'react-native';
* WordPress dependencies
*/
import { LinearGradient } from '@wordpress/components';
import { __experimentalUseGradient } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
Expand All @@ -21,13 +20,13 @@ function ColorBackground( { children, borderRadiusValue, backgroundColor } ) {
},
];

const { gradientValue } = __experimentalUseGradient();
const isGradient = backgroundColor.includes( 'linear-gradient' );

return (
<View style={ wrapperStyles }>
{ gradientValue && (
{ isGradient && (
<LinearGradient
gradientValue={ gradientValue }
gradientValue={ backgroundColor }
angleCenter={ { x: 0.5, y: 0.5 } }
style={ [
styles.linearGradient,
Expand Down
49 changes: 24 additions & 25 deletions packages/block-library/src/button/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import {
withColors,
InspectorControls,
BlockControls,
SETTINGS_DEFAULTS,
} from '@wordpress/block-editor';
import {
TextControl,
ToggleControl,
PanelBody,
RangeControl,
UnsupportedFooterControl,
ToolbarGroup,
ToolbarButton,
BottomSheet,
Expand All @@ -39,7 +39,7 @@ import { link, external } from '@wordpress/icons';
*/
import richTextStyle from './rich-text.scss';
import styles from './editor.scss';
import ColorBackground from './color-background.native';
import ColorBackground from './color-background';
import LinkRelIcon from './link-rel';

const NEW_TAB_REL = 'noreferrer noopener';
Expand Down Expand Up @@ -173,23 +173,31 @@ class ButtonEdit extends Component {

getBackgroundColor() {
const { backgroundColor, attributes } = this.props;
const { style } = attributes;

const { style, gradient, customGradient } = attributes;
const defaultGradients = SETTINGS_DEFAULTS.gradients;

if ( customGradient || gradient ) {
return (
customGradient ||
defaultGradients.find(
( defaultGradient ) => defaultGradient.slug === gradient
).gradient
);
}
return (
( style && style.color && style.color.background ) ||
backgroundColor.color ||
styles.fallbackButton.backgroundColor
styles.defaultButton.backgroundColor
);
}

getTextColor() {
const { textColor, attributes } = this.props;
const { style } = attributes;

return (
( style && style.color && style.color.text ) ||
textColor.color ||
styles.fallbackButton.color
styles.defaultButton.color
);
}

Expand Down Expand Up @@ -267,7 +275,7 @@ class ButtonEdit extends Component {
onSetMaxWidth( width ) {
const { maxWidth } = this.state;
const { parentWidth } = this.props;
const { marginRight: spacing } = styles.button;
const { marginRight: spacing } = styles.defaultButton;

const isParentWidthChanged = maxWidth !== parentWidth;
const isWidthChanged = maxWidth !== width;
Expand Down Expand Up @@ -398,20 +406,18 @@ class ButtonEdit extends Component {
isButtonFocused,
placeholderTextWidth,
} = this.state;
const { paddingTop: spacing, borderWidth } = styles.defaultButton;

if ( parentWidth === 0 ) {
return null;
}

const borderRadiusValue =
borderRadius !== undefined
? borderRadius
: styles.button.borderRadius;
const borderRadiusValue = Number.isInteger( borderRadius )
? borderRadius
: styles.defaultButton.borderRadius;
const outlineBorderRadius =
borderRadiusValue > 0
? borderRadiusValue +
styles.button.paddingTop +
styles.button.borderWidth
? borderRadiusValue + spacing + borderWidth
: 0;

// To achieve proper expanding and shrinking `RichText` on iOS, there is a need to set a `minWidth`
Expand All @@ -430,6 +436,7 @@ class ButtonEdit extends Component {
: placeholder || __( 'Add text…' );

const backgroundColor = this.getBackgroundColor();
const textColor = this.getTextColor();

return (
<View onLayout={ this.onLayout }>
Expand Down Expand Up @@ -458,7 +465,7 @@ class ButtonEdit extends Component {
onChange={ this.onChangeText }
style={ {
...richTextStyle.richText,
color: this.getTextColor(),
color: textColor,
} }
textAlign="center"
placeholderTextColor={
Expand All @@ -475,11 +482,11 @@ class ButtonEdit extends Component {
this.onToggleButtonFocus( true )
}
__unstableMobileNoFocusOnMount={ ! isSelected }
selectionColor={ textColor }
onBlur={ () => {
this.onToggleButtonFocus( false );
this.onSetMaxWidth();
} }
selectionColor={ this.getTextColor() }
onReplace={ onReplace }
onRemove={ this.onRemove }
onMerge={ mergeBlocks }
Expand Down Expand Up @@ -527,14 +534,6 @@ class ButtonEdit extends Component {
<PanelBody title={ __( 'Link Settings' ) }>
{ this.getLinkSettings( url, rel, linkTarget, true ) }
</PanelBody>
<PanelBody>
<UnsupportedFooterControl
label={ __(
'Button color settings are coming soon.'
) }
separatorType="none"
/>
</PanelBody>
</InspectorControls>
</View>
);
Expand Down
9 changes: 2 additions & 7 deletions packages/block-library/src/button/editor.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,11 @@
bottom: 0;
}

.button {
border-width: $border-width;
.defaultButton {
border-radius: $border-width * 4;
padding: $block-spacing;
max-width: 580px;
min-width: 108px;
border-width: $border-width;
margin: 2 * $panel-padding;
}

.fallbackButton {
background-color: $button-fallback-bg;
color: $white;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/columns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { __ } from '@wordpress/i18n';
import { columns as icon } from '@wordpress/icons';

import { Platform } from '@wordpress/element';
/**
* Internal dependencies
*/
Expand All @@ -27,7 +27,7 @@ export const settings = {
align: [ 'wide', 'full' ],
html: false,
lightBlockWrapper: true,
__experimentalColor: { gradients: true },
__experimentalColor: Platform.OS === 'web' && { gradients: true },
geriux marked this conversation as resolved.
Show resolved Hide resolved
},
variations,
example: {
Expand Down
Loading