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

[RNMobile] Embed Block caption field #32226

Merged
merged 11 commits into from
Jul 2, 2021
3 changes: 3 additions & 0 deletions packages/block-library/src/embed/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const EmbedEdit = ( props ) => {
setAttributes,
insertBlocksAfter,
onFocus,
clientId,
} = props;

const defaultEmbedInfo = {
Expand Down Expand Up @@ -214,6 +215,7 @@ const EmbedEdit = ( props ) => {

// No preview, or we can't embed the current URL, or we've clicked the edit button.
const showEmbedPlaceholder = ! preview || cannotEmbed || isEditingURL;

if ( showEmbedPlaceholder ) {
return (
<View { ...blockProps }>
Expand Down Expand Up @@ -279,6 +281,7 @@ const EmbedEdit = ( props ) => {
icon={ icon }
label={ label }
insertBlocksAfter={ insertBlocksAfter }
clientId={ clientId }
hypest marked this conversation as resolved.
Show resolved Hide resolved
/>
</View>
</>
Expand Down
91 changes: 91 additions & 0 deletions packages/block-library/src/embed/embed-preview.native.js
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;
23 changes: 23 additions & 0 deletions packages/block-library/src/embed/styles.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,26 @@
align-items: center;
fill: $gray-dark;
}

.embed-preview__placeholder {
flex: 1;
padding-left: 12px;
padding-right: 12px;
padding-top: 40px;
padding-bottom: 40px;
background-color: $gray-lighten-30;
}

.embed-preview__placeholder--dark {
background-color: $gray-darken-30;
}

.embed-preview__placeholder-text {
font-size: $default-font-size;
text-align: center;
color: $light-primary;
}

.embed-preview__placeholder-text--dark {
color: $dark-primary;
}