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] Create cover block with custom colour (without an image) #23870

Merged
merged 52 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
c608052
Create cover block with only colour (from a default palette)
Jul 9, 2020
508f015
Added custom colour swatch
Jul 10, 2020
96b1582
Custom Color picker action
Jul 10, 2020
8c13787
Hide the block settings button
Jul 10, 2020
6e83663
Use noop instead of empty arrow function
Jul 13, 2020
3919a7d
Use default settings colors
Jul 13, 2020
a2eee4b
WIP: Changes Based on design feedback
Jul 13, 2020
83668c7
Merge branch 'master' into rnmobile/23831_Cover_Only_color
Jul 14, 2020
c71346a
Merge branch 'master' into rnmobile/23831_Cover_Only_color
Jul 14, 2020
a41dc37
Merge branch 'rnmobile/23831_Cover_Only_color' into rnmobile/Cover_wi…
Jul 14, 2020
0cbe0c1
Show palette with both hardcoded and theme colors
Jul 14, 2020
a0cd93b
Customise media placeholder styles only for the cover component
Jul 14, 2020
30d5ccb
Merge branch 'rnmobile/23831_Cover_Only_color' into rnmobile/Cover_wi…
Jul 14, 2020
7aec919
Pass only modified media-placeholder styles
Jul 15, 2020
a152a4a
Pass only modified color-palette styles
Jul 15, 2020
53d5435
Merge branch 'rnmobile/23831_Cover_Only_color' into rnmobile/Cover_wi…
Jul 15, 2020
787b462
Fixes lint issue
Jul 15, 2020
9929516
Updated color palette height
Jul 16, 2020
485cef9
Updated color palette height
Jul 16, 2020
91ff055
Use only theme colors
Jul 16, 2020
3babed3
Merge branch 'rnmobile/23831_Cover_Only_color' into rnmobile/Cover_wi…
Jul 16, 2020
a6a1f3f
Merge branch 'master' into rnmobile/23831_Cover_Only_color
Jul 17, 2020
97cc951
Fixes Dark mode styling bug
Jul 17, 2020
ecf4147
Merge branch 'rnmobile/23831_Cover_Only_color' into rnmobile/Cover_wi…
Jul 17, 2020
60f248d
Use noop instead of empty arrow functions
Jul 17, 2020
9036c9e
Simplified media-placeholder props
Jul 17, 2020
7d6219f
Removed unnecessary style
Jul 17, 2020
201c7d6
Revert "Removed unnecessary style"
Jul 17, 2020
77b06a8
Merge branch 'rnmobile/23831_tmp' into rnmobile/Cover_with_custom_color
Jul 17, 2020
65fc25e
Merge branch 'rnmobile/23831_tmp' into rnmobile/Cover_with_custom_color
Jul 17, 2020
be77f4f
Fixes style issue
Jul 17, 2020
2bfd357
Added missing callbacks
Jul 17, 2020
e5d0a77
Added bottom label
Jul 17, 2020
56449db
Removes unnecessary function
Jul 17, 2020
8d2237d
Merge branch 'master' into rnmobile/Cover_with_custom_color
Jul 19, 2020
7179432
Apply custom color picker color
Jul 19, 2020
d8fbac9
Removes unused import
Jul 19, 2020
dc664fb
Lint issues and cleanup
Jul 20, 2020
0a37400
Merge branch 'master' into rnmobile/Cover_with_custom_color
Jul 22, 2020
0a72e9f
Design fixes
Jul 22, 2020
7a4f90d
Renamed prop to declare usage more clearly
Jul 22, 2020
8e2c894
Lint Issue
Jul 22, 2020
537211c
PR review fixes
Jul 23, 2020
df25f6b
Extra fixes to avoid inconsistent states
Jul 23, 2020
054a6b5
Lint fix and comment
Jul 23, 2020
852f9a4
Revert "Lint fix and comment"
Jul 24, 2020
f529dae
Revert "Extra fixes to avoid inconsistent states"
Jul 24, 2020
a623b1b
Review changes
Jul 24, 2020
b4ab716
Android hardware button handling
Jul 24, 2020
979e8d4
Merge branch 'master' into rnmobile/Cover_with_custom_color
Jul 24, 2020
a416741
Lint fix
Jul 24, 2020
2ae97d2
Removed unused prop/style
Jul 24, 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 @@ -45,6 +45,8 @@ function MediaPlaceholder( props ) {
value = [],
children,
height,
backgroundColor,
hideContent,
} = props;

