Skip to content

Commit

Permalink
Custom Color picker action
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonis Lilis committed Jul 10, 2020
1 parent 508f015 commit 96b1582
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
23 changes: 21 additions & 2 deletions packages/block-library/src/cover/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ToolbarGroup,
Gradient,
ColorPalette,
ColorPicker,
} from '@wordpress/components';
import {
BlockControls,
Expand Down Expand Up @@ -102,6 +103,7 @@ const Cover = ( {
overlayColor,
setAttributes,
openGeneralSidebar,
closeSettingsBottomSheet,
} ) => {
const {
backgroundType,
Expand Down Expand Up @@ -269,6 +271,20 @@ const Cover = ( {
</InspectorControls>
);

const colorPickerControls = (
<InspectorControls>
<ColorPicker
shouldEnableBottomSheetScroll={ () => {} }
shouldDisableBottomSheetMaxHeight={ () => {} }
setColor={ () => {} }
onApply={ setColor }
onNavigationBack={ closeSettingsBottomSheet }
onCloseBottomSheet={ () => {} }
isBottomSheetContentScrolling={ () => {} }
/>
</InspectorControls>
);

const renderBackground = ( {
open: openMediaOptions,
getMediaOptions,
Expand Down Expand Up @@ -338,6 +354,7 @@ const Cover = ( {
if ( ! hasBackground ) {
return (
<View>
{ colorPickerControls }
<MediaPlaceholder
icon={ placeholderIcon }
labels={ {
Expand Down Expand Up @@ -417,8 +434,10 @@ export default compose( [
const { openGeneralSidebar } = dispatch( 'core/edit-post' );

return {
openGeneralSidebar: () =>
openGeneralSidebar( 'edit-post/block' ),
openGeneralSidebar: () => openGeneralSidebar( 'edit-post/block' ),
closeSettingsBottomSheet() {
dispatch( 'core/edit-post' ).closeGeneralSidebar();
},
};
} ),
withPreferredColorScheme,
Expand Down
8 changes: 7 additions & 1 deletion packages/components/src/color-picker/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function ColorPicker( {
isGradientColor,
onNavigationBack,
onCloseBottomSheet,
onApply,
} ) {
const isIOS = Platform.OS === 'ios';
const hitSlop = { top: 22, bottom: 22, left: 22, right: 22 };
Expand Down Expand Up @@ -98,7 +99,12 @@ function ColorPicker( {
onNavigationBack();
onCloseBottomSheet( null );
shouldDisableBottomSheetMaxHeight( true );
setColor( action === 'apply' ? currentColor : savedColor );
if ( action === 'apply' ) {
setColor( currentColor );
if ( onApply !== undefined ) onApply( currentColor );
} else {
setColor( savedColor );
}
}

return (
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

0 comments on commit 96b1582

Please sign in to comment.