Skip to content

Commit

Permalink
[RNMobile] Embed block: Enable replace option (#33253)
Browse files Browse the repository at this point in the history
* Add replace option to native version of embed block

* Add invalid and empty URL cases to replace action
  • Loading branch information
fluiddot authored Jul 7, 2021
1 parent 5052772 commit 2f25d1c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/block-library/src/embed/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ const EmbedEdit = ( props ) => {
invalidateResolution( 'getEmbedPreview', [ url ] );
} }
isSelected={ isSelected }
isEditingURL={ isEditingURL }
/>
</View>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ const EmbedBottomSheet = ( { value, isVisible, onClose, onSubmit } ) => {
createErrorNotice(
__( 'Invalid URL. Please enter a valid URL.' )
);
// If the URL was already defined, we submit it to stop showing the embed placeholder.
if ( value !== '' ) {
onSubmit( value );
}
}
} else if ( value !== '' ) {
// Resets the URL when new value is empty and URL was already defined.
onSubmit( '' );
}
}, [ url, onSubmit ] );
}, [ url, onSubmit, value ] );

function setAttributes( attributes ) {
setURL( attributes.url );
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/embed/embed-placeholder.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import styles from './styles.scss';

const EmbedPlaceholder = ( {
icon,
isEditingURL,
isSelected,
label,
onFocus,
Expand All @@ -39,7 +40,7 @@ const EmbedPlaceholder = ( {
[ clientId ]
);
const [ isEmbedSheetVisible, setIsEmbedSheetVisible ] = useState(
isSelected && wasBlockJustInserted && ! value
isSelected && ( ( wasBlockJustInserted && ! value ) || isEditingURL )
);

const containerStyle = usePreferredColorSchemeStyle(
Expand Down

0 comments on commit 2f25d1c

Please sign in to comment.