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: Implemented media options sheet #13656

Merged
merged 24 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0f08be6
Implemented media options sheet
marecar3 Feb 4, 2019
65fbbb7
Fixed lint errors
marecar3 Feb 4, 2019
ab82cd2
Merge branch 'master' into rnmobile/introduce_media_options_sheet
marecar3 Feb 5, 2019
a1294a9
Fixed color error
marecar3 Feb 5, 2019
fe66aa6
Change "Upload Image" label to "Select Image" label
marecar3 Feb 5, 2019
ee79341
Use proper style format
marecar3 Feb 5, 2019
5048cf4
Merge branch 'master' into rnmobile/introduce_media_options_sheet
marecar3 Feb 5, 2019
c215079
Dismiss modal on back pressed
marecar3 Feb 5, 2019
9718879
Restyle action sheet for Android and iOS
marecar3 Feb 5, 2019
7f6e1ac
Execute the callbacks from the bottom sheet with a delay on iOS.
SergioEstevao Feb 6, 2019
7618c03
Merge branch 'master' into rnmobile/introduce_media_options_sheet
SergioEstevao Feb 6, 2019
e15230e
Merge branch 'master' into rnmobile/introduce_media_options_sheet
SergioEstevao Feb 6, 2019
9067b08
Avoid delay for iOS
marecar3 Feb 6, 2019
fcc482f
Revert "Avoid delay for iOS"
marecar3 Feb 6, 2019
c36a904
Merge branch 'master' into rnmobile/introduce_media_options_sheet
marecar3 Feb 6, 2019
b5adc60
Avoid leaking of Modal view
marecar3 Feb 6, 2019
391a82d
Revert "Avoid leaking of Modal view"
marecar3 Feb 6, 2019
ecc150e
Merge branch 'master' into rnmobile/introduce_media_options_sheet
marecar3 Feb 6, 2019
4cadc20
Merge branch 'master' into rnmobile/introduce_media_options_sheet
marecar3 Feb 7, 2019
40744ed
Merge branch 'master' into rnmobile/introduce_media_options_sheet
marecar3 Feb 8, 2019
4dd84e4
Use Picker instead of Bottom Sheet
marecar3 Feb 8, 2019
974c144
Merge branch 'master' into rnmobile/introduce_media_options_sheet
marecar3 Feb 8, 2019
b0acd98
Merge branch 'master' into rnmobile/introduce_media_options_sheet
marecar3 Feb 11, 2019
c81ec3e
Merge branch 'master' into rnmobile/introduce_media_options_sheet
marecar3 Feb 14, 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
97 changes: 68 additions & 29 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
/**
* Internal dependencies
*/
import { MediaPlaceholder, RichText, BlockControls, InspectorControls, BottomSheet } from '@wordpress/editor';
import { MediaPlaceholder, RichText, BlockControls, InspectorControls, BottomSheet, Picker } from '@wordpress/editor';
import { Toolbar, ToolbarButton, Spinner, Dashicon } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import ImageSize from './image-size';
Expand All @@ -34,6 +34,10 @@ const MEDIA_UPLOAD_STATE_SUCCEEDED = 2;
const MEDIA_UPLOAD_STATE_FAILED = 3;
const MEDIA_UPLOAD_STATE_RESET = 4;

const MEDIA_UPLOAD_BOTTOM_SHEET_VALUE_CHOOSE_FROM_DEVICE = 'choose_from_device';
const MEDIA_UPLOAD_BOTTOM_SHEET_VALUE_TAKE_PHOTO = 'take_photo';
const MEDIA_UPLOAD_BOTTOM_SHEET_VALUE_WORD_PRESS_LIBRARY = 'wordpress_media_library';

const LINK_DESTINATION_CUSTOM = 'custom';

class ImageEdit extends React.Component {
Expand Down Expand Up @@ -164,6 +168,14 @@ class ImageEdit extends React.Component {
} ) );
}

