diff --git a/packages/block-library/src/gallery/gallery-image-style.native.scss b/packages/block-library/src/gallery/gallery-image-style.native.scss index 765f6c4918544d..50fd10dc1ebf73 100644 --- a/packages/block-library/src/gallery/gallery-image-style.native.scss +++ b/packages/block-library/src/gallery/gallery-image-style.native.scss @@ -1,11 +1,11 @@ $gallery-image-container-height: 150px; -$overlay-border-width: 3px; +$overlay-border-width: 2px; $caption-background-color: rgba(0, 0, 0, 0.4); -$caption-padding-vertical: 8px; .galleryImageContainer { flex: 1; height: $gallery-image-container-height; + overflow: hidden; background-color: $gray-lighten-30; } @@ -14,30 +14,7 @@ $caption-padding-vertical: 8px; } .image { - position: absolute; - top: 0; - bottom: 0; - left: 0; - right: 0; - opacity: 1; -} - -.imageUploading { - opacity: 0.3; -} - -.overlay { - position: absolute; - top: 0; - bottom: 0; - left: 0; - right: 0; - border-width: $overlay-border-width; - border-color: #0000; -} - -.overlaySelected { - border-color: $blue-wordpress; + height: 100%; } .button { @@ -67,14 +44,12 @@ $caption-padding-vertical: 8px; .separator { border-right-color: $gray-30; - // border-right-width: StyleSheet.hairlineWidth; border-right-width: 1px; height: 20px; } -.removeButton { - width: 30px; - border-radius: 30px; +.toolbarContainer { + position: absolute; } .toolbar { @@ -115,6 +90,11 @@ $caption-padding-vertical: 8px; flex: 1; flex-direction: row; align-items: flex-end; + position: absolute; + bottom: $overlay-border-width; + left: $overlay-border-width; + right: $overlay-border-width; + top: 45; } @mixin caption-shared { @@ -128,30 +108,24 @@ $caption-padding-vertical: 8px; .caption { @include caption-shared; background-color: $caption-background-color; - padding-top: $caption-padding-vertical; - padding-bottom: $caption-padding-vertical; + padding-top: $grid-unit; + padding-bottom: $grid-unit; } .captionPlaceholder { color: #ccc; } -/* -.captionDark { - background-color: #0007; -} -*/ - // expand caption container to compensate for overlay border .captionExpandedContainer { // constrain height to gallery image height for caption scroll max-height: $gallery-image-container-height; position: absolute; - bottom: - $overlay-border-width; - left: - $overlay-border-width; - right: - $overlay-border-width; - padding-top: $caption-padding-vertical; - padding-bottom: $overlay-border-width + $caption-padding-vertical; + bottom: 0; + left: 0; + right: 0; + padding-top: $grid-unit; + padding-bottom: $overlay-border-width + $grid-unit; padding-left: $overlay-border-width; padding-right: $overlay-border-width; // use caption background color on container when expanded diff --git a/packages/block-library/src/gallery/gallery-image.native.js b/packages/block-library/src/gallery/gallery-image.native.js index d34362efd5e68e..1670e1e81a7d87 100644 --- a/packages/block-library/src/gallery/gallery-image.native.js +++ b/packages/block-library/src/gallery/gallery-image.native.js @@ -2,7 +2,6 @@ * External dependencies */ import { - Image, StyleSheet, View, ScrollView, @@ -17,14 +16,15 @@ import { isEmpty } from 'lodash'; import { requestImageFailedRetryDialog, requestImageUploadCancelDialog, + requestImageFullscreenPreview, } from '@wordpress/react-native-bridge'; import { Component } from '@wordpress/element'; -import { Icon } from '@wordpress/components'; +import { Icon, Image } from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; import { Caption, MediaUploadProgress } from '@wordpress/block-editor'; import { getProtocol } from '@wordpress/url'; import { withPreferredColorScheme } from '@wordpress/compose'; -import { close, arrowLeft, arrowRight } from '@wordpress/icons'; +import { arrowLeft, arrowRight } from '@wordpress/icons'; /** * Internal dependencies @@ -38,9 +38,7 @@ const separatorStyle = compose( style.separator, { borderRightWidth: StyleSheet.hairlineWidth, } ); const buttonStyle = compose( style.button, { aspectRatio: 1 } ); -const removeButtonStyle = compose( style.removeButton, { aspectRatio: 1 } ); const ICON_SIZE_ARROW = 15; -const ICON_SIZE_REMOVE = 20; class GalleryImage extends Component { constructor() { @@ -50,7 +48,7 @@ class GalleryImage extends Component { this.onSelectCaption = this.onSelectCaption.bind( this ); this.onMediaPressed = this.onMediaPressed.bind( this ); this.onCaptionChange = this.onCaptionChange.bind( this ); - this.bindContainer = this.bindContainer.bind( this ); + this.onSelectMedia = this.onSelectMedia.bind( this ); this.updateMediaProgress = this.updateMediaProgress.bind( this ); this.finishMediaUploadWithSuccess = this.finishMediaUploadWithSuccess.bind( @@ -68,10 +66,6 @@ class GalleryImage extends Component { }; } - bindContainer( ref ) { - this.container = ref; - } - onSelectCaption() { if ( ! this.state.captionSelected ) { this.setState( { @@ -85,17 +79,24 @@ class GalleryImage extends Component { } onMediaPressed() { - const { id, url } = this.props; + const { id, url, isSelected } = this.props; + const { + captionSelected, + isUploadInProgress, + didUploadFail, + } = this.state; this.onSelectImage(); - if ( this.state.isUploadInProgress ) { + if ( isUploadInProgress ) { requestImageUploadCancelDialog( id ); } else if ( - this.state.didUploadFail || + didUploadFail || ( id && getProtocol( url ) === 'file:' ) ) { requestImageFailedRetryDialog( id ); + } else if ( isSelected && ! captionSelected ) { + requestImageFullscreenPreview( url ); } } @@ -115,6 +116,11 @@ class GalleryImage extends Component { } } + onSelectMedia( media ) { + const { setAttributes } = this.props; + setAttributes( media ); + } + onCaptionChange( caption ) { const { setAttributes } = this.props; setAttributes( { caption } ); @@ -187,17 +193,6 @@ class GalleryImage extends Component { const { isUploadFailed, retryMessage } = params; const resizeMode = isCropped ? 'cover' : 'contain'; - const imageStyle = [ - style.image, - { resizeMode }, - isUploadInProgress ? style.imageUploading : undefined, - ]; - - const overlayStyle = compose( - style.overlay, - isSelected ? style.overlaySelected : undefined - ); - const captionPlaceholderStyle = getStylesFromColorScheme( style.captionPlaceholder, style.captionPlaceholderDark @@ -213,17 +208,33 @@ class GalleryImage extends Component { const captionStyle = shouldShowCaptionExpanded ? style.captionExpanded - : getStylesFromColorScheme( style.caption, style.captionDark ); + : style.caption; + + const mediaPickerOptions = [ + { + destructiveButton: true, + id: 'removeImage', + label: __( 'Remove' ), + onPress: onRemove, + separated: true, + value: 'removeImage', + }, + ]; return ( <> { + { isUploadFailed && ( @@ -237,89 +248,71 @@ class GalleryImage extends Component { ) } - - { ! isUploadInProgress && ( - <> - { isSelected && ( - - -