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

Feature/inserter modal #124

Merged
merged 23 commits into from
Aug 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d6a5fd9
added react-native-modal library
mzorz Aug 18, 2018
5ef7a16
added block-picker component using Modal library
mzorz Aug 20, 2018
3ab17d2
removed old block type picker
mzorz Aug 20, 2018
4ea24a5
moved list of block types to block-picker
mzorz Aug 20, 2018
4b1a470
fixed merge conflict
mzorz Aug 21, 2018
c29ffc2
fixed modalContent style and added dismiss onBackdropPress
mzorz Aug 22, 2018
149a355
fixed this.onBlockTypeSelected to carry itemValue alone
mzorz Aug 22, 2018
d63ecfe
fixed style prop in PropsType
mzorz Aug 22, 2018
e738580
moved BlockPicker StyleSheet definitions to .scss file
mzorz Aug 22, 2018
2df2876
fix lint issues
mzorz Aug 22, 2018
dcaac66
added comment
mzorz Aug 22, 2018
efcde15
showing BlockType title on BlockPicker and removed hardcoded index in…
mzorz Aug 22, 2018
b9ed407
added a bit of styling to bottom-anchored modal dialog
mzorz Aug 22, 2018
eceeac9
more style love
mzorz Aug 22, 2018
ed512a9
bold title
mzorz Aug 22, 2018
c05d4b0
added modal border and set backdrop semitransparent color to grey
mzorz Aug 22, 2018
d04f443
modified touch behavior a bit to show feedback
mzorz Aug 22, 2018
fe99757
made modal corners more round, and divider line occupy full width
mzorz Aug 22, 2018
6c45a84
added short grey line as modal dragging indicator
mzorz Aug 22, 2018
cbd6de4
added ADD BLOCK HERE label
mzorz Aug 22, 2018
4de33d6
added icon text placeholder
mzorz Aug 22, 2018
80e0b63
fixed lint warnings
mzorz Aug 22, 2018
a955808
Merge branch 'master' into feature/inserter-modal
mzorz Aug 22, 2018
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"node-sass": "^4.8.3",
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-modal": "^6.5.0",
"react-native-recyclerview-list": "git+https://github.com/wordpress-mobile/react-native-recyclerview-list.git#bfccbaab6b5954e18f8b0ed441ba38275853b79c",
"react-native-svg": "^6.5.2",
"react-redux": "^5.0.7",
Expand Down
63 changes: 35 additions & 28 deletions src/block-management/block-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
*/

import React from 'react';
import { Platform, Switch, Text, View, FlatList, Picker, TextInput, KeyboardAvoidingView } from 'react-native';
import { Platform, Switch, Text, View, FlatList, TextInput, KeyboardAvoidingView } from 'react-native';
import RecyclerViewList, { DataSource } from 'react-native-recyclerview-list';
import BlockHolder from './block-holder';
import { ToolbarButton } from './constants';
import type { BlockType } from '../store/';
import styles from './block-manager.scss';
import BlockPicker from './block-picker';
// Gutenberg imports
import { getBlockType, getBlockTypes, serialize, createBlock } from '@wordpress/blocks';
import { getBlockType, serialize, createBlock } from '@wordpress/blocks';

