-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
packages/editor/src/components/default-block-appender/index.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
14 changes: 14 additions & 0 deletions
14
packages/editor/src/components/default-block-appender/style.native.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters