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

[Mobile] - Fix missing custom gradient indicator in the color palette #57605

Merged
merged 9 commits into from
Jan 10, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ exports[`Buttons block color customization sets a background color 1`] = `
<!-- /wp:buttons -->"
`;

exports[`Buttons block color customization sets a custom gradient background color 1`] = `
"<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button {"style":{"color":{"gradient":"linear-gradient(200deg,rgb(122,220,180) 0%,rgb(0,208,130) 100%)"}}} /--></div>
<!-- /wp:buttons -->"
`;

exports[`Buttons block color customization sets a gradient background color 1`] = `
"<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button {"gradient":"light-green-cyan-to-vivid-green-cyan"} /--></div>
Expand Down
49 changes: 49 additions & 0 deletions packages/block-library/src/buttons/test/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
initializeEditor,
triggerBlockListLayout,
typeInRichText,
openBlockSettings,
waitFor,
} from 'test/helpers';

Expand Down Expand Up @@ -391,5 +392,53 @@ describe( 'Buttons block', () => {
// Assert
expect( getEditorHtml() ).toMatchSnapshot();
} );

it( 'sets a custom gradient background color', async () => {
// Arrange
const screen = await initializeEditor();
await addBlock( screen, 'Buttons' );

// Act
const buttonsBlock = getBlock( screen, 'Buttons' );
fireEvent.press( buttonsBlock );

// Trigger onLayout for the list
await triggerBlockListLayout( buttonsBlock );

const buttonBlock = await getBlock( screen, 'Button' );
fireEvent.press( buttonBlock );

// Open Block Settings.
await openBlockSettings( screen );

// Open Text color settings
fireEvent.press( screen.getByLabelText( 'Background, Default' ) );

// Tap on the gradient segment
fireEvent.press( screen.getByLabelText( 'Gradient' ) );

// Tap one gradient color
fireEvent.press(
screen.getByLabelText( 'Light green cyan to vivid green cyan' )
);

// Tap on Customize Gradient
fireEvent.press( screen.getByLabelText( /Customize Gradient/ ) );

// Change the current angle
fireEvent.press( screen.getByText( '135', { hidden: true } ) );
const angleTextInput = screen.getByDisplayValue( '135', {
hidden: true,
} );
fireEvent.changeText( angleTextInput, '200' );

// Go back to the settings list.
fireEvent.press( await screen.findByLabelText( 'Go back' ) );

// Assert
const customButton = await screen.findByText( 'CUSTOM' );
expect( customButton ).toBeVisible();
expect( getEditorHtml() ).toMatchSnapshot();
} );
} );
} );
1 change: 1 addition & 0 deletions packages/block-library/src/cover/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ const Cover = ( {
<BottomSheetConsumer>
{ ( { shouldEnableBottomSheetScroll } ) => (
<ColorPalette
enableCustomColor={ true }
customColorIndicatorStyles={
styles.paletteColorIndicator
}
Expand Down
25 changes: 18 additions & 7 deletions packages/components/src/color-palette/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let scrollPosition = 0;
let customIndicatorWidth = 0;

function ColorPalette( {
enableCustomColor = true,
enableCustomColor = false,
setColor,
activeColor,
isGradientColor,
Expand Down Expand Up @@ -62,24 +62,35 @@ function ColorPalette( {
const scale = useRef( new Animated.Value( 1 ) ).current;
const opacity = useRef( new Animated.Value( 1 ) ).current;

const defaultColors = [
const mergedColors = [
...new Set(
( defaultSettings.colors ?? [] ).map( ( { color } ) => color )
),
];
const mergedColors = [
const mergedGradients = [
...new Set(
( defaultSettings.gradients ?? [] ).map(
( { gradient } ) => gradient
)
),
];
const allAvailableColors = [
...new Set(
( defaultSettings.allColors ?? [] ).map( ( { color } ) => color )
),
];
const defaultGradientColors = [
const allAvailableGradients = [
...new Set(
( defaultSettings.gradients ?? [] ).map(
( defaultSettings.allGradients ?? [] ).map(
( { gradient } ) => gradient
)
),
];
const colors = isGradientSegment ? defaultGradientColors : defaultColors;

const colors = isGradientSegment ? mergedGradients : mergedColors;
const allColors = isGradientSegment
? allAvailableGradients
: allAvailableColors;

const customIndicatorColor = isGradientSegment
? activeColor
Expand Down Expand Up @@ -110,7 +121,7 @@ function ColorPalette( {

function isSelectedCustom() {
const isWithinColors =
activeColor && mergedColors && mergedColors.includes( activeColor );
activeColor && allColors?.includes( activeColor );
if ( enableCustomColor && activeColor ) {
if ( isGradientSegment ) {
return isGradientColor && ! isWithinColors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { colorsUtils } from './utils';
import styles from './style.scss';

const HIT_SLOP = { top: 8, bottom: 8, left: 8, right: 8 };
const THEME_PALETTE_NAME = 'Theme';

const PaletteScreen = () => {
const route = useRoute();
Expand All @@ -48,7 +47,6 @@ const PaletteScreen = () => {
const [ currentValue, setCurrentValue ] = useState( colorValue );
const isGradientColor = isGradient( currentValue );
const selectedSegmentIndex = isGradientColor ? 1 : 0;
const allAvailableColors = useMobileGlobalStylesColors();

const [ currentSegment, setCurrentSegment ] = useState(
segments[ selectedSegmentIndex ]
Expand All @@ -57,6 +55,10 @@ const PaletteScreen = () => {
const currentSegmentColors = ! isGradientSegment
? defaultSettings.colors
: defaultSettings.gradients;
const allAvailableColors = useMobileGlobalStylesColors();
const allAvailableGradients = currentSegmentColors
.flatMap( ( { gradients } ) => gradients )
.filter( Boolean );

const horizontalSeparatorStyle = usePreferredColorSchemeStyle(
styles.horizontalSeparator,
Expand Down Expand Up @@ -184,10 +186,10 @@ const PaletteScreen = () => {
colors: palette.colors,
gradients: palette.gradients,
allColors: allAvailableColors,
allGradients: allAvailableGradients,
};
const enableCustomColor =
! isGradientSegment &&
palette.name === THEME_PALETTE_NAME;
// Limit to show the custom indicator to the first available palette
const enableCustomColor = paletteKey === 0;

return (
<ColorPalette
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ For each user feature we should also add a importance categorization label to i

## Unreleased
- [**] Image block media uploads display a custom error message when there is no internet connection [#56937]
- [*] Fix missing custom color indicator for custom gradients [#57605]

## 1.110.0
- [*] [internal] Move InserterButton from components package to block-editor package [#56494]
Expand Down
Loading