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] Audio block I - x-platform audio block test #27372

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export {
default as MediaUpload,
MEDIA_TYPE_IMAGE,
MEDIA_TYPE_VIDEO,
MEDIA_TYPE_AUDIO,
MEDIA_TYPE_ANY,
} from './media-upload';
export { default as MediaUploadProgress } from './media-upload-progress';
Expand All @@ -37,6 +38,7 @@ export { default as Caption } from './caption';
export { default as PanelColorSettings } from './panel-color-settings';
export { default as __experimentalPanelColorGradientSettings } from './colors-gradients/panel-color-gradient-settings';
export { default as __experimentalUseEditorFeature } from './use-editor-feature';
export { default as MediaReplaceFlow } from './media-replace-flow';

export {
BottomSheetSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
MediaUpload,
MEDIA_TYPE_IMAGE,
MEDIA_TYPE_VIDEO,
MEDIA_TYPE_AUDIO,
} from '@wordpress/block-editor';
import { withPreferredColorScheme } from '@wordpress/compose';
import { useRef } from '@wordpress/element';
Expand Down Expand Up @@ -65,6 +66,7 @@ function MediaPlaceholder( props ) {
const isOneType = allowedTypes.length === 1;
const isImage = isOneType && allowedTypes.includes( MEDIA_TYPE_IMAGE );
const isVideo = isOneType && allowedTypes.includes( MEDIA_TYPE_VIDEO );
const isAudio = isOneType && allowedTypes.includes( MEDIA_TYPE_AUDIO );

let placeholderTitle = labels.title;
if ( placeholderTitle === undefined ) {
Expand All @@ -73,6 +75,8 @@ function MediaPlaceholder( props ) {
placeholderTitle = __( 'Image' );
} else if ( isVideo ) {
placeholderTitle = __( 'Video' );
} else if ( isAudio ) {
placeholderTitle = __( 'Audio' );
}
}

Expand All @@ -82,6 +86,8 @@ function MediaPlaceholder( props ) {
instructions = __( 'ADD IMAGE' );
} else if ( isVideo ) {
instructions = __( 'ADD VIDEO' );
} else if ( isAudio ) {
instructions = __( 'ADD AUDIO' );
} else {
instructions = __( 'ADD IMAGE OR VIDEO' );
}
Expand All @@ -92,6 +98,8 @@ function MediaPlaceholder( props ) {
accessibilityHint = __( 'Double tap to select an image' );
} else if ( isVideo ) {
accessibilityHint = __( 'Double tap to select a video' );
} else if ( isAudio ) {
accessibilityHint = __( 'Double tap to select aa audio file' );
}

const emptyStateTitleStyle = getStylesFromColorScheme(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { ToolbarGroup, ToolbarButton } from '@wordpress/components';
import { replace } from '@wordpress/icons';

const MediaReplaceFlow = () => {
return (
<ToolbarGroup>
<ToolbarButton
title={ __( 'Edit audio' ) }
icon={ replace }
onClick={ () => {} }
/>
</ToolbarGroup>
);
};

export default MediaReplaceFlow;
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {

export const MEDIA_TYPE_IMAGE = 'image';
export const MEDIA_TYPE_VIDEO = 'video';
export const MEDIA_TYPE_AUDIO = 'audio';
export const MEDIA_TYPE_ANY = 'any';

export const OPTION_TAKE_VIDEO = __( 'Take a Video' );
Expand Down Expand Up @@ -166,6 +167,7 @@ export class MediaUpload extends React.Component {
const isOneType = allowedTypes.length === 1;
const isImage = isOneType && allowedTypes.includes( MEDIA_TYPE_IMAGE );
const isVideo = isOneType && allowedTypes.includes( MEDIA_TYPE_VIDEO );
const isAudio = isOneType && allowedTypes.includes( MEDIA_TYPE_AUDIO );
const isAnyType = isOneType && allowedTypes.includes( MEDIA_TYPE_ANY );

const isImageOrVideo =
Expand Down Expand Up @@ -194,8 +196,18 @@ export class MediaUpload extends React.Component {
} else {
pickerTitle = __( 'Choose image or video' );
}
} else if ( isAudio ) {
if ( isReplacingMedia ) {
pickerTitle = __( 'Replace audio' );
} else {
pickerTitle = __( 'Choose audio' );
}
} else if ( isAnyType ) {
pickerTitle = __( 'Choose file' );
if ( isReplacingMedia ) {
pickerTitle = __( 'Replace file' );
} else {
pickerTitle = __( 'Choose file' );
}
}

const getMediaOptions = () => (
Expand Down
16 changes: 16 additions & 0 deletions packages/block-library/src/audio/audio-player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* WordPress dependencies
*/
import { Disabled } from '@wordpress/components';

export function AudioPlayer( { src } ) {
/*
Disable the audio tag so the user clicking on it won't play the
file or change the position slider when the controls are enabled.
*/
return (
<Disabled>
<audio controls="controls" src={ src } />
</Disabled>
);
}
8 changes: 8 additions & 0 deletions packages/block-library/src/audio/audio-player.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* External dependencies
*/
import { Text } from 'react-native';

export function AudioPlayer() {
return <Text>Audio Player goes here</Text>;
}
23 changes: 10 additions & 13 deletions packages/block-library/src/audio/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* WordPress dependencies
*/
import { getBlobByURL, isBlobURL } from '@wordpress/blob';
import { View, Figure } from '@wordpress/primitives';
import {
Disabled,
PanelBody,
SelectControl,
ToggleControl,
Expand All @@ -28,17 +28,19 @@ import { createBlock } from '@wordpress/blocks';
* Internal dependencies
*/
import { createUpgradedEmbedBlock } from '../embed/util';
import { AudioPlayer } from './audio-player';

const ALLOWED_MEDIA_TYPES = [ 'audio' ];

function AudioEdit( {
export function AudioEdit( {
attributes,
noticeOperations,
setAttributes,
onReplace,
isSelected,
noticeUI,
insertBlocksAfter,
onFocus,
} ) {
const { id, autoplay, caption, loop, preload, src } = attributes;
const blockProps = useBlockProps();
Expand Down Expand Up @@ -116,7 +118,7 @@ function AudioEdit( {
}
if ( ! src ) {
return (
<div { ...blockProps }>
<View { ...blockProps }>
<MediaPlaceholder
icon={ <BlockIcon icon={ icon } /> }
onSelect={ onSelectAudio }
Expand All @@ -126,8 +128,9 @@ function AudioEdit( {
value={ attributes }
notices={ noticeUI }
onError={ onUploadError }
onFocus={ onFocus }
/>
</div>
</View>
);
}

Expand Down Expand Up @@ -175,14 +178,8 @@ function AudioEdit( {
/>
</PanelBody>
</InspectorControls>
<figure { ...blockProps }>
{ /*
Disable the audio tag so the user clicking on it won't play the
file or change the position slider when the controls are enabled.
*/ }
<Disabled>
<audio controls="controls" src={ src } />
</Disabled>
<Figure { ...blockProps }>
<AudioPlayer src={ src } />
{ ( ! RichText.isEmpty( caption ) || isSelected ) && (
<RichText
tagName="figcaption"
Expand All @@ -197,7 +194,7 @@ function AudioEdit( {
}
/>
) }
</figure>
</Figure>
</>
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export const registerCoreBlocks = () => {
socialLinks,
pullquote,
devOnly( file ),
devOnly( audio ),
].forEach( registerBlock );

registerBlockVariations( socialLink );
Expand Down
1 change: 1 addition & 0 deletions packages/primitives/src/figure/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const Figure = 'figure';
4 changes: 4 additions & 0 deletions packages/primitives/src/figure/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* External dependencies
*/
export { View as Figure } from 'react-native';
1 change: 1 addition & 0 deletions packages/primitives/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './svg';
export * from './horizontal-rule';
export * from './block-quotation';
export * from './view';
export * from './figure';