From 0f08be65e12b1820a87bfa58d8b3b4c10b98339b Mon Sep 17 00:00:00 2001 From: Marko Savic Date: Mon, 4 Feb 2019 15:21:05 +0100 Subject: [PATCH 01/13] Implemented media options sheet --- .../block-library/src/image/edit.native.js | 98 ++++++++++++++----- .../media-placeholder/index.native.js | 25 +++-- .../media-placeholder/styles.native.scss | 1 + 3 files changed, 84 insertions(+), 40 deletions(-) diff --git a/packages/block-library/src/image/edit.native.js b/packages/block-library/src/image/edit.native.js index 985c333e4be401..f4244d288547d2 100644 --- a/packages/block-library/src/image/edit.native.js +++ b/packages/block-library/src/image/edit.native.js @@ -34,6 +34,7 @@ export default class ImageEdit extends React.Component { this.state = { showSettings: false, + showMediaOptions: false, progress: 0, isUploadInProgress: false, isUploadFailed: false, @@ -133,6 +134,7 @@ export default class ImageEdit extends React.Component { const { url, caption, height, width } = attributes; const onMediaLibraryButtonPressed = () => { + this.setState( { showMediaOptions: false } ); requestMediaPickFromMediaLibrary( ( mediaId, mediaUrl ) => { if ( mediaUrl ) { setAttributes( { id: mediaId, url: mediaUrl } ); @@ -140,33 +142,25 @@ export default class ImageEdit extends React.Component { } ); }; - if ( ! url ) { - const onMediaUploadButtonPressed = () => { - requestMediaPickFromDeviceLibrary( ( mediaId, mediaUri ) => { - if ( mediaUri ) { - this.addMediaUploadListener( ); - setAttributes( { url: mediaUri, id: mediaId } ); - } - } ); - }; - - const onMediaCaptureButtonPressed = () => { - requestMediaPickFromDeviceCamera( ( mediaId, mediaUri ) => { - if ( mediaUri ) { - this.addMediaUploadListener( ); - setAttributes( { url: mediaUri, id: mediaId } ); - } - } ); - }; + const onMediaUploadButtonPressed = () => { + this.setState( { showMediaOptions: false } ); + requestMediaPickFromDeviceLibrary( ( mediaId, mediaUri ) => { + if ( mediaUri ) { + this.addMediaUploadListener( ); + setAttributes( { url: mediaUri, id: mediaId } ); + } + } ); + }; - return ( - - ); - } + const onMediaCaptureButtonPressed = () => { + this.setState( { showMediaOptions: false } ); + requestMediaPickFromDeviceCamera( ( mediaId, mediaUri ) => { + if ( mediaUri ) { + this.addMediaUploadListener( ); + setAttributes( { url: mediaUri, id: mediaId } ); + } + } ); + }; const onImageSettingsButtonPressed = () => { this.setState( { showSettings: true } ); @@ -176,12 +170,20 @@ export default class ImageEdit extends React.Component { this.setState( { showSettings: false } ); }; + const onMediaOptionsButtonPressed = () => { + this.setState( { showMediaOptions: true } ); + }; + + const onMediaOptionsClose = () => { + this.setState( { showMediaOptions: false } ); + }; + const toolbarEditButton = ( ); @@ -214,6 +216,47 @@ export default class ImageEdit extends React.Component { ); + const getMediaOptions = () => ( + + + + + + + ); + + if ( ! url) { + return ( + + { getMediaOptions() } + + + ); + } + const showSpinner = this.state.isUploadInProgress; const opacity = this.state.isUploadInProgress ? 0.3 : 1; const progress = this.state.progress * 100; @@ -252,6 +295,7 @@ export default class ImageEdit extends React.Component { return ( { getInspectorControls() } + { getMediaOptions() } - - { __( 'Image' ) } - - - { __( 'Upload a new image or select a file from your library.' ) } - - -