From b950684e9b482a6fca786ba0666d6e2842c3aaca Mon Sep 17 00:00:00 2001 From: Chip Date: Mon, 15 Jun 2020 09:52:37 -0400 Subject: [PATCH] [RNMobile] Fix issues with gradients on Button Block and resetting themes (#23075) * Fix issues with gradients on Button Block * Reset to Defaults when clearing theme * Add code comments --- packages/block-library/src/button/edit.native.js | 4 ++-- .../editor/src/components/provider/index.native.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/button/edit.native.js b/packages/block-library/src/button/edit.native.js index e31dac35a3650..8a7ee832aece1 100644 --- a/packages/block-library/src/button/edit.native.js +++ b/packages/block-library/src/button/edit.native.js @@ -176,9 +176,9 @@ class ButtonEdit extends Component { getBackgroundColor() { const { backgroundColor, attributes, gradientValue } = this.props; - const { gradient, customGradient } = attributes; + const { customGradient } = attributes; - if ( customGradient || gradient ) { + if ( customGradient || gradientValue ) { return customGradient || gradientValue; } const colorAndStyleProps = getColorAndStyleProps( attributes ); diff --git a/packages/editor/src/components/provider/index.native.js b/packages/editor/src/components/provider/index.native.js index 6e71b90fba412..cb3299f28298a 100644 --- a/packages/editor/src/components/provider/index.native.js +++ b/packages/editor/src/components/provider/index.native.js @@ -24,6 +24,7 @@ import { import { withDispatch, withSelect } from '@wordpress/data'; import { compose } from '@wordpress/compose'; import { applyFilters } from '@wordpress/hooks'; +import { SETTINGS_DEFAULTS } from '@wordpress/block-editor'; const postTypeEntities = [ { name: 'post', baseURL: '/wp/v2/posts' }, @@ -107,6 +108,15 @@ class NativeEditorProvider extends Component { this.subscriptionParentUpdateTheme = subscribeUpdateTheme( ( theme ) => { + // Reset the colors and gradients in case one theme was set with custom items and then updated to a theme without custom elements. + if ( theme.colors === undefined ) { + theme.colors = SETTINGS_DEFAULTS.colors; + } + + if ( theme.gradients === undefined ) { + theme.gradients = SETTINGS_DEFAULTS.gradients; + } + this.props.updateSettings( theme ); } );