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

Mobile gallery draft #18111

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
d27412e
Add simple tiles component for gallery
mkevins Oct 28, 2019
a2bd38f
Refactor tiles to accept props more directly
mkevins Oct 16, 2019
11bd1fd
Add groutSpacing prop to tiles
mkevins Oct 23, 2019
b7175fe
Tiles - WIP - debugging layout issue on orientation change
mkevins Oct 28, 2019
66406bf
Tiles - fix spacing (fence-post issue)
mkevins Oct 28, 2019
28dfef4
Tiles - use width instead of flexBasis to fix rotation glitch
mkevins Oct 28, 2019
ae536e3
Fix lint errors
mkevins Oct 28, 2019
9754371
Add native gallery - gallery image
pinarol Oct 10, 2019
ee3b0eb
WIP - refactor native gallery image
mkevins Oct 25, 2019
018448b
WIP - gallery image - deselect caption when image tapped
mkevins Oct 29, 2019
07ebc54
Add MediaUploadProgress to GalleryImage
mkevins Nov 1, 2019
b24fb08
Extract styles from gallery image
mkevins Nov 4, 2019
843bace
Add failed upload UI to gallery image
mkevins Nov 4, 2019
17499b7
Remove HOC from gallery image
mkevins Nov 4, 2019
b043431
Remove unused props / methods in gallery image
mkevins Nov 4, 2019
5c9c313
Remove gallery image when upload is cancelled
mkevins Nov 4, 2019
f83aa92
Remove unused code from gallery image
mkevins Nov 4, 2019
82ae9d5
Use accessibilityLabel prop on gallery image buttons
mkevins Nov 4, 2019
e779b5b
Remove href code from gallery image
mkevins Nov 4, 2019
1f47a68
Extract remaining styles from gallery image
mkevins Nov 4, 2019
00a195c
Fix lint errors
mkevins Nov 4, 2019
b52d643
Extract gallery.js
pinarol Oct 10, 2019
8aa8a32
Refactor gallery to accept props more directly
mkevins Oct 16, 2019
2190ff6
Use viewport HOC in gallery edit
mkevins Oct 25, 2019
4cb7c7f
Use cross-platform Platform module in gallery edit
mkevins Oct 25, 2019
5cef2f2
WIP - gallery edit - use icon prop with RangeControl
mkevins Oct 29, 2019
4461e72
Fix lint errors
mkevins Oct 29, 2019
b7fe6a7
WIP - add gallery button
mkevins Oct 25, 2019
216c78b
Fix lint errors
mkevins Nov 4, 2019
2907d0a
Add append logic to MediaPlaceholder for gallery
mkevins Oct 25, 2019
d9c9bca
Fix lint errors
mkevins Nov 4, 2019
2a810a5
Rename groutSpacing prop to spacing in gallery tiles
mkevins Nov 5, 2019
f533477
Extract gallery tiles styles to scss
mkevins Nov 5, 2019
b995d5d
Add explanatory comment to gallery tiles for layout logic
mkevins Nov 5, 2019
d44177a
Add native gallery
pinarol Oct 10, 2019
0040899
Add native gallery block behind DEV flag
pinarol Oct 10, 2019
4b756b9
Refactor gallery to accept props more directly
mkevins Oct 16, 2019
a6182f4
Pass isBlockSelected prop to gallery-image
mkevins Oct 25, 2019
a13454a
Pass isCropped prop to gallery-image
mkevins Oct 25, 2019
d4315fd
Limit displayed columns on mobile for gallery
mkevins Oct 25, 2019
f0ca1ce
Fix lint errors
mkevins Oct 29, 2019
cde6846
Use renamed tiles spacing prop in native gallery component
mkevins Nov 5, 2019
8fafcd0
Merge branches 'try/gallery-draft-mediaplaceholder', 'try/gallery-dra…
mkevins Nov 5, 2019
9522e1d
Trigger travis
mkevins Nov 6, 2019
5cdac2b
Remove isString check from gallery button
mkevins Nov 6, 2019
da7e78f
Refactor gallery to accept props more directly
mkevins Nov 6, 2019
1457fa5
Merge branch 'master' into try/gallery-draft-extract-gallery
mkevins Nov 6, 2019
20e7777
Merge branches 'try/gallery-draft-extract-gallery', 'try/gallery-draf…
mkevins Nov 6, 2019
85be21b
[RNMobile] Gallery - Button (#18264)
mkevins Nov 6, 2019
c95d5eb
Merge branch 'master' into try/gallery-draft
mkevins Nov 7, 2019
86b9e55
Fix isCropped style for mobile gallery image
mkevins Nov 7, 2019
14422b6
Merge branch 'try/gallery-draft-gallery-image' into try/gallery-draft
mkevins Nov 7, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { View, Text, TouchableWithoutFeedback } from 'react-native';
import { uniqBy } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -22,6 +23,7 @@ import styles from './styles.scss';

function MediaPlaceholder( props ) {
const {
addToGallery,
allowedTypes = [],
labels = {},
icon,
Expand All @@ -30,8 +32,13 @@ function MediaPlaceholder( props ) {
disableMediaButtons,
getStylesFromColorScheme,
multiple,
value = [],
} = props;

const setMedia = multiple && addToGallery ?
( selected ) => onSelect( uniqBy( [ ...value, ...selected ], 'id' ) ) :
onSelect;

const isOneType = allowedTypes.length === 1;
const isImage = isOneType && allowedTypes.includes( MEDIA_TYPE_IMAGE );
const isVideo = isOneType && allowedTypes.includes( MEDIA_TYPE_VIDEO );
Expand Down Expand Up @@ -103,7 +110,7 @@ function MediaPlaceholder( props ) {
<View style={ { flex: 1 } }>
<MediaUpload
allowedTypes={ allowedTypes }
onSelect={ onSelect }
onSelect={ setMedia }
multiple={ multiple }
render={ ( { open, getMediaOptions } ) => {
return (
Expand Down
86 changes: 24 additions & 62 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import classnames from 'classnames';
import {
every,
filter,
Expand All @@ -26,19 +25,19 @@ import {
BlockIcon,
MediaPlaceholder,
InspectorControls,
RichText,
} from '@wordpress/block-editor';
import { Component } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { Component, Platform } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { getBlobByURL, isBlobURL, revokeBlobURL } from '@wordpress/blob';
import { withSelect } from '@wordpress/data';
import { withViewportMatch } from '@wordpress/viewport';

/**
* Internal dependencies
*/
import GalleryImage from './gallery-image';
import { icon } from './icons';
import { defaultColumnsNumber, pickRelevantMediaFiles } from './shared';
import Gallery from './gallery';

const MAX_COLUMNS = 8;
const linkOptions = [
Expand Down Expand Up @@ -254,12 +253,9 @@ class GalleryEdit extends Component {
className,
isSelected,
noticeUI,
setAttributes,
} = this.props;
const {
align,
columns = defaultColumnsNumber( attributes ),
caption,
imageCrop,
images,
linkTo,
Expand All @@ -268,6 +264,11 @@ class GalleryEdit extends Component {
const hasImages = !! images.length;
const hasImagesWithId = hasImages && some( images, ( { id } ) => id );

const instructions = Platform.select( {
web: __( 'Drag images, upload new ones or select files from your library.' ),
native: __( 'Add media' ),
} );

const mediaPlaceholder = (
<MediaPlaceholder
addToGallery={ hasImagesWithId }
Expand All @@ -277,7 +278,7 @@ class GalleryEdit extends Component {
icon={ ! hasImages && <BlockIcon icon={ icon } /> }
labels={ {
title: ! hasImages && __( 'Gallery' ),
instructions: ! hasImages && __( 'Drag images, upload new ones or select files from your library.' ),
instructions: ! hasImages && instructions,
} }
onSelect={ this.onSelectImages }
accept="image/*"
Expand All @@ -286,25 +287,20 @@ class GalleryEdit extends Component {
value={ hasImagesWithId ? images : undefined }
onError={ this.onUploadError }
notices={ hasImages ? undefined : noticeUI }
onFocus={ this.props.onFocus }
/>
);

if ( ! hasImages ) {
return mediaPlaceholder;
}

const captionClassNames = classnames(
'blocks-gallery-caption',
{
'screen-reader-text': ! isSelected && RichText.isEmpty( caption ),
}
);
return (
<>
<InspectorControls>
<PanelBody title={ __( 'Gallery Settings' ) }>
{ images.length > 1 && <RangeControl
label={ __( 'Columns' ) }
icon={ 'admin-settings' }
value={ columns }
onChange={ this.setColumnsNumber }
min={ 1 }
Expand All @@ -326,52 +322,17 @@ class GalleryEdit extends Component {
</PanelBody>
</InspectorControls>
{ noticeUI }
<figure className={ classnames(
className,
{
[ `align${ align }` ]: align,
[ `columns-${ columns }` ]: columns,
'is-cropped': imageCrop,
}
) }
>
<ul className="blocks-gallery-grid">
{ images.map( ( img, index ) => {
/* translators: %1$d is the order number of the image, %2$d is the total number of images. */
const ariaLabel = sprintf( __( 'image %1$d of %2$d in gallery' ), ( index + 1 ), images.length );

return (
<li className="blocks-gallery-item" key={ img.id || img.url }>
<GalleryImage
url={ img.url }
alt={ img.alt }
id={ img.id }
isFirstItem={ index === 0 }
isLastItem={ ( index + 1 ) === images.length }
isSelected={ isSelected && this.state.selectedImage === index }
onMoveBackward={ this.onMoveBackward( index ) }
onMoveForward={ this.onMoveForward( index ) }
onRemove={ this.onRemoveImage( index ) }
onSelect={ this.onSelectImage( index ) }
setAttributes={ ( attrs ) => this.setImageAttributes( index, attrs ) }
caption={ img.caption }
aria-label={ ariaLabel }
/>
</li>
);
} ) }
</ul>
{ mediaPlaceholder }
<RichText
tagName="figcaption"
className={ captionClassNames }
placeholder={ __( 'Write gallery caption…' ) }
value={ caption }
unstableOnFocus={ this.onFocusGalleryCaption }
onChange={ ( value ) => setAttributes( { caption: value } ) }
inlineToolbar
/>
</figure>
<Gallery
{ ...this.props }
selectedImage={ this.state.selectedImage }
mediaPlaceholder={ mediaPlaceholder }
onMoveBackward={ this.onMoveBackward }
onMoveForward={ this.onMoveForward }
onRemoveImage={ this.onRemoveImage }
onSelectImage={ this.onSelectImage }
onSetImageAttributes={ this.setImageAttributes }
onFocusGalleryCaption={ this.onFocusGalleryCaption }
/>
</>
);
}
Expand All @@ -383,4 +344,5 @@ export default compose( [
return { mediaUpload };
} ),
withNotices,
withViewportMatch( { isMobile: '< small' } ),
] )( GalleryEdit );
55 changes: 55 additions & 0 deletions packages/block-library/src/gallery/gallery-button.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* External dependencies
*/
import { StyleSheet, TouchableOpacity, View } from 'react-native';

/**
* WordPress dependencies
*/
import { Icon } from '@wordpress/components';

const styles = StyleSheet.create( {
buttonActive: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
borderRadius: 6,
borderColor: '#2e4453',
backgroundColor: '#2e4453',
aspectRatio: 1,
},
} );

export function Button( props ) {
const {
icon,
onClick,
disabled,
'aria-disabled': ariaDisabled,
accessibilityLabel = 'button',
style,
} = props;

const buttonStyle = StyleSheet.compose( styles.buttonActive, style );

const isDisabled = disabled || ariaDisabled;

const fill = isDisabled ? 'gray' : 'white';

return (
<TouchableOpacity
activeOpacity={ 0.7 }
accessible={ true }
accessibilityLabel={ accessibilityLabel }
accessibilityRole={ 'button' }
onPress={ onClick }
disabled={ isDisabled }
>
<View style={ buttonStyle }>
<Icon icon={ icon } fill={ fill } size={ 24 } />
</View>
</TouchableOpacity>
);
}

export default Button;
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
.container {
flex: 1;
height: 150px;
}

.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;
padding: 5px;
border-width: 3px;
border-color: #00000000;
}

.overlaySelected {
border-color: #0070ff;
}

.button {
width: 30px;
}

.moverButtons {
flex-direction: row;
align-items: center;
border-radius: 3px;
background-color: #2e4453;
}

.separator {
border-right-color: gray;
// border-right-width: StyleSheet.hairlineWidth;
border-right-width: 1px;
height: 20px;
}

.removeButton {
width: 30px;
border-radius: 30px;
}

.toolbar {
flex-direction: row;
justify-content: space-between;
}

.caption {
position: absolute;
bottom: 0;
left: 0;
right: 0;
}

.uploadFailedContainer {
position: absolute;
background-color: rgba(0, 0, 0, 0.5);
width: 100%;
height: 100%;
justify-content: center;
align-items: center;
}

.uploadFailed {
width: 24px;
height: 24px;
justify-content: center;
align-items: center;
}

.uploadFailedIcon {
fill: #fff;
width: 100%;
height: 100%;
}

.uploadFailedText {
color: #fff;
font-size: 14px;
margin-top: 5px;
}
Loading