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 - Global styles: Set theme's background and text color #30810

Merged
merged 24 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7716adc
Mobile - Read global styles and set color palette and gradients
Apr 9, 2021
f670aec
Mobile - Enable colors for blocks that support it
Apr 13, 2021
3f18835
Parse all color variables
Apr 13, 2021
fa6b94d
Merge branch 'rnmobile/feature/global-styles-base' into rnmobile/feat…
Apr 13, 2021
007e862
Mobile - Set background, title, text and link colors
Apr 13, 2021
6561363
Fix gradients
Apr 13, 2021
69881e5
Merge branch 'rnmobile/feature/global-styles-base' into rnmobile/feat…
Apr 13, 2021
ac1ac60
Add placeholder color
Apr 20, 2021
ef66314
Update global styles mocked data
May 6, 2021
0187528
Move color settings
May 6, 2021
acef561
Removed added spaces
May 6, 2021
d83a6b0
Add tests
May 6, 2021
f65d4d3
Merge branch 'rnmobile/3163-GSS' into rnmobile/feature/global-styles-…
May 7, 2021
bfceb8d
Update experimental features path and prepare for rawGlobalStylesBase…
May 7, 2021
cad71d8
Merge branch 'rnmobile/3163-GSS' into rnmobile/feature/global-styles-…
May 7, 2021
dace68b
Merge branch 'rnmobile/feature/global-styles-base' into rnmobile/feat…
May 7, 2021
3e41130
Add missing provider
May 7, 2021
f25b49f
Merge branch 'rnmobile/3163-GSS' into rnmobile/feature/global-styles-…
May 18, 2021
b04de9f
Get the right color attribute
May 18, 2021
1dc8de1
Remove mock data
May 18, 2021
66a873f
Merge branch 'rnmobile/3163-GSS' into rnmobile/feature/global-styles-…
May 21, 2021
31121ef
Merge branch 'rnmobile/3163-GSS' into rnmobile/feature/global-styles-…
May 28, 2021
026dd44
Mobile - Fix base global colors
May 28, 2021
fb1537c
Merge branch 'rnmobile/3163-GSS' into rnmobile/feature/global-styles-…
Jun 17, 2021
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 @@ -48,11 +48,13 @@ function BlockForType( {
parentWidth,
wrapperProps,
blockWidth,
baseGlobalStyles,
} ) {
const defaultColors = useSetting( 'color.palette' ) || emptyArray;
const globalStyle = useGlobalStyles();
const mergedStyle = useMemo( () => {
return getMergedGlobalStyles(
baseGlobalStyles,
globalStyle,
wrapperProps.style,
attributes,
Expand Down Expand Up @@ -300,6 +302,7 @@ export default compose( [
withSelect( ( select, { clientId, rootClientId } ) => {
const {
getBlockIndex,
getSettings,
isBlockSelected,
__unstableGetBlockWithoutInnerBlocks,
getSelectedBlockClientId,
Expand Down Expand Up @@ -347,6 +350,9 @@ export default compose( [
isDescendantOfParentSelected ||
isParentSelected ||
parentId === '';
const baseGlobalStyles = getSettings()
?.__experimentalGlobalStylesBaseStyles;

return {
icon,
name: name || 'core/missing',
Expand All @@ -360,6 +366,7 @@ export default compose( [
isParentSelected,
firstToSelectId,
isTouchable,
baseGlobalStyles,
wrapperProps: getWrapperProps(
attributes,
blockType.getEditWrapperProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useEffect } from '@wordpress/element';
import withRegistryProvider from './with-registry-provider';
import useBlockSync from './use-block-sync';
import { store as blockEditorStore } from '../../store';
import { BlockRefsProvider } from './block-refs-provider';

/** @typedef {import('@wordpress/data').WPDataRegistry} WPDataRegistry */

Expand All @@ -24,7 +25,7 @@ function BlockEditorProvider( props ) {
// Syncs the entity provider with changes in the block-editor store.
useBlockSync( props );

return children;
return <BlockRefsProvider>{ children }</BlockRefsProvider>;
}

export default withRegistryProvider( BlockEditorProvider );
2 changes: 1 addition & 1 deletion packages/block-editor/src/hooks/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export function ColorEdit( props ) {
localAttributes.current = attributes;
}, [ attributes ] );

if ( ! hasColorSupport( blockName ) || Platform.OS !== 'web' ) {
if ( ! hasColorSupport( blockName ) ) {
return null;
}

Expand Down
5 changes: 5 additions & 0 deletions packages/block-library/src/paragraph/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ function ParagraphBlock( {
const { align, content, placeholder } = attributes;

const styles = {
...( mergedStyle?.baseColors && {
color: mergedStyle.baseColors?.color?.text,
placeholderColor: mergedStyle.baseColors?.color?.text,
linkColor: mergedStyle.baseColors?.elements?.link?.color?.text,
} ),
...mergedStyle,
...style,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,21 @@ const GlobalStylesContext = createContext( { style: {} } );
GlobalStylesContext.BLOCK_STYLE_ATTRIBUTES = BLOCK_STYLE_ATTRIBUTES;

export const getMergedGlobalStyles = (
baseGlobalStyles,
globalStyle,
wrapperPropsStyle,
blockAttributes,
defaultColors
) => {
const baseGlobalColors = {
baseColors: baseGlobalStyles || {},
};
const blockStyleAttributes = pick(
blockAttributes,
BLOCK_STYLE_ATTRIBUTES
);
const mergedStyle = {
...baseGlobalColors,
...globalStyle,
...wrapperPropsStyle,
};
Expand Down
30 changes: 22 additions & 8 deletions packages/edit-post/src/components/layout/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import SafeArea from 'react-native-safe-area';
*/
import { Component } from '@wordpress/element';
import { withSelect } from '@wordpress/data';
import { BottomSheetSettings, FloatingToolbar } from '@wordpress/block-editor';
import {
BottomSheetSettings,
FloatingToolbar,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { compose, withPreferredColorScheme } from '@wordpress/compose';
import {
HTMLTextInput,
Expand Down Expand Up @@ -101,7 +105,7 @@ class Layout extends Component {
}

render() {
const { getStylesFromColorScheme, mode } = this.props;
const { getStylesFromColorScheme, mode, globalStyles } = this.props;

const isHtmlView = mode === 'text';

Expand All @@ -118,6 +122,16 @@ class Layout extends Component {
bottom: this.state.safeAreaInsets.bottom,
};

const editorStyles = [
getStylesFromColorScheme(
styles.background,
styles.backgroundDark
),
globalStyles?.background && {
backgroundColor: globalStyles.background,
},
];

return (
<Tooltip.Slot>
<SafeAreaView
Expand All @@ -128,12 +142,7 @@ class Layout extends Component {
onLayout={ this.onRootViewLayout }
>
<AutosaveMonitor disableIntervalChecks />
<View
style={ getStylesFromColorScheme(
styles.background,
styles.backgroundDark
) }
>
<View style={ editorStyles }>
{ isHtmlView ? this.renderHTML() : this.renderVisual() }
{ ! isHtmlView && Platform.OS === 'android' && (
<FloatingToolbar />
Expand Down Expand Up @@ -176,9 +185,14 @@ export default compose( [
editorStore
);
const { getEditorMode } = select( editPostStore );
const { getSettings } = select( blockEditorStore );
const globalStyles = getSettings()?.__experimentalGlobalStylesBaseStyles
?.color;

return {
isReady: isEditorReady(),
mode: getEditorMode(),
globalStyles,
};
} ),
withPreferredColorScheme,
Expand Down
30 changes: 22 additions & 8 deletions packages/editor/src/components/post-title/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { withFocusOutside } from '@wordpress/components';
import { withInstanceId, compose } from '@wordpress/compose';
import { __, sprintf } from '@wordpress/i18n';
import { pasteHandler } from '@wordpress/blocks';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { store as editorStore } from '@wordpress/editor';

/**
* Internal dependencies
Expand Down Expand Up @@ -107,12 +109,20 @@ class PostTitle extends Component {
borderStyle,
isDimmed,
postType,
globalStyles,
} = this.props;

const decodedPlaceholder = decodeEntities( placeholder );
const borderColor = this.props.isSelected
? focusedBorderColor
: 'transparent';
const titleStyles = {
...style,
...( globalStyles?.text && {
color: globalStyles.text,
placeholderColor: globalStyles.text,
} ),
};

return (
<View
Expand All @@ -134,7 +144,7 @@ class PostTitle extends Component {
unstableOnFocus={ this.props.onSelect }
onBlur={ this.props.onBlur } // always assign onBlur as a props
multiline={ false }
style={ style }
style={ titleStyles }
styles={ styles }
fontSize={ 24 }
fontWeight={ 'bold' }
Expand All @@ -159,30 +169,34 @@ class PostTitle extends Component {
export default compose(
withSelect( ( select ) => {
const { isPostTitleSelected, getEditedPostAttribute } = select(
'core/editor'
);

const { getSelectedBlockClientId, getBlockRootClientId } = select(
'core/block-editor'
editorStore
);
const {
getSelectedBlockClientId,
getBlockRootClientId,
getSettings,
} = select( blockEditorStore );

const selectedId = getSelectedBlockClientId();
const selectionIsNested = !! getBlockRootClientId( selectedId );
const globalStyles = getSettings()?.__experimentalGlobalStylesBaseStyles
?.color;

return {
postType: getEditedPostAttribute( 'type' ),
isAnyBlockSelected: !! selectedId,
isSelected: isPostTitleSelected(),
isDimmed: selectionIsNested,
globalStyles,
};
} ),
withDispatch( ( dispatch ) => {
const { undo, redo, togglePostTitleSelection } = dispatch(
'core/editor'
editorStore
);

const { clearSelectedBlock, insertDefaultBlock } = dispatch(
'core/block-editor'
blockEditorStore
);

return {
Expand Down
15 changes: 7 additions & 8 deletions packages/rich-text/src/component/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
/**
* External dependencies
*/
import { View, Platform } from 'react-native';
import { get, pickBy, debounce, isString } from 'lodash';
import memize from 'memize';
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for cleaning up 👍


/**
* WordPress dependencies
*/
import RCTAztecView from '@wordpress/react-native-aztec';
import { View, Platform } from 'react-native';
import {
showUserSuggestions,
showXpostSuggestions,
} from '@wordpress/react-native-bridge';
import { get, pickBy, debounce, isString } from 'lodash';
import memize from 'memize';

/**
* WordPress dependencies
*/
import { BlockFormatControls } from '@wordpress/block-editor';
import { Component } from '@wordpress/element';
import { compose, withPreferredColorScheme } from '@wordpress/compose';
Expand Down Expand Up @@ -982,10 +979,12 @@ export class RichText extends Component {
text: html,
eventCount: this.lastEventCount,
selection,
linkTextColor: defaultTextDecorationColor,
linkTextColor:
style?.linkColor || defaultTextDecorationColor,
} }
placeholder={ this.props.placeholder }
placeholderTextColor={
style?.placeholderColor ||
this.props.placeholderTextColor ||
defaultPlaceholderTextColor
}
Expand Down