Skip to content

Commit 8034516

Browse files
committed
Make a simple version of DefaultBlockAppender for mobile (#12434)
* Make a simple version of DefaultBlockAppender for mobile * Use the same padding used for other blocks in DefaultBlockAppender * Update copy, auto focus and bind keypress * Do not bind key events * Change style of placeholder
1 parent f62f336 commit 8034516

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { TextInput, TouchableWithoutFeedback, View } from 'react-native';
5+
6+
/**
7+
* WordPress dependencies
8+
*/
9+
import { __ } from '@wordpress/i18n';
10+
import { compose } from '@wordpress/compose';
11+
import { decodeEntities } from '@wordpress/html-entities';
12+
import { withSelect, withDispatch } from '@wordpress/data';
13+
14+
import styles from './style.scss';
15+
16+
export function DefaultBlockAppender( {
17+
isLocked,
18+
isVisible,
19+
onAppend,
20+
placeholder,
21+
} ) {
22+
if ( isLocked || ! isVisible ) {
23+
return null;
24+
}
25+
26+
const value = decodeEntities( placeholder ) || __( 'Start writing or press \u2295 to add content' );
27+
28+
return (
29+
<TouchableWithoutFeedback
30+
onPress={ onAppend }
31+
>
32+
<View style={ styles.blockHolder } pointerEvents="box-only">
33+
<View style={ styles.blockContainer }>
34+
<TextInput
35+
style={ styles.textView }
36+
textAlignVertical="top"
37+
multiline
38+
numberOfLines={ 0 }
39+
value={ value }
40+
/>
41+
</View>
42+
</View>
43+
</TouchableWithoutFeedback>
44+
);
45+
}
46+
47+
export default compose(
48+
withSelect( ( select, ownProps ) => {
49+
const { getBlockCount, getEditorSettings, getTemplateLock } = select( 'core/editor' );
50+
51+
const isEmpty = ! getBlockCount( ownProps.rootClientId );
52+
const { bodyPlaceholder } = getEditorSettings();
53+
54+
return {
55+
isVisible: isEmpty,
56+
isLocked: !! getTemplateLock( ownProps.rootClientId ),
57+
placeholder: bodyPlaceholder,
58+
};
59+
} ),
60+
withDispatch( ( dispatch, ownProps ) => {
61+
const {
62+
insertDefaultBlock,
63+
startTyping,
64+
} = dispatch( 'core/editor' );
65+
66+
return {
67+
onAppend() {
68+
const { rootClientId } = ownProps;
69+
70+
insertDefaultBlock( undefined, rootClientId );
71+
startTyping();
72+
},
73+
};
74+
} ),
75+
)( DefaultBlockAppender );
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
.blockHolder {
3+
flex: 1 1 auto;
4+
}
5+
6+
.blockContainer {
7+
background-color: $white;
8+
padding: 8px;
9+
}
10+
11+
.textView {
12+
color: #87a6bc;
13+
font-size: 16px;
14+
}

packages/editor/src/components/index.native.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export { default as MediaPlaceholder } from './media-placeholder';
66
export { default as BlockFormatControls } from './block-format-controls';
77
export { default as BlockControls } from './block-controls';
88
export { default as BlockEdit } from './block-edit';
9+
export { default as DefaultBlockAppender } from './default-block-appender';
910
export { default as EditorHistoryRedo } from './editor-history/redo';
1011
export { default as EditorHistoryUndo } from './editor-history/undo';

0 commit comments

Comments
 (0)