-
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 Bottom Sheet to set a link (#31343)
* Add separatorType option to LinkSettings footer * Create native EmbedBottomSheet component * Use EmbedBottomSheet in native EmbedPlaceholder * Add onSetAttributes callback to embed bottom sheet When the attributes are modified in the LinkSettingsNavigation component the setAttributes callback is triggered. This callback is called once unlike the onClose callback, which is called multiple times and doesn't guarantee that the attributes are up-to-date at the time is triggered. * Correct isEmbedSheetVisible typo * Use onDismiss callback to notify embed URL value update * Add comment to onChangeURL embed placeholder * Only display the embed sheet on block insertion * Add native version of onSubmit in embed * Prevent onDismiss prop overwriting in bottom sheet I noticed that if a onDismiss prop is passed to the bottom sheet component, the internal function onDismiss is not executed. This behavior looks wrong because this function is intended to actually call the onDismiss prop. * Show only the embed sheet automatically if empty * Fix clipboard case for embed sheet * Omit onDismiss prop from rest object Co-authored-by: Carlos Garcia <[email protected]>
- Loading branch information
Showing
6 changed files
with
156 additions
and
26 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
66 changes: 66 additions & 0 deletions
66
packages/block-library/src/embed/embed-bottom-sheet.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,66 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
LinkSettingsNavigation, | ||
FooterMessageLink, | ||
} from '@wordpress/components'; | ||
import { isURL } from '@wordpress/url'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { store as noticesStore } from '@wordpress/notices'; | ||
import { useCallback, useState } from '@wordpress/element'; | ||
|
||
const linkSettingsOptions = { | ||
url: { | ||
label: __( 'Embed link' ), | ||
placeholder: __( 'Add link' ), | ||
autoFocus: true, | ||
autoFill: true, | ||
}, | ||
footer: { | ||
label: ( | ||
<FooterMessageLink | ||
href={ __( 'https://wordpress.org/support/article/embeds/' ) } | ||
value={ __( 'Learn more about embeds' ) } | ||
/> | ||
), | ||
separatorType: 'topFullWidth', | ||
}, | ||
}; | ||
|
||
const EmbedBottomSheet = ( { value, isVisible, onClose, onSubmit } ) => { | ||
const [ url, setURL ] = useState( value ); | ||
const { createErrorNotice } = useDispatch( noticesStore ); | ||
|
||
const onDismiss = useCallback( () => { | ||
if ( url !== '' && url !== value ) { | ||
if ( isURL( url ) ) { | ||
onSubmit( url ); | ||
} else { | ||
createErrorNotice( | ||
__( 'Invalid URL. Please enter a valid URL.' ) | ||
); | ||
} | ||
} | ||
}, [ url, onSubmit ] ); | ||
|
||
function setAttributes( attributes ) { | ||
setURL( attributes.url ); | ||
} | ||
|
||
return ( | ||
<LinkSettingsNavigation | ||
isVisible={ isVisible } | ||
url={ url } | ||
onClose={ onClose } | ||
onDismiss={ onDismiss } | ||
setAttributes={ setAttributes } | ||
options={ linkSettingsOptions } | ||
withBottomSheet | ||
showIcon | ||
/> | ||
); | ||
}; | ||
|
||
export default EmbedBottomSheet; |
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
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