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

Make a simple version of DefaultBlockAppender for mobile #12434

Merged
merged 5 commits into from
Dec 3, 2018
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
@@ -0,0 +1,75 @@
/**
* External dependencies
*/
import { TextInput, TouchableWithoutFeedback, View } from 'react-native';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { compose } from '@wordpress/compose';
import { decodeEntities } from '@wordpress/html-entities';
import { withSelect, withDispatch } from '@wordpress/data';

import styles from './style.scss';

export function DefaultBlockAppender( {
isLocked,
isVisible,
onAppend,
placeholder,
} ) {
if ( isLocked || ! isVisible ) {
return null;
}

const value = decodeEntities( placeholder ) || __( 'Start writing or press \u2295 to add content' );

return (
<TouchableWithoutFeedback
onPress={ onAppend }
>
<View style={ styles.blockHolder } pointerEvents="box-only">
<View style={ styles.blockContainer }>
<TextInput
style={ styles.textView }
textAlignVertical="top"
multiline
numberOfLines={ 0 }
value={ value }
/>
</View>
</View>
</TouchableWithoutFeedback>
);
}

export default compose(
withSelect( ( select, ownProps ) => {
const { getBlockCount, getEditorSettings, getTemplateLock } = select( 'core/editor' );

const isEmpty = ! getBlockCount( ownProps.rootClientId );
const { bodyPlaceholder } = getEditorSettings();

return {
isVisible: isEmpty,
isLocked: !! getTemplateLock( ownProps.rootClientId ),
placeholder: bodyPlaceholder,
};
} ),
withDispatch( ( dispatch, ownProps ) => {
const {
insertDefaultBlock,
startTyping,
} = dispatch( 'core/editor' );

return {
onAppend() {
const { rootClientId } = ownProps;

insertDefaultBlock( undefined, rootClientId );
startTyping();
},
};
} ),
)( DefaultBlockAppender );
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

.blockHolder {
flex: 1 1 auto;
}

.blockContainer {
background-color: $white;
padding: 8px;
}

.textView {
color: #87a6bc;
font-size: 16px;
}
1 change: 1 addition & 0 deletions packages/editor/src/components/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export { default as MediaPlaceholder } from './media-placeholder';
export { default as BlockFormatControls } from './block-format-controls';
export { default as BlockControls } from './block-controls';
export { default as BlockEdit } from './block-edit';
export { default as DefaultBlockAppender } from './default-block-appender';
export { default as EditorHistoryRedo } from './editor-history/redo';
export { default as EditorHistoryUndo } from './editor-history/undo';