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

Style improvements for template previews #19763

Merged
merged 44 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
196c5bc
First scaffold for template previews (mobile only)
koke Dec 12, 2019
6c5579b
WIP: managed to make the preview show, saving as a checkpoint
koke Dec 13, 2019
b216ad5
Set a fixed height for the template preview
koke Dec 13, 2019
5c744af
Move template picker to the toolbar
koke Dec 17, 2019
d30b426
Read only block list
koke Dec 17, 2019
1c8531d
Lint fixes
koke Dec 17, 2019
93379d1
Made scrolling sort of working with read only block list
koke Dec 18, 2019
9fa1128
A longer template to test scrolling
koke Dec 23, 2019
4f0ba05
Replace BottomSheet with Modal for previews
koke Dec 23, 2019
02a1a13
Merge branch 'master' into add/spt-template-preview
koke Dec 27, 2019
aad8e3f
Allow closing previews with back button on Android
koke Dec 27, 2019
7c9fedd
Revert changes to BlockList that were required for bottom sheet integ…
koke Dec 27, 2019
e68c7a9
Revert changes to BottomSheet
koke Dec 27, 2019
8663c04
Add usage example for ModalHeaderBar
koke Dec 27, 2019
4e86917
Improve accessibility of template preview
koke Dec 27, 2019
833b049
Improve accessibility of ModalHeaderBar
koke Dec 27, 2019
247ad17
Remove unused imports
koke Dec 27, 2019
37b372f
Added missing web file
koke Dec 27, 2019
2b8f59f
RNMobile - Page template picker: apply layout from the preview
Jan 3, 2020
f305785
Merge branch 'master' into add/spt-template-preview
koke Jan 8, 2020
17e5366
Merge branch 'add/spt-template-preview' of github.com:WordPress/guten…
Jan 10, 2020
a6072ac
RNMobile - Layout preview: apply action
Jan 15, 2020
5d473c4
Merge with master
Jan 15, 2020
98b4c95
RNMobile - Page templates - set layout action
Jan 15, 2020
1380756
Remove mobile action from docs
Jan 15, 2020
b33d708
New components for modal header buttons
koke Jan 16, 2020
f247ccc
Fix alignment of modal header buttons
koke Jan 16, 2020
e877d5c
Fix metrics for iOS modal header
koke Jan 20, 2020
7a49209
Add subtitle to preview header
koke Jan 20, 2020
a317a97
Merge branch 'master' into fix/template-preview-styles
koke Jan 20, 2020
0ac724b
Use named color for modal header button
koke Jan 20, 2020
199e313
Updated modal title color and weight
koke Jan 21, 2020
9221ae4
Make Apply button bolder on iOS
koke Jan 21, 2020
b06b3cb
Make Apply button bolder on iOS
koke Jan 21, 2020
db1db31
Fix vertical alignment for close button
koke Jan 21, 2020
6ece428
Allow modal rotation on iOS
koke Jan 21, 2020
58740aa
Fix modal background on dark mode
koke Jan 21, 2020
a935cc5
Fixed dark mode for template previews
koke Jan 21, 2020
2d61cbf
Merge branch 'master' into fix/template-preview-styles
koke Jan 22, 2020
8e21a7a
Merge branch 'master' into fix/template-preview-styles
koke Jan 22, 2020
8af053d
Revert changes to editor store after bad merge
koke Jan 23, 2020
bf23bbc
Add material close icon for modal header
koke Jan 23, 2020
4ccda89
Tweak modal title colors
koke Jan 24, 2020
badc83b
Lint fixes
koke Jan 24, 2020
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 @@ -2,19 +2,15 @@
* WordPress dependencies
*/
import { BlockEditorProvider, BlockList } from '@wordpress/block-editor';
import { Button, ModalHeaderBar } from '@wordpress/components';
import { ModalHeaderBar } from '@wordpress/components';
import { usePreferredColorScheme } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';

/**
* External dependencies
*/
import { Modal, View, SafeAreaView, Text, TouchableOpacity } from 'react-native';

/**
* Internal dependencies
*/
import styles from './styles.scss';
import { Modal, View, SafeAreaView } from 'react-native';

// We are replicating this here because the one in @wordpress/block-editor always
// tries to scale the preview and we would need a lot of cross platform code to handle
Expand Down Expand Up @@ -46,45 +42,38 @@ BlockPreview.displayName = 'BlockPreview';