getMediaOptionsItems() {
return [
{ icon: 'wordpress-alt', value: MEDIA_UPLOAD_BOTTOM_SHEET_VALUE_CHOOSE_FROM_DEVICE, label: __( 'Choose from device' ) },
{ icon: 'camera', value: MEDIA_UPLOAD_BOTTOM_SHEET_VALUE_TAKE_PHOTO, label: __( 'Take a Photo' ) },
{ icon: 'format-image', value: MEDIA_UPLOAD_BOTTOM_SHEET_VALUE_WORD_PRESS_LIBRARY, label: __( 'WordPress Media Library' ) },
];
}

render() {
const { attributes, isSelected, setAttributes } = this.props;
const { url, caption, height, width, alt, href } = attributes;
Expand All @@ -176,33 +188,23 @@ 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 = () => {
requestMediaPickFromDeviceLibrary( ( mediaId, mediaUri ) => {
if ( mediaUri ) {
this.addMediaUploadListener( );
setAttributes( { url: mediaUri, id: mediaId } );
}
} );
};

return (
<MediaPlaceholder
onUploadMediaPressed={ onMediaUploadButtonPressed }
onMediaLibraryPressed={ onMediaLibraryButtonPressed }
onCapturePhotoPressed={ onMediaCaptureButtonPressed }
/>
);
}
const onMediaCaptureButtonPressed = () => {
requestMediaPickFromDeviceCamera( ( mediaId, mediaUri ) => {
if ( mediaUri ) {
this.addMediaUploadListener( );
setAttributes( { url: mediaUri, id: mediaId } );
}
} );
};

