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 75 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.
Jump to
Jump to file
Failed to load files.
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,18 @@
/**
* WordPress dependencies
*/
import { BottomSheet } from '@wordpress/components';
import {
BottomSheet,
BottomSheetConsumer,
ColorSettings,
colorsUtils,
} 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 +32,23 @@ function BottomSheetSettings( {
contentStyle={ styles.content }
{ ...props }
>
<InspectorControls.Slot />
<BottomSheetConsumer>
{ ( { currentScreen, extraProps, ...bottomSheetProps } ) => {
switch ( currentScreen ) {
case colorsUtils.subsheets.color:
return (
<ColorSettings
defaultSettings={ defaultSettings }
{ ...bottomSheetProps }
{ ...extraProps }
/>
);
case colorsUtils.subsheets.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;
}
1 change: 1 addition & 0 deletions packages/block-editor/src/components/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export { default as BlockInvalidWarning } from './block-list/block-invalid-warni
export { default as BlockCaption } from './block-caption';
export { default as Caption } from './caption';
export { default as PanelColorSettings } from './panel-color-settings';
export { default as __experimentalPanelColorGradientSettings } from './colors-gradients/panel-color-gradient-settings';

export { BottomSheetSettings, BlockSettingsButton } from './block-settings';
export { default as VideoPlayer, VIDEO_ASPECT_RATIO } from './video-player';
Expand Down
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.

7 changes: 5 additions & 2 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,7 +243,10 @@ 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={ [
{
Expand Down
10 changes: 4 additions & 6 deletions packages/block-library/src/button/color-background.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { View } from 'react-native';
/**
* WordPress dependencies
*/
import { LinearGradient } from '@wordpress/components';
import { __experimentalUseGradient } from '@wordpress/block-editor';
import { LinearGradient, colorsUtils } from '@wordpress/components';
/**
* Internal dependencies
*/
import styles from './editor.scss';

function ColorBackground( { children, borderRadiusValue, backgroundColor } ) {
const { isGradient } = colorsUtils;
const wrapperStyles = [
styles.richTextWrapper,
{
Expand All @@ -21,13 +21,11 @@ function ColorBackground( { children, borderRadiusValue, backgroundColor } ) {
},
];

const { gradientValue } = __experimentalUseGradient();

return (
<View style={ wrapperStyles }>
{ gradientValue && (
{ isGradient( backgroundColor ) && (
<LinearGradient
gradientValue={ gradientValue }
gradientValue={ backgroundColor }
angleCenter={ { x: 0.5, y: 0.5 } }
style={ [
styles.linearGradient,
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/button/color-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { pickBy, isEqual, isObject, identity, mapValues } from 'lodash';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useState, useEffect, useRef } from '@wordpress/element';
import { useState, useEffect, useRef, Platform } from '@wordpress/element';
import { useSelect } from '@wordpress/data';

/**
Expand All @@ -23,6 +23,8 @@ import {
InspectorControls,
} from '@wordpress/block-editor';

const isWebPlatform = Platform.OS === 'web';

// The code in this file is copied entirely from the "color" and "style" support flags
// The flag can't be used at the moment because of the extra wrapper around
// the button block markup.
Expand Down Expand Up @@ -50,7 +52,7 @@ const cleanEmptyObject = ( object ) => {
: cleanedNestedObjects;
};

function ColorPanel( { settings, clientId, enableContrastChecking = true } ) {
function ColorPanel( { settings, clientId, enableContrastChecking = isWebPlatform } ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I'm wondering if we could change it a bit to block the contrast checking for mobile even if it is set to true in props?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can add check isWebPlatform before each enableContrastCheking.

const { getComputedStyle, Node } = window;

const [ detectedBackgroundColor, setDetectedBackgroundColor ] = useState();
Expand Down Expand Up @@ -191,7 +193,7 @@ function ColorEdit( props ) {

return (
<ColorPanel
enableContrastChecking={ ! gradient && ! style?.color?.gradient }
enableContrastChecking={ isWebPlatform && ! gradient && ! style?.color?.gradient }
clientId={ props.clientId }
settings={ [
{
Expand Down