// use ref to keep media array current for callbacks during rerenders
Expand Down Expand Up @@ -170,12 +172,13 @@ function MediaPlaceholder( props ) {
[
emptyStateContainerStyle,
height && { height },
backgroundColor && { backgroundColor },
],
isAppender && appenderStyle,
] }
>
{ getMediaOptions() }
{ renderContent() }
{ ! hideContent && renderContent() }
</View>
</TouchableWithoutFeedback>
);
Expand Down
76 changes: 71 additions & 5 deletions packages/block-library/src/cover/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import { View, TouchableWithoutFeedback } from 'react-native';
import Video from 'react-native-video';
import { noop } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -27,6 +26,8 @@ import {
ToolbarGroup,
Gradient,
ColorPalette,
ColorPicker,
BottomSheetConsumer,
} from '@wordpress/components';
import {
BlockControls,
Expand Down Expand Up @@ -81,6 +82,7 @@ const Cover = ( {
onFocus,
overlayColor,
setAttributes,
openGeneralSidebar,
settings,
closeSettingsBottomSheet,
} ) => {
Expand Down Expand Up @@ -111,6 +113,13 @@ const Cover = ( {
gradientValue
);

const [
isCustomColorPickerShowing,
setCustomColorPickerShowing,
] = useState( false );

const [ customColor, setCustomColor ] = useState( '' );

const openMediaOptionsRef = useRef();

// Used to set a default color for its InnerBlocks
Expand Down Expand Up @@ -190,6 +199,13 @@ const Cover = ( {
} );
}

function openColorPicker() {
if ( isParentSelected ) {
openGeneralSidebar();
setCustomColorPickerShowing( true );
}
}

const backgroundColor = getStylesFromColorScheme(
styles.backgroundSolid,
styles.backgroundSolidDark
Expand Down Expand Up @@ -275,6 +291,43 @@ const Cover = ( {
</InspectorControls>
);

const colorPickerControls = (
<InspectorControls>
<BottomSheetConsumer>
{ ( {
shouldEnableBottomSheetScroll,
shouldDisableBottomSheetMaxHeight,
onCloseBottomSheet,
onHardwareButtonPress,
isBottomSheetContentScrolling,
} ) => (
<ColorPicker
shouldEnableBottomSheetScroll={
shouldEnableBottomSheetScroll
}
shouldDisableBottomSheetMaxHeight={
shouldDisableBottomSheetMaxHeight
}
setColor={ ( color ) => {
setCustomColor( color );
setColor( color );
} }
onNavigationBack={ closeSettingsBottomSheet }
onCloseBottomSheet={ onCloseBottomSheet }
onHardwareButtonPress={ onHardwareButtonPress }
onBottomSheetClosed={ () => {
setCustomColorPickerShowing( false );
} }
isBottomSheetContentScrolling={
isBottomSheetContentScrolling
}
bottomLabelText={ __( 'Select a color' ) }
/>
) }
</BottomSheetConsumer>
</InspectorControls>
);

const renderBackground = ( getMediaOptions ) => (
<TouchableWithoutFeedback
accessible={ ! isParentSelected }
Expand Down Expand Up @@ -352,11 +405,16 @@ const Cover = ( {
</TouchableWithoutFeedback>
);

if ( ! hasBackground ) {
if ( ! hasBackground || isCustomColorPickerShowing ) {
return (
<View>
{ isCustomColorPickerShowing && colorPickerControls }
<MediaPlaceholder
height={ styles.mediaPlaceholderEmptyStateContainer.height }
backgroundColor={ customColor }
hideContent={
customColor !== '' && customColor !== undefined
}
icon={ placeholderIcon }
labels={ {
title: __( 'Cover' ),
Expand All @@ -370,11 +428,17 @@ const Cover = ( {
customColorIndicatorStyles={
styles.paletteColorIndicator
}
customIndicatorWrapperStyles={
styles.paletteCustomIndicatorWrapper
}
customVerticalSeparatorStyles={
styles.paletteVerticalSeparator
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this is not being used, should we remove it or is there something that we need to add?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right @geriux ! This was used at some point during the development but not any more.
I updated the PR

setColor={ setColor }
onCustomPress={ noop }
onCustomPress={ openColorPicker }
defaultSettings={ coverDefaultPalette }
shouldShowCustomIndicatorOption={ false }
shouldShowCustomLabel={ false }
shouldShowCustomVerticalSeparator={ false }
/>
</View>
</MediaPlaceholder>
Expand Down Expand Up @@ -470,12 +534,14 @@ export default compose( [
};
} ),
withDispatch( ( dispatch ) => {
const { openGeneralSidebar } = dispatch( 'core/edit-post' );

return {
openGeneralSidebar: () => openGeneralSidebar( 'edit-post/block' ),
closeSettingsBottomSheet() {
dispatch( 'core/edit-post' ).closeGeneralSidebar();
},
};
} ),

withPreferredColorScheme,
] )( Cover );
11 changes: 9 additions & 2 deletions packages/block-library/src/cover/style.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,15 @@
.paletteColorIndicator {
margin-top: 0;
margin-bottom: 0;
width: 32px;
height: 32px;
width: $grid-unit-40;
height: $grid-unit-40;
}

.paletteCustomIndicatorWrapper {
flex-direction: row;
align-items: baseline;
width: $grid-unit-40;
height: $grid-unit-40;
}

.mediaPlaceholderEmptyStateContainer {
Expand Down
6 changes: 5 additions & 1 deletion packages/components/src/color-indicator/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ function ColorIndicator( {
return (
<Gradient
gradientValue={ gradientValue }
style={ [ styles.circleOption, styles.absolute ] }
style={ [
styles.circleOption,
styles.absolute,
style,
] }
key={ gradientValue }
/>
);
Expand Down
15 changes: 12 additions & 3 deletions packages/components/src/color-palette/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ function ColorPalette( {
shouldEnableBottomSheetScroll,
shouldShowCustomIndicatorOption = true,
shouldShowCustomLabel = true,
shouldShowCustomVerticalSeparator = true,
customColorIndicatorStyles,
customIndicatorWrapperStyles,
} ) {
const customSwatchGradients = [
'linear-gradient(120deg, rgba(255,0,0,.8), 0%, rgba(255,255,255,1) 70.71%)',
Expand Down Expand Up @@ -188,6 +190,11 @@ function ColorPalette( {
styles.customTextDark
);

const customIndicatorWrapperStyle = [
styles.customIndicatorWrapper,
customIndicatorWrapperStyles,
];

return (
<ScrollView
contentContainerStyle={ styles.contentContainer }
Expand Down Expand Up @@ -237,17 +244,19 @@ function ColorPalette( {
} ) }
{ shouldShowCustomIndicator && (
<View
style={ styles.customIndicatorWrapper }
style={ customIndicatorWrapperStyle }
onLayout={ onCustomIndicatorLayout }
>
<View style={ verticalSeparatorStyle } />
{ shouldShowCustomVerticalSeparator && (
<View style={ verticalSeparatorStyle } />
) }
<TouchableWithoutFeedback
onPress={ onCustomPress }
accessibilityRole={ 'button' }
accessibilityState={ { selected: isSelectedCustom() } }
accessibilityHint={ accessibilityHint }
>
<View style={ styles.customIndicatorWrapper }>
<View style={ customIndicatorWrapperStyle }>
<ColorIndicator
withCustomPicker={ ! isGradientSegment }
color={ customIndicatorColor }
Expand Down
32 changes: 28 additions & 4 deletions packages/components/src/color-picker/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ function ColorPicker( {
isGradientColor,
onNavigationBack,
onCloseBottomSheet,
onBottomSheetClosed,
onHardwareButtonPress,
bottomLabelText,
} ) {
const isIOS = Platform.OS === 'ios';
const hitSlop = { top: 22, bottom: 22, left: 22, right: 22 };
Expand Down Expand Up @@ -55,6 +58,10 @@ function ColorPicker( {
styles.colorText,
styles.colorTextDark
);
const selectColorTextStyle = usePreferredColorSchemeStyle(
styles.selectColorText,
styles.selectColorTextDark
);
const footerStyle = usePreferredColorSchemeStyle(
styles.footer,
styles.footerDark
Expand Down Expand Up @@ -82,7 +89,15 @@ function ColorPicker( {
}
setColor( activeColor );
shouldDisableBottomSheetMaxHeight( false );
onCloseBottomSheet( () => setColor( savedColor ) );
onCloseBottomSheet( () => {
setColor( savedColor );
if ( onBottomSheetClosed ) {
onBottomSheetClosed();
}
} );
if ( onHardwareButtonPress ) {
onHardwareButtonPress( onButtonPress );
}
}, [] );

function onHuePickerChange( { hue: h } ) {
Expand All @@ -99,6 +114,9 @@ function ColorPicker( {
onCloseBottomSheet( null );
shouldDisableBottomSheetMaxHeight( true );
setColor( action === 'apply' ? currentColor : savedColor );
if ( onBottomSheetClosed ) {
onBottomSheetClosed();
}
}

return (
Expand Down Expand Up @@ -157,9 +175,15 @@ function ColorPicker( {
) }
</View>
</TouchableWithoutFeedback>
<Text style={ colorTextStyle } selectable>
{ currentColor.toUpperCase() }
</Text>
{ bottomLabelText ? (
<Text style={ selectColorTextStyle }>
{ bottomLabelText }
</Text>
) : (
<Text style={ colorTextStyle } selectable>
{ currentColor.toUpperCase() }
</Text>
) }
<TouchableWithoutFeedback
onPress={ () => onButtonPress( 'apply' ) }
hitSlop={ hitSlop }
Expand Down
11 changes: 11 additions & 0 deletions packages/components/src/color-picker/style.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@
color: $dark-primary;
}

.selectColorText {
text-align: center;
color: $gray;
font-size: 16px;
line-height: 24px;
}

.selectColorTextDark {
color: $dark-primary;
}

.picker {
padding: $grid-unit-20;
border-radius: $grid-unit-20 / 2;
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export {
} from '@wordpress/primitives';
export { default as ColorIndicator } from './color-indicator';
export { default as ColorPalette } from './color-palette';
export { default as ColorPicker } from './color-picker';
export { default as Dashicon } from './dashicon';
export { default as Dropdown } from './dropdown';
export { default as DropdownMenu } from './dropdown-menu';
Expand Down