const Preview = ( props ) => {
const { template, onDismiss, onApply } = props;
const preferredColorScheme = usePreferredColorScheme();
const containerBackgroundColor = preferredColorScheme === 'dark' ? 'black' : 'white';

if ( template === undefined ) {
return null;
}

const leftButton = (
<View
style={ { flex: 1, width: 44 } }
>
<Button
icon="no-alt"
size={ 24 }
label={ __( 'Close' ) }
onClick={ onDismiss }
/>
</View>
<ModalHeaderBar.CloseButton onPress={ onDismiss } />
);

const rightButton = (
<View
style={ styles.headerRightButton }
>
<TouchableOpacity onPress={ onApply }>
<Text>{ __( 'Apply' ) }</Text>
</TouchableOpacity>
</View>
<ModalHeaderBar.Button
onPress={ onApply }
title={ __( 'Apply' ) }
isPrimary={ true }
/>
);

return (
<Modal
visible={ !! template }
animationType="slide"
onRequestClose={ onDismiss }
supportedOrientations={ [ 'portrait', 'landscape' ] }
>
<SafeAreaView style={ { flex: 1 } }>
<SafeAreaView style={ { flex: 1, backgroundColor: containerBackgroundColor } }>
<ModalHeaderBar
leftButton={ leftButton }
rightButton={ rightButton }
title={ template.name }
subtitle={ __( 'Template Preview' ) }
/>
<BlockPreview
blocks={ template.blocks }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,3 @@
.buttonTextDark {
color: $light-opacity-700;
}

.headerRightButton {
flex: 1;
align-items: flex-end;
justify-content: center;
padding-right: 12px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@import "./button.native.scss";

.icon {
margin-top: 1px;
}

.title {
text-transform: uppercase;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import "./button.native.scss";

.titlePrimary {
font-weight: 600;
}
52 changes: 52 additions & 0 deletions packages/components/src/mobile/modal-header-bar/button.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* WordPress dependencies
*/
import { withPreferredColorScheme } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';

/**
* External dependencies
*/
import { Platform, Text, TouchableOpacity } from 'react-native';

/**
* Internal dependencies
*/
import Icon from '../../icon';
import styles from './button.scss';

const ICON_SIZE = 24;

const Button = withPreferredColorScheme( ( { icon, onPress, title, isPrimary, getStylesFromColorScheme } ) => {
const titleStyle = getStylesFromColorScheme( styles.title, styles.titleDark );
return (
<TouchableOpacity onPress={ onPress }>
{ icon ?
<Icon icon={ icon } size={ ICON_SIZE } style={ styles.icon } /> :
<Text style={ [ titleStyle, isPrimary && styles.titlePrimary ] }>{ title }</Text>
}
</TouchableOpacity>
);
} );

Button.displayName = 'ModalHeaderBar.Button';

export { Button };

const CloseButton = ( { onPress } ) => {
const props = Platform.select( {
ios: {
title: __( 'Close' ),
},
android: {
accessibilityLabel: __( 'Close' ),
icon: 'no-alt',
},
} );
return (
<Button onPress={ onPress } { ...props } />
);
};
CloseButton.displayName = 'ModalHeaderBar.CloseButton';

export { CloseButton };
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.title {
color: $blue-50;
font-size: 17px;
}

.titleDark {
color: $blue-30;
}
19 changes: 15 additions & 4 deletions packages/components/src/mobile/modal-header-bar/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,36 @@ import { withPreferredColorScheme } from '@wordpress/compose';
* Internal dependencies
*/
import styles from './styles.scss';
import { Button, CloseButton } from './button';

const ModalHeaderBar = withPreferredColorScheme( ( props ) => {
const {
leftButton,
title,
subtitle,
rightButton,
getStylesFromColorScheme,
} = props;

const separatorStyle = getStylesFromColorScheme( styles.separator, styles.separatorDark );
// TODO: dark mode for background and title??
const titleStyle = getStylesFromColorScheme( styles.title, styles.titleDark );
const subtitleStyle = getStylesFromColorScheme( styles.subtitle, styles.subtitleDark );

return (
<View>
<View style={ styles.bar }>
<View style={ [ styles.bar, subtitle && styles.subtitleBar ] }>
<View style={ styles.leftContainer }>
{ leftButton }
</View>
<View style={ styles.titleContainer }>
<Text style={ styles.title } accessibilityRole="header">
<View style={ styles.titleContainer } accessibilityRole="header">
<Text style={ titleStyle }>
{ title }
</Text>
{ subtitle &&
<Text style={ subtitleStyle }>
{ subtitle }
</Text>
}
</View>
<View style={ styles.rightContainer }>
{ rightButton }
Expand All @@ -46,4 +54,7 @@ const ModalHeaderBar = withPreferredColorScheme( ( props ) => {

ModalHeaderBar.displayName = 'ModalHeaderBar';

ModalHeaderBar.Button = Button;
ModalHeaderBar.CloseButton = CloseButton;

export default ModalHeaderBar;
40 changes: 29 additions & 11 deletions packages/components/src/mobile/modal-header-bar/styles.native.scss
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
.bar {
flex-direction: row;
width: 100%;
margin-bottom: 5px;
justify-content: space-between;
align-items: center;
align-content: center;
min-height: 48;
height: 48px;
padding: 0 16px;
}

.subtitleBar {
height: 64px;
}

.leftContainer {
flex: 1;
justify-content: flex-start;
flex-grow: 0;
flex-shrink: 0;
}

.rightContainer {
flex: 1;
justify-content: flex-end;
flex-grow: 0;
flex-shrink: 0;
}

.titleContainer {
justify-content: center;
flex: 2;
align-content: center;
flex: 1;
flex-direction: column;
}

.title {
color: $dark-gray-600;
color: $gray-90;
font-size: 18px;
font-weight: 600;
font-weight: bold;
text-align: center;
}

.titleDark {
color: $white;
}

.subtitle {
flex-shrink: 0;
text-align: center;
font-size: 16px;
color: $gray-60;
}

.subtitleDark {
color: $light-opacity-200;
}

.separator {
Expand Down
14 changes: 14 additions & 0 deletions packages/editor/src/store/actions.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*/
import RNReactNativeGutenbergBridge from 'react-native-gutenberg-bridge';

/**
* Internal dependencies
*/
import { editPost } from './actions.js';

export * from './actions.js';

/**
Expand All @@ -25,3 +30,12 @@ export function togglePostTitleSelection( isSelected = true ) {
export function* autosave() {
RNReactNativeGutenbergBridge.editorDidAutosave();
}

/**
* Action generator to set the selected layout template.
*
* @param {Object} template Layout's template
*/
export function* setLayoutTemplate( template ) {
koke marked this conversation as resolved.
Show resolved Hide resolved
yield* editPost( { title: template.name, blocks: template.content } );
}