Skip to content

Commit

Permalink
[Mobile] Create cover block with only colour (from a default palette)…
Browse files Browse the repository at this point in the history
… without an image (#23833)

* Create cover block with only color (from a theme palette)
  • Loading branch information
Antonis Lilis authored Jul 17, 2020
1 parent 0a22d69 commit 44295ce
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ function MediaPlaceholder( props ) {
getStylesFromColorScheme,
multiple,
value = [],
children,
height,
} = props;

// use ref to keep media array current for callbacks during rerenders
Expand Down Expand Up @@ -107,6 +109,7 @@ function MediaPlaceholder( props ) {
<Text style={ emptyStateTitleStyle }>
{ placeholderTitle }
</Text>
{ children }
<Text style={ styles.emptyStateDescription }>
{ instructions }
</Text>
Expand Down Expand Up @@ -164,7 +167,10 @@ function MediaPlaceholder( props ) {
>
<View
style={ [
emptyStateContainerStyle,
[
emptyStateContainerStyle,
height && { height },
],
isAppender && appenderStyle,
] }
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

.emptyStateTitle {
text-align: center;
margin-top: 8;
margin-bottom: 10;
margin-top: 4;
margin-bottom: 16;
font-size: 14;
color: #2e4453;
}
Expand Down
37 changes: 36 additions & 1 deletion packages/block-library/src/cover/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { View, TouchableWithoutFeedback } from 'react-native';
import Video from 'react-native-video';
import { noop } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -22,6 +23,7 @@ import {
ToolbarButton,
ToolbarGroup,
Gradient,
ColorPalette,
} from '@wordpress/components';
import {
BlockControls,
Expand Down Expand Up @@ -76,6 +78,7 @@ const Cover = ( {
onFocus,
overlayColor,
setAttributes,
settings,
closeSettingsBottomSheet,
} ) => {
const {
Expand All @@ -90,6 +93,11 @@ const Cover = ( {
} = attributes;
const CONTAINER_HEIGHT = minHeight || COVER_DEFAULT_HEIGHT;

const THEME_COLORS_COUNT = 4;
const coverDefaultPalette = {
colors: settings.colors.slice( 0, THEME_COLORS_COUNT ),
};

const { gradientValue } = __experimentalUseGradient();

const hasBackground = !! (
Expand Down Expand Up @@ -160,6 +168,16 @@ const Cover = ( {
setIsVideoLoading( false );
};

function setColor( color ) {
setAttributes( {
// clear all related attributes (only one should be set)
overlayColor: undefined,
customOverlayColor: color,
gradient: undefined,
customGradient: undefined,
} );
}

const backgroundColor = getStylesFromColorScheme(
styles.backgroundSolid,
styles.backgroundSolidDark
Expand Down Expand Up @@ -314,14 +332,28 @@ const Cover = ( {
return (
<View>
<MediaPlaceholder
height={ styles.mediaPlaceholderEmptyStateContainer.height }
icon={ placeholderIcon }
labels={ {
title: __( 'Cover' ),
} }
onSelect={ onSelectMedia }
allowedTypes={ ALLOWED_MEDIA_TYPES }
onFocus={ onFocus }
/>
>
<View style={ styles.colorPaletteWrapper }>
<ColorPalette
customColorIndicatorStyles={
styles.paletteColorIndicator
}
setColor={ setColor }
onCustomPress={ noop }
defaultSettings={ coverDefaultPalette }
shouldShowCustomIndicatorOption={ false }
shouldShowCustomLabel={ false }
/>
</View>
</MediaPlaceholder>
</View>
);
}
Expand Down Expand Up @@ -377,7 +409,10 @@ export default compose( [

const selectedBlockClientId = getSelectedBlockClientId();

const { getSettings } = select( 'core/block-editor' );

return {
settings: getSettings(),
isParentSelected: selectedBlockClientId === clientId,
};
} ),
Expand Down
15 changes: 15 additions & 0 deletions packages/block-library/src/cover/style.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,18 @@
.clearMediaButton {
color: $alert-red;
}

.colorPaletteWrapper {
min-height: 50px;
}

.paletteColorIndicator {
margin-top: 0;
margin-bottom: 0;
width: 32px;
height: 32px;
}

.mediaPlaceholderEmptyStateContainer {
height: 300;
}
28 changes: 20 additions & 8 deletions packages/components/src/color-palette/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ function ColorPalette( {
currentSegment,
onCustomPress,
shouldEnableBottomSheetScroll,
shouldShowCustomIndicatorOption = true,
shouldShowCustomLabel = true,
customColorIndicatorStyles,
} ) {
const customSwatchGradients = [
'linear-gradient(120deg, rgba(255,0,0,.8), 0%, rgba(255,255,255,1) 70.71%)',
Expand All @@ -66,7 +69,8 @@ function ColorPalette( {
: customSwatchGradients;
const isCustomGradientColor = isGradientColor && isSelectedCustom();
const shouldShowCustomIndicator =
! isGradientSegment || isCustomGradientColor;
shouldShowCustomIndicatorOption &&
( ! isGradientSegment || isCustomGradientColor );

const accessibilityHint = isGradientSegment
? __( 'Navigates to customize the gradient' )
Expand Down Expand Up @@ -222,7 +226,10 @@ function ColorPalette( {
color={ color }
isSelected={ isSelected( color ) }
opacity={ opacity }
style={ styles.colorIndicator }
style={ [
styles.colorIndicator,
customColorIndicatorStyles,
] }
/>
</Animated.View>
</TouchableWithoutFeedback>
Expand All @@ -245,13 +252,18 @@ function ColorPalette( {
withCustomPicker={ ! isGradientSegment }
color={ customIndicatorColor }
isSelected={ isSelectedCustom() }
style={ styles.colorIndicator }
style={ [
styles.colorIndicator,
customColorIndicatorStyles,
] }
/>
<Text style={ customTextStyle }>
{ isIOS
? customText
: customText.toUpperCase() }
</Text>
{ shouldShowCustomLabel && (
<Text style={ customTextStyle }>
{ isIOS
? customText
: customText.toUpperCase() }
</Text>
) }
</View>
</TouchableWithoutFeedback>
</View>
Expand Down

0 comments on commit 44295ce

Please sign in to comment.