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] Support Theme Colors and Gradients #22197

Merged
merged 15 commits into from
Jun 3, 2020
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 @@ -9,10 +9,7 @@ import {
} from '@wordpress/components';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import {
InspectorControls,
SETTINGS_DEFAULTS as defaultSettings,
} from '@wordpress/block-editor';
import { InspectorControls } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -22,6 +19,7 @@ import styles from './container.native.scss';
function BottomSheetSettings( {
editorSidebarOpened,
closeGeneralSidebar,
settings,
...props
} ) {
return (
Expand All @@ -38,7 +36,7 @@ function BottomSheetSettings( {
case colorsUtils.subsheets.color:
return (
<ColorSettings
defaultSettings={ defaultSettings }
defaultSettings={ settings }
{ ...bottomSheetProps }
{ ...extraProps }
/>
Expand All @@ -56,8 +54,9 @@ function BottomSheetSettings( {
export default compose( [
withSelect( ( select ) => {
const { isEditorSidebarOpened } = select( 'core/edit-post' );

const { getSettings } = select( 'core/block-editor' );
return {
settings: getSettings(),
editorSidebarOpened: isEditorSidebarOpened(),
};
} ),
Expand Down
14 changes: 5 additions & 9 deletions packages/block-library/src/button/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
withColors,
InspectorControls,
BlockControls,
SETTINGS_DEFAULTS,
__experimentalUseGradient,
} from '@wordpress/block-editor';
import {
TextControl,
Expand Down Expand Up @@ -175,17 +175,11 @@ class ButtonEdit extends Component {
}

getBackgroundColor() {
const { backgroundColor, attributes } = this.props;
const { backgroundColor, attributes, gradientValue } = this.props;
const { gradient, customGradient } = attributes;
const defaultGradients = SETTINGS_DEFAULTS.gradients;

if ( customGradient || gradient ) {
return (
customGradient ||
defaultGradients.find(
( defaultGradient ) => defaultGradient.slug === gradient
).gradient
);
return customGradient || gradientValue;
}
const colorAndStyleProps = getColorAndStyleProps( attributes );
return (
Expand Down Expand Up @@ -547,6 +541,7 @@ export default compose( [
withInstanceId,
withColors( 'backgroundColor', { textColor: 'color' } ),
withSelect( ( select, { clientId } ) => {
const { gradientValue } = __experimentalUseGradient();
const { isEditorSidebarOpened } = select( 'core/edit-post' );
const {
getSelectedBlockClientId,
Expand All @@ -559,6 +554,7 @@ export default compose( [
const numOfButtons = getBlockCount( parentId );

return {
gradientValue,
selectedId,
editorSidebarOpened: isEditorSidebarOpened(),
numOfButtons,
Expand Down
18 changes: 16 additions & 2 deletions packages/edit-post/src/editor.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class Editor extends Component {
hasFixedToolbar,
focusMode,
hiddenBlockTypes,
blockTypes
blockTypes,
colors,
gradients
) {
settings = {
...settings,
Expand All @@ -70,6 +72,14 @@ class Editor extends Component {
);
}

if ( colors !== undefined ) {
settings.colors = colors;
}

if ( gradients !== undefined ) {
settings.gradients = gradients;
}

dratwas marked this conversation as resolved.
Show resolved Hide resolved
return settings;
}

Expand Down Expand Up @@ -103,6 +113,8 @@ class Editor extends Component {
blockTypes,
post,
postType,
colors,
gradients,
...props
} = this.props;

Expand All @@ -111,7 +123,9 @@ class Editor extends Component {
hasFixedToolbar,
focusMode,
hiddenBlockTypes,
blockTypes
blockTypes,
colors,
gradients
);

const normalizedPost = post || {
Expand Down
14 changes: 13 additions & 1 deletion packages/editor/src/components/provider/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import RNReactNativeGutenbergBridge, {
subscribeUpdateHtml,
subscribeSetTitle,
subscribeMediaAppend,
subscribeUpdateTheme,
} from 'react-native-gutenberg-bridge';

/**
Expand Down Expand Up @@ -98,6 +99,12 @@ class NativeEditorProvider extends Component {
this.props.insertBlock( newBlock, insertionIndex );
}
);

this.subscriptionParentUpdateTheme = subscribeUpdateTheme(
( theme ) => {
this.props.updateSettings( theme );
}
);
}

componentWillUnmount() {
Expand All @@ -120,6 +127,10 @@ class NativeEditorProvider extends Component {
if ( this.subscriptionParentMediaAppend ) {
this.subscriptionParentMediaAppend.remove();
}

if ( this.subscriptionParentUpdateTheme ) {
this.subscriptionParentUpdateTheme.remove();
}
}

componentDidUpdate( prevProps ) {
Expand Down Expand Up @@ -221,13 +232,14 @@ export default compose( [
} ),
withDispatch( ( dispatch ) => {
const { editPost, resetEditorBlocks } = dispatch( 'core/editor' );
const { clearSelectedBlock, insertBlock } = dispatch(
const { updateSettings, clearSelectedBlock, insertBlock } = dispatch(
'core/block-editor'
);
const { switchEditorMode } = dispatch( 'core/edit-post' );
const { addEntities, receiveEntityRecords } = dispatch( 'core' );

return {
updateSettings,
addEntities,
clearSelectedBlock,
insertBlock,
Expand Down
1 change: 1 addition & 0 deletions test/native/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jest.mock( 'react-native-gutenberg-bridge', () => {
subscribeUpdateHtml: jest.fn(),
subscribeMediaAppend: jest.fn(),
subscribeAndroidModalClosed: jest.fn(),
subscribeUpdateTheme: jest.fn(),
subscribePreferredColorScheme: () => 'light',
editorDidMount: jest.fn(),
editorDidAutosave: jest.fn(),
Expand Down