Skip to content

Commit

Permalink
Media upload improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
geriux committed Oct 3, 2019
1 parent f7831cc commit b3c5a6f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ export class MediaUploadProgress extends React.Component {

return (
<View style={ styles.mediaUploadProgress }>
{ showSpinner && <Spinner progress={ progress } /> }
{ showSpinner &&
<View style={ styles.progressBar }>
<Spinner progress={ progress } />
</View>
}
{ coverUrl &&
<ImageSize src={ coverUrl } >
{ ( sizes ) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.mediaUploadProgress {
flex: 1;
}

.progressBar {
background-color: $gray-lighten-30;
}
22 changes: 12 additions & 10 deletions packages/block-library/src/media-text/media-container.native.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { Dimensions, View, ImageBackground, Text, TouchableWithoutFeedback } from 'react-native';
import { Dimensions, View, ImageBackground, Text, TouchableWithoutFeedback, Platform } from 'react-native';
import {
requestMediaImport,
mediaUploadSync,
Expand Down Expand Up @@ -42,7 +42,8 @@ import SvgIconRetry from './icon-retry';
/**
* Constants
*/
const ALLOWED_MEDIA_TYPES = [ MEDIA_TYPE_IMAGE, MEDIA_TYPE_VIDEO ];
// For Android it will only work with the first element of the array (images)
const ALLOWED_MEDIA_TYPES = [ MEDIA_TYPE_IMAGE, ...( Platform.OS === 'ios' ? [ MEDIA_TYPE_VIDEO ] : [] ) ];

// Default Video ratio 16:9
const VIDEO_ASPECT_RATIO = 16 / 9;
Expand All @@ -68,10 +69,10 @@ class MediaContainer extends Component {

if ( mediaId && mediaUrl && ! isURL( mediaUrl ) ) {
if ( mediaUrl.indexOf( 'file:' ) === 0 ) {
requestMediaImport( mediaUrl, ( id, url ) => {
requestMediaImport( mediaUrl, ( id, url, type ) => {
if ( url ) {
onSelectMedia( {
media_type: 'image', // video | image
media_type: type || 'image', // image fallback for android
id,
url,
} );
Expand All @@ -89,11 +90,11 @@ class MediaContainer extends Component {
}

onSelectMediaUploadOption( params ) {
const { id, url } = params;
const { id, url, type } = params;
const { onSelectMedia } = this.props;

onSelectMedia( {
media_type: 'image', // video | image
media_type: type || 'image', // image fallback for android
id,
url,
} );
Expand Down Expand Up @@ -244,10 +245,10 @@ class MediaContainer extends Component {
let mediaElement = null;

switch ( mediaType ) {
case 'image':
case MEDIA_TYPE_IMAGE:
mediaElement = this.renderImage( params, openMediaOptions );
break;
case 'video':
case MEDIA_TYPE_VIDEO:
mediaElement = this.renderVideo( params, openMediaOptions );
break;
}
Expand All @@ -270,7 +271,8 @@ class MediaContainer extends Component {
}

render() {
const { mediaUrl, mediaId } = this.props;
const { mediaUrl, mediaId, mediaType } = this.props;
const coverUrl = mediaType === MEDIA_TYPE_IMAGE ? mediaUrl : null;

if ( mediaUrl ) {
return (
Expand All @@ -284,7 +286,7 @@ class MediaContainer extends Component {
{ this.renderToolbarEditButton( open ) }

<MediaUploadProgress
coverUrl={ mediaUrl }
coverUrl={ coverUrl }
mediaId={ mediaId }
onUpdateMediaProgress={ this.updateMediaProgress }
onFinishMediaUploadWithSuccess={ this.finishMediaUploadWithSuccess }
Expand Down

0 comments on commit b3c5a6f

Please sign in to comment.