const onImageSettingsButtonPressed = () => {
this.setState( { showSettings: true } );
Expand All @@ -212,12 +214,18 @@ class ImageEdit extends React.Component {
this.setState( { showSettings: false } );
};

let picker;

const onMediaOptionsButtonPressed = () => {
picker.presentPicker();
};

const toolbarEditButton = (
<Toolbar>
<ToolbarButton
label={ __( 'Edit image' ) }
icon="edit"
onClick={ onMediaLibraryButtonPressed }
onClick={ onMediaOptionsButtonPressed }
/>
</Toolbar>
);
Expand All @@ -244,7 +252,7 @@ class ImageEdit extends React.Component {
label={ __( 'Image Size' ) }
value={ 'Large' } // Temporary for UI implementation.
options={ sizeOptions }
onChangeValue={ () => {} } // Temporary for UI implementation.
onChangeValue={ ( ) => { } } // Temporary for UI implementation.
/>
<BottomSheet.Cell
icon={ 'editor-textcolor' }
Expand All @@ -262,6 +270,36 @@ class ImageEdit extends React.Component {
</BottomSheet>
);

const mediaOptions = this.getMediaOptionsItems();

const getMediaOptions = () => (
<Picker
hideCancelButton={ true }
ref={ ( instance ) => picker = instance }
options={ mediaOptions }
onChange={ ( value ) => {
if ( value === MEDIA_UPLOAD_BOTTOM_SHEET_VALUE_CHOOSE_FROM_DEVICE ) {
onMediaUploadButtonPressed();
} else if ( value === MEDIA_UPLOAD_BOTTOM_SHEET_VALUE_TAKE_PHOTO ) {
onMediaCaptureButtonPressed();
} else if ( value === MEDIA_UPLOAD_BOTTOM_SHEET_VALUE_WORD_PRESS_LIBRARY ) {
onMediaLibraryButtonPressed();
}
} }
/>
);

if ( ! url ) {
return (
<View style={ { flex: 1 } } >
{ getMediaOptions() }
<MediaPlaceholder
onMediaOptionsPressed={ onMediaOptionsButtonPressed }
/>
</View>
);
}

const showSpinner = this.state.isUploadInProgress;
const opacity = this.state.isUploadInProgress ? 0.3 : 1;
const progress = this.state.progress * 100;
Expand Down Expand Up @@ -300,6 +338,7 @@ class ImageEdit extends React.Component {
return (
<View style={ { flex: 1 } } >
{ getInspectorControls() }
{ getMediaOptions() }
<ImageBackground
style={ { width: finalWidth, height: finalHeight, opacity } }
resizeMethod="scale"
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/components/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export { default as EditorHistoryRedo } from './editor-history/redo';
export { default as EditorHistoryUndo } from './editor-history/undo';
export { default as InspectorControls } from './inspector-controls';
export { default as BottomSheet } from './mobile/bottom-sheet';
export { default as Picker } from './mobile/picker';
25 changes: 12 additions & 13 deletions packages/editor/src/components/media-placeholder/index.native.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
/**
* External dependencies
*/
import { View, Text, Button } from 'react-native';
import { View, Text, TouchableWithoutFeedback } from 'react-native';

import styles from './styles.scss';

import { __ } from '@wordpress/i18n';
import { Dashicon } from '@wordpress/components';

function MediaPlaceholder( props ) {
return (
<View style={ styles.emptyStateContainer }>
<Text style={ styles.emptyStateTitle }>
{ __( 'Image' ) }
</Text>
<Text style={ styles.emptyStateDescription }>
{ __( 'Upload a new image or select a file from your library.' ) }
</Text>
<View style={ styles.emptyStateButtonsContainer }>
<Button title={ __( 'Device Library' ) } onPress={ props.onUploadMediaPressed } />
<Button title={ __( 'Take photo' ) } onPress={ props.onCapturePhotoPressed } />
<TouchableWithoutFeedback onPress={ props.onMediaOptionsPressed }>
<View style={ styles.emptyStateContainer }>
<Dashicon icon={ 'format-image' } />
<Text style={ styles.emptyStateTitle }>
{ __( 'Image' ) }
</Text>
<Text style={ styles.emptyStateDescription }>
{ __( 'CHOOSE IMAGE' ) }
</Text>
</View>
<Button title={ __( 'Media Library' ) } onPress={ props.onMediaLibraryPressed } />
</View>
</TouchableWithoutFeedback>
);
}

Expand Down
21 changes: 11 additions & 10 deletions packages/editor/src/components/media-placeholder/styles.native.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.emptyStateContainer {
flex: 1;
height: 142;
flex-direction: column;
align-items: center;
justify-content: center;
background-color: #f2f2f2;
padding-left: 12;
padding-right: 12;
Expand All @@ -9,18 +13,15 @@

.emptyStateTitle {
text-align: center;
font-weight: 600;
padding-bottom: 12;
margin-top: 8;
margin-bottom: 10;
font-size: 14;
color: #2e4453;
}

.emptyStateDescription {
text-align: center;
}

.emptyStateButtonsContainer {
margin-top: 15;
margin-bottom: 15;
flex-direction: row;
justify-content: space-evenly;
width: 100%;
color: #0087be;
font-size: 14;
font-weight: 500;
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class BottomSheet extends Component {
backdropTransitionOutTiming={ 500 }
backdropOpacity={ 0.2 }
onBackdropPress={ this.props.onClose }
onBackButtonPress={ this.props.onClose }
onSwipe={ this.props.onClose }
swipeDirection="down"
>
Expand Down
5 changes: 3 additions & 2 deletions packages/editor/src/components/mobile/picker/index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@ export default class Picker extends Component {
<View>
{ this.props.options.map( ( option, index ) =>
<BottomSheet.Cell
icon={ option.icon }
key={ index }
label={ option.label }
onPress={ () => this.onCellPress( option.value ) }
/>
) }
<BottomSheet.Cell
{ ! this.props.hideCancelButton && <BottomSheet.Cell
label={ __( 'Cancel' ) }
onPress={ this.onClose }
drawSeparator={ false }
/>
/> }
</View>
</BottomSheet>
);
Expand Down