diff --git a/packages/block-library/src/audio/edit.native.js b/packages/block-library/src/audio/edit.native.js index d8ee2f45f8b654..3e66485f936991 100644 --- a/packages/block-library/src/audio/edit.native.js +++ b/packages/block-library/src/audio/edit.native.js @@ -1,7 +1,8 @@ /** * External dependencies */ -import { Text } from 'react-native'; +import { Text, TouchableWithoutFeedback } from 'react-native'; +import { isEmpty } from 'lodash'; /** * WordPress dependencies @@ -16,17 +17,17 @@ import { ToolbarGroup, } from '@wordpress/components'; import { + BlockCaption, BlockControls, BlockIcon, InspectorControls, MediaPlaceholder, MediaUpload, MediaUploadProgress, - RichText, } from '@wordpress/block-editor'; -import { __ } from '@wordpress/i18n'; +import { __, sprintf } from '@wordpress/i18n'; import { audio as icon, replace } from '@wordpress/icons'; -import { createBlock } from '@wordpress/blocks'; +import { useState } from '@wordpress/element'; const ALLOWED_MEDIA_TYPES = [ 'audio' ]; @@ -38,8 +39,12 @@ function AudioEdit( { noticeUI, insertBlocksAfter, onFocus, + onBlur, + clientId, } ) { - const { id, autoplay, caption, loop, preload, src } = attributes; + const { id, autoplay, loop, preload, src } = attributes; + + const [ isCaptionSelected, setIsCaptionSelected ] = useState( false ); const onFileChange = ( { mediaId, mediaUrl } ) => { setAttributes( { id: mediaId, src: mediaUrl } ); @@ -78,6 +83,16 @@ function AudioEdit( { setAttributes( { src: media.url, id: media.id } ); } + function onAudioPress() { + setIsCaptionSelected( false ); + } + + function onFocusCaption() { + if ( ! isCaptionSelected ) { + setIsCaptionSelected( true ); + } + } + if ( ! src ) { return ( @@ -121,30 +136,13 @@ function AudioEdit( { renderContent={ ( { isUploadInProgress, isUploadFailed } ) => { return ( - { getBlockControls( open ) } + { ! isCaptionSelected && getBlockControls( open ) } { getMediaOptions() } ⏯ Audio Player goes here.{ ' ' } { isUploadInProgress && 'Uploading...' } { isUploadFailed && 'ERROR' } - { ( ! RichText.isEmpty( caption ) || - isSelected ) && ( - - setAttributes( { caption: value } ) - } - inlineToolbar - __unstableOnSplitAtEnd={ () => - insertBlocksAfter( - createBlock( 'core/paragraph' ) - ) - } - /> - ) } ); } } @@ -153,46 +151,70 @@ function AudioEdit( { } return ( - <> - - - - - - setAttributes( { - preload: value || undefined, - } ) - } - options={ [ - { value: '', label: __( 'Browser default' ) }, - { value: 'auto', label: __( 'Auto' ) }, - { value: 'metadata', label: __( 'Metadata' ) }, - { value: 'none', label: __( 'None' ) }, - ] } - /> - - - { - return getBlockUI( open, getMediaOptions ); - } } - /> - + + + + + + + + setAttributes( { + preload: value || undefined, + } ) + } + options={ [ + { value: '', label: __( 'Browser default' ) }, + { value: 'auto', label: __( 'Auto' ) }, + { value: 'metadata', label: __( 'Metadata' ) }, + { value: 'none', label: __( 'None' ) }, + ] } + /> + + + { + return getBlockUI( open, getMediaOptions ); + } } + /> + + isEmpty( caption ) + ? /* translators: accessibility text. Empty Audio caption. */ + __( 'Audio caption. Empty' ) + : sprintf( + /* translators: accessibility text. %s: Audio caption. */ + __( 'Audio caption. %s' ), + caption + ) + } + clientId={ clientId } + isSelected={ isCaptionSelected } + onFocus={ onFocusCaption } + onBlur={ onBlur } + insertBlocksAfter={ insertBlocksAfter } + /> + + ); } export default withNotices( AudioEdit );