-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] Embed Block caption field (#32226)
* Created an EmbedPreview component to house the caption. * Disabled the placeholder mode temporarily until the linking is enabled. * Update placeholder of embed preview and small refactor * Add dark mode to embed preview placeholder * [TEST] Set always a url attribute in embed block * Add comment as a reminder to remove testing code * Add workaround for embed preview in native * Revert workaround for embed preview in native Co-authored-by: Carlos Garcia <[email protected]>
- Loading branch information
1 parent
829f88e
commit ce5325f
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
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
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,91 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { TouchableWithoutFeedback, Text } from 'react-native'; | ||
import { isEmpty } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { View } from '@wordpress/primitives'; | ||
|
||
import { BlockCaption } from '@wordpress/block-editor'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { useState } from '@wordpress/element'; | ||
import { usePreferredColorSchemeStyle } from '@wordpress/compose'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './styles.scss'; | ||
|
||
const EmbedPreview = ( { | ||
clientId, | ||
insertBlocksAfter, | ||
isSelected, | ||
onBlur, | ||
onFocus, | ||
} ) => { | ||
const [ isCaptionSelected, setIsCaptionSelected ] = useState( false ); | ||
const stylePlaceholder = usePreferredColorSchemeStyle( | ||
styles[ 'embed-preview__placeholder' ], | ||
styles[ 'embed-preview__placeholder--dark' ] | ||
); | ||
const stylePlaceholderText = usePreferredColorSchemeStyle( | ||
styles[ 'embed-preview__placeholder-text' ], | ||
styles[ 'embed-preview__placeholder-text--dark' ] | ||
); | ||
|
||
function accessibilityLabelCreator( caption ) { | ||
return isEmpty( caption ) | ||
? /* translators: accessibility text. Empty Embed caption. */ | ||
__( 'Embed caption. Empty' ) | ||
: sprintf( | ||
/* translators: accessibility text. %s: Embed caption. */ | ||
__( 'Embed caption. %s' ), | ||
caption | ||
); | ||
} | ||
|
||
function onEmbedPreviewPress() { | ||
setIsCaptionSelected( false ); | ||
} | ||
|
||
function onFocusCaption() { | ||
if ( onFocus ) { | ||
onFocus(); | ||
} | ||
if ( ! isCaptionSelected ) { | ||
setIsCaptionSelected( true ); | ||
} | ||
} | ||
|
||
// Currently returning a Text component that act's as the Embed Preview to simulate the caption's isSelected state. | ||
return ( | ||
<TouchableWithoutFeedback | ||
accessible={ ! isSelected } | ||
onPress={ onEmbedPreviewPress } | ||
disabled={ ! isSelected } | ||
> | ||
<View> | ||
<View style={ stylePlaceholder }> | ||
<Text style={ stylePlaceholderText }> | ||
Embed Preview will be directly above the Block Caption | ||
component when it is implemented. | ||
</Text> | ||
</View> | ||
<BlockCaption | ||
accessibilityLabelCreator={ accessibilityLabelCreator } | ||
accessible | ||
clientId={ clientId } | ||
insertBlocksAfter={ insertBlocksAfter } | ||
isSelected={ isCaptionSelected } | ||
onBlur={ onBlur } | ||
onFocus={ onFocusCaption } | ||
/> | ||
</View> | ||
</TouchableWithoutFeedback> | ||
); | ||
}; | ||
|
||
export default EmbedPreview; |
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