export type BlockListType = {
onChange: ( clientId: string, attributes: mixed ) => void,
Expand All @@ -36,8 +37,6 @@ type StateType = {
};

export default class BlockManager extends React.Component<PropsType, StateType> {
availableBlockTypes = getBlockTypes();

constructor( props: PropsType ) {
super( props );
this.state = {
Expand Down Expand Up @@ -75,8 +74,8 @@ export default class BlockManager extends React.Component<PropsType, StateType>

// TODO: in the near future this will likely be changed to onShowBlockTypePicker and bound to this.props
// once we move the action to the toolbar
showBlockTypePicker() {
this.setState( { ...this.state, blockTypePickerVisible: true } );
showBlockTypePicker( show: boolean ) {
this.setState( { ...this.state, blockTypePickerVisible: show } );
}

onBlockTypeSelected( itemValue: string ) {
Expand Down Expand Up @@ -125,7 +124,7 @@ export default class BlockManager extends React.Component<PropsType, StateType>
this.props.deleteBlockAction( clientId );
break;
case ToolbarButton.PLUS:
this.showBlockTypePicker();
this.showBlockTypePicker( true );
break;
case ToolbarButton.SETTINGS:
// TODO: implement settings
Expand Down Expand Up @@ -201,17 +200,14 @@ export default class BlockManager extends React.Component<PropsType, StateType>
}

const blockTypePicker = (
<View>
<Picker
selectedValue={ this.state.selectedBlockType }
onValueChange={ ( itemValue ) => {
this.onBlockTypeSelected( itemValue );
} } >
{ this.availableBlockTypes.map( ( item, index ) => {
return ( <Picker.Item label={ item.title } value={ item.name } key={ index + 1 } /> );
} ) }
</Picker>
</View>
<BlockPicker
visible={ this.state.blockTypePickerVisible }
onDismiss={ () => {
this.showBlockTypePicker( false );
} }
onValueSelected={ ( itemValue ) => {
this.onBlockTypeSelected( itemValue );
} } />
);

return (
Expand All @@ -228,7 +224,7 @@ export default class BlockManager extends React.Component<PropsType, StateType>
</View>
{ this.state.showHtml && this.renderHTML() }
{ ! this.state.showHtml && list }
{ this.state.blockTypePickerVisible && blockTypePicker }
{ blockTypePicker }
</View>
);
}
Expand All @@ -249,16 +245,27 @@ export default class BlockManager extends React.Component<PropsType, StateType>
}

renderItem( value: { item: BlockType, clientId: string } ) {
const insertHere = (
<View style={ styles.containerStyleAddHere } >
<View style={ styles.lineStyleAddHere }></View>
<Text style={ styles.labelStyleAddHere } >ADD BLOCK HERE</Text>
<View style={ styles.lineStyleAddHere }></View>
</View>
);

return (
<BlockHolder
key={ value.clientId }
onToolbarButtonPressed={ this.onToolbarButtonPressed.bind( this ) }
onBlockHolderPressed={ this.onBlockHolderPressed.bind( this ) }
onChange={ this.onChange.bind( this ) }
focused={ value.item.focused }
clientId={ value.clientId }
{ ...value.item }
/>
<View>
<BlockHolder
key={ value.clientId }
onToolbarButtonPressed={ this.onToolbarButtonPressed.bind( this ) }
onBlockHolderPressed={ this.onBlockHolderPressed.bind( this ) }
onChange={ this.onChange.bind( this ) }
focused={ value.item.focused }
clientId={ value.clientId }
{ ...value.item }
/>
{ this.state.blockTypePickerVisible && value.item.focused && insertHere }
</View>
);
}

Expand Down
21 changes: 21 additions & 0 deletions src/block-management/block-manager.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,24 @@
flex-direction: row;
justify-content: flex-start;
}

.lineStyleAddHere {
flex: 1;
background-color: #0087be; // blue_wordpress
align-self: center;
height: 2px;
}

.labelStyleAddHere {
flex: 1;
text-align: center;
font-family: $default-monospace-font;
font-size: 12px;
font-weight: bold;
}

.containerStyleAddHere {
flex: 1;
flex-direction: row;
background-color: white;
}
77 changes: 77 additions & 0 deletions src/block-management/block-picker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* @format
* @flow
*/
import React, { Component } from 'react';
import { FlatList, Text, TouchableHighlight, View } from 'react-native';
import Modal from 'react-native-modal';
import styles from './block-picker.scss';
// Gutenberg imports
import { getBlockTypes } from '@wordpress/blocks';

type PropsType = {
visible: boolean,
style?: StyleSheet,
onValueSelected: ( itemValue: string, itemIndex: number ) => void,
onDismiss: () => void,
};

// TODO: not used for now - will hold currently selected Block Type, probably makes sense for the inspector
type StateType = {
selectedIndex: number,
};

export default class BlockPicker extends Component<PropsType, StateType> {
availableBlockTypes = getBlockTypes();

constructor( props: PropsType ) {
super( props );
this.state = {
selectedIndex: 0,
};
}

render() {
return (
<Modal
animationType="slide"
transparent={ true }
isVisible={ this.props.visible }
onSwipe={ this.props.onDismiss.bind( this ) }
swipeDirection="down"
style={ [ styles.bottomModal, this.props.style ] }
backdropColor={ 'lightgrey' }
backdropOpacity={ 0.4 }
onBackdropPress={ this.props.onDismiss.bind( this ) }>
<View style={ styles.modalContent }>
<View style={ styles.shortLineStyle } />
<View>
<Text style={ styles.title }>ADD BLOCK</Text>
</View>
<View style={ styles.lineStyle } />
<FlatList
numColumns={ 3 }
data={ this.availableBlockTypes }
keyExtractor={ ( item ) => item.name }
renderItem={ ( { item } ) =>
<TouchableHighlight
style={ styles.touchableArea }
underlayColor={ 'transparent' }
activeOpacity={ .5 }
onPress={ this.props.onValueSelected.bind( this, item.name ) }>
<View style={ styles.modalItem }>
<View style={ styles.modalIcon }>
{ /* TODO: ICON IMAGE GOES HERE */ }
{ /* <Text>{ item.icon.src }</Text> */ }
<Text>icon</Text>
</View>
<Text style={ styles.modalItemLabel }>{ item.title }</Text>
</View>
</TouchableHighlight>
}
/>
</View>
</Modal>
);
}
}
76 changes: 76 additions & 0 deletions src/block-management/block-picker.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/** @format */

@import '../variables.scss';

.title {
font-family: $default-monospace-font;
font-size: 16px;
font-weight: bold;
margin-bottom: 8px;
}

.lineStyle {
border-bottom-color: lightgray;
border-bottom-width: 1px;
width: 100%;
}

.shortLineStyle {
border-bottom-color: lightgray;
border-bottom-width: 2px;
margin-bottom: 8px;
width: 40px;
}

.bottomModal {
justify-content: flex-end;
margin: 0px;
}

.touchableArea {
border-radius: 4px 4px 4px 4px;
}

.modalContent {
background-color: white;
padding-top: 8;
padding-bottom: 8;
justify-content: center;
align-items: center;
border-radius: 10px 10px 0px 0px;
border-color: grey;
border-width: 1px;
}

.modalItem {
flex: 1 1 auto;
margin: 5px;
width: 100px;
align-self: stretch;
justify-content: center;
align-items: center;
}

.modalIcon {
flex: 1 1 auto;
background-color: lightgray;
padding-left: 8;
padding-right: 8;
padding-top: 8;
padding-bottom: 8;
margin: 4px;
width: 72px;
height: 48px;
justify-content: center;
align-items: center;
border-radius: 4px 4px 4px 4px;
}

.modalItemLabel {
background-color: transparent;
padding-left: 2;
padding-right: 2;
padding-top: 2;
padding-bottom: 2;
justify-content: center;
}
15 changes: 14 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6214,7 +6214,7 @@ promise@^7.0.3, promise@^7.1.1:
dependencies:
asap "~2.0.3"

prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.2:
prop-types@^15.5.10, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2:
version "15.6.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102"
dependencies:
Expand Down Expand Up @@ -6334,6 +6334,12 @@ react-is@^16.3.1:
version "16.4.2"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.4.2.tgz#84891b56c2b6d9efdee577cc83501dfc5ecead88"

react-native-animatable@^1.2.4:
version "1.3.0"
resolved "https://registry.yarnpkg.com/react-native-animatable/-/react-native-animatable-1.3.0.tgz#b5c3940fc758cfd9b2fe54613a457c4b6962b46e"
dependencies:
prop-types "^15.5.10"

react-native-crypto@^2.0.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/react-native-crypto/-/react-native-crypto-2.1.2.tgz#cfe68cad51cd1f73a4202b7ac164f96c1144cb2a"
Expand All @@ -6348,6 +6354,13 @@ react-native-crypto@^2.0.1:
pbkdf2 "3.0.8"
public-encrypt "^4.0.0"

react-native-modal@^6.5.0:
version "6.5.0"
resolved "https://registry.yarnpkg.com/react-native-modal/-/react-native-modal-6.5.0.tgz#46220b2289a41597d344c1db17454611b426a758"
dependencies:
prop-types "^15.6.1"
react-native-animatable "^1.2.4"

react-native-randombytes@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/react-native-randombytes/-/react-native-randombytes-2.3.0.tgz#3ed6f8a4a803c453d787961047f6b2650d7c7335"
Expand Down