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

Rnmobile/upload media file #13128

Merged
merged 56 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
49bb394
temporarily disable link formatting
mzorz Dec 20, 2018
96a73c5
Make sure RichText resigns focus when unmounted (#13048)
koke Dec 20, 2018
93057b2
Implemented react native spinner
marecar3 Dec 28, 2018
0a0764e
Add upload button in media placeholder
marecar3 Dec 28, 2018
1876d22
Transform ImageEdit from function to class
marecar3 Dec 28, 2018
8a363f9
Fixed lint issues
marecar3 Dec 28, 2018
db23d43
Fixed lint errors
marecar3 Dec 28, 2018
ff11770
Put some space between components in media-placeholder
marecar3 Dec 28, 2018
704b755
Rename state constants to match style convention
marecar3 Dec 28, 2018
e2b08e1
Implements a native version of post-title.
diegoreymendez Jan 4, 2019
40b7c9c
Merge branch 'master' into mobileissue/372-add-title-to-gutenberg-mobile
diegoreymendez Jan 4, 2019
d5910a8
Removes some unnecessary log calls.
diegoreymendez Jan 4, 2019
08108a0
Merge branch 'master' into rnmobile/372-add-title-to-gutenberg-mobile
diegoreymendez Jan 10, 2019
047f1d8
Submits a few lint fixes.
diegoreymendez Jan 10, 2019
4f55ba9
Fixes a linting issue.
diegoreymendez Jan 10, 2019
7b823ec
Merge branch 'master' into rnmobile/upload_media_file
marecar3 Jan 16, 2019
e5d8d3f
Rename callback methods to follow naming convention
marecar3 Jan 16, 2019
2668862
Updated spinner to match the specs
marecar3 Jan 16, 2019
408cb1e
Moved placeholder string to localization format
marecar3 Jan 16, 2019
50c9a12
Merge branch 'master' into rnmobile/upload_media_file
marecar3 Jan 16, 2019
d840e30
Added isURL method to check if passed url is local or web url
marecar3 Jan 16, 2019
5f2889f
Removed duplicated code
marecar3 Jan 16, 2019
21920fd
Add missing attributes
marecar3 Jan 16, 2019
4f4d5f6
Merge branch 'master' into rnmobile/upload_media_file
marecar3 Jan 16, 2019
876b445
Revert missing opacity
marecar3 Jan 16, 2019
d436e9b
Merge branch 'master' into rnmobile/upload_media_file
marecar3 Jan 16, 2019
4c27638
When focusing the title, any focused block loses its focus.
diegoreymendez Jan 16, 2019
0ab5a1b
FocusOut is now wired for post-title for mobile.
diegoreymendez Jan 16, 2019
1f9c722
Removes unused some code.
diegoreymendez Jan 16, 2019
e54d5b9
Added a file I failed to commit.
diegoreymendez Jan 16, 2019
e2cb5c9
Revert media upload event to be non dynamic
marecar3 Jan 17, 2019
046213a
Merge branch 'master' into rnmobile/upload_media_file
marecar3 Jan 17, 2019
7f05b9c
Fixes a linting issue.
diegoreymendez Jan 17, 2019
b94bede
Merge branch 'master' into rnmobile/372-add-title-to-gutenberg-mobile
diegoreymendez Jan 17, 2019
77a1fbe
Make sure that we are receiving events for current media image
marecar3 Jan 17, 2019
8264c52
Renamed constants to follow naming convention
marecar3 Jan 17, 2019
c2a8cf5
Wrap RNReactNativeGutenbergBridge calls inside react-native-gutenberg…
marecar3 Jan 17, 2019
2e7267b
Merge branch 'master' into rnmobile/upload_media_file
marecar3 Jan 17, 2019
08f5cc2
Add state isUploadInProgress instead of checking isUrl is valid
marecar3 Jan 17, 2019
9b2f540
Removed private variable so that can pass
marecar3 Jan 18, 2019
f3b9607
Merge branch 'master' into rnmobile/upload_media_file
marecar3 Jan 18, 2019
5814a4c
Fixed lint tests
marecar3 Jan 18, 2019
e0d5d9b
Merge branch 'master' into rnmobile/upload_media_file
marecar3 Jan 18, 2019
a5a200b
Start listen for progress media upload if it's didn't finish
marecar3 Jan 18, 2019
c9d7b9f
Merge branch 'master' into rnmobile/upload_media_file
marecar3 Jan 18, 2019
9ea8f39
Merge branch 'master' into rnmobile/upload_media_file
marecar3 Jan 21, 2019
b822344
Merge branch 'master' into rnmobile/upload_media_file
marecar3 Jan 22, 2019
e4bf38e
Merge branch 'master' into rnmobile/upload_media_file
marecar3 Jan 23, 2019
6129033
RN Mobile - Upload media file ios (#13421)
SergioEstevao Jan 23, 2019
b5e679b
Merge branch 'master' of https://github.com/WordPress/gutenberg into …
daniloercoli Jan 24, 2019
74aeb23
Merge branch 'rnmobile/372-add-title-to-gutenberg-mobile' into rnmobi…
SergioEstevao Jan 24, 2019
345d356
Merge branch 'master' into rnmobile/upload_media_file
marecar3 Jan 25, 2019
9fecd69
Fix lint errors.
SergioEstevao Jan 25, 2019
028ab55
Rnmobile/upload captured photo (#13450)
marecar3 Jan 25, 2019
93e6e95
using onImageQueryReattach (#13516)
mzorz Jan 28, 2019
2fc48c9
Merge branch 'master' into rnmobile/upload_media_file
marecar3 Jan 28, 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
163 changes: 129 additions & 34 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,165 @@
/**
* External dependencies
*/
import React from 'react';
import { View, Image, TextInput } from 'react-native';
import RNReactNativeGutenbergBridge from 'react-native-gutenberg-bridge';
import {
subscribeMediaUpload,
onMediaLibraryPressed,
onUploadMediaPressed,
onCapturePhotoPressed,
} from 'react-native-gutenberg-bridge';

/**
* Internal dependencies
*/
import { MediaPlaceholder, RichText, BlockControls } from '@wordpress/editor';
import { Toolbar, ToolbarButton } from '@wordpress/components';
import { Component } from '@wordpress/element';
import { Toolbar, ToolbarButton, Spinner } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import ImageSize from './image-size';
import { isURL } from '@wordpress/url';

class ImageEdit extends Component {
constructor() {
super( ...arguments );
this.onMediaLibraryPress = this.onMediaLibraryPress.bind( this );
const MEDIA_ULOAD_STATE_UPLOADING = 1;
const MEDIA_ULOAD_STATE_SUCCEEDED = 2;
const MEDIA_ULOAD_STATE_FAILED = 3;

export default class ImageEdit extends React.Component {
constructor( props ) {
super( props );

this.state = {
progress: 0,
isUploadInProgress: false,
};

this.mediaUpload = this.mediaUpload.bind( this );
this.addMediaUploadListener = this.addMediaUploadListener.bind( this );
this.removeMediaUploadListener = this.removeMediaUploadListener.bind( this );
this.finishMediaUploadWithSuccess = this.finishMediaUploadWithSuccess.bind( this );
this.finishMediaUploadWithFailure = this.finishMediaUploadWithFailure.bind( this );
}

componentDidMount() {
const { attributes } = this.props;

if ( attributes.id && ! isURL( attributes.url ) ) {
this.addMediaUploadListener();
}
}

componentWillUnmount() {
this.removeMediaUploadListener();
}

mediaUpload( payload ) {
const { attributes } = this.props;

if ( payload.mediaId !== attributes.id ) {
return;
}

switch ( payload.state ) {
case MEDIA_ULOAD_STATE_UPLOADING:
this.setState( { progress: payload.progress, isUploadInProgress: true } );
break;
case MEDIA_ULOAD_STATE_SUCCEEDED:
this.finishMediaUploadWithSuccess( payload );
break;
case MEDIA_ULOAD_STATE_FAILED:
this.finishMediaUploadWithFailure( payload );
break;
}
SergioEstevao marked this conversation as resolved.
Show resolved Hide resolved
}

onUploadPress() {
// This method should present an image picker from
// the device.
//TODO: Implement upload image method.
finishMediaUploadWithSuccess( payload ) {
const { setAttributes } = this.props;

setAttributes( { url: payload.mediaUrl, id: payload.mediaServerId } );
this.setState( { isUploadInProgress: false } );

this.removeMediaUploadListener();
}

onMediaLibraryPress() {
RNReactNativeGutenbergBridge.onMediaLibraryPress( ( mediaUrl ) => {
if ( mediaUrl ) {
this.props.setAttributes( { url: mediaUrl } );
}
finishMediaUploadWithFailure( payload ) {
const { setAttributes } = this.props;

setAttributes( { url: payload.mediaUrl, id: payload.mediaId } );
this.setState( { isUploadInProgress: false } );

this.removeMediaUploadListener();
}

addMediaUploadListener() {
this.subscriptionParentMediaUpload = subscribeMediaUpload( ( payload ) => {
this.mediaUpload( payload );
} );
}

toolbarEditButton() {
return (
<Toolbar>
<ToolbarButton
className="components-toolbar__control"
label={ __( 'Edit image' ) }
icon="edit"
onClick={ this.onMediaLibraryPress }
/>
</Toolbar>
);
removeMediaUploadListener() {
if ( this.subscriptionParentMediaUpload ) {
this.subscriptionParentMediaUpload.remove();
}
}

render() {
const { attributes, isSelected, setAttributes } = this.props;
const { url, caption, height, width } = attributes;

const onMediaLibraryButtonPressed = () => {
onMediaLibraryPressed( ( mediaId, mediaUrl ) => {
if ( mediaUrl ) {
setAttributes( { id: mediaId, url: mediaUrl } );
}
} );
};

if ( ! url ) {
const onUploadMediaButtonPressed = () => {
onUploadMediaPressed( ( mediaId, mediaUri ) => {
if ( mediaUri ) {
this.addMediaUploadListener( );
setAttributes( { url: mediaUri, id: mediaId } );
}
} );
};

const onCapturePhotoButtonPressed = () => {
onCapturePhotoPressed( ( mediaId, mediaUri ) => {
if ( mediaUri ) {
this.addMediaUploadListener( );
setAttributes( { url: mediaUri, id: mediaId } );
}
} );
};

return (
<MediaPlaceholder
onUploadPress={ this.onUploadPress }
onMediaLibraryPress={ this.onMediaLibraryPress }
onUploadMediaPressed={ onUploadMediaButtonPressed }
onMediaLibraryPressed={ onMediaLibraryButtonPressed }
onCapturePhotoPressed={ onCapturePhotoButtonPressed }
/>
);
}

const toolbarEditButton = (
<Toolbar>
<ToolbarButton
label={ __( 'Edit image' ) }
icon="edit"
onClick={ onMediaLibraryButtonPressed }
/>
</Toolbar>
);

const showSpinner = this.state.isUploadInProgress;
const opacity = this.state.isUploadInProgress ? 0.3 : 1;
const progress = this.state.progress * 100;

return (
<View style={ { flex: 1 } }>
{ showSpinner && <Spinner progress={ progress } /> }
<BlockControls>
{ this.toolbarEditButton() }
{ toolbarEditButton }
</BlockControls>
<ImageSize src={ url } >
{ ( sizes ) => {
Expand All @@ -84,7 +181,7 @@ class ImageEdit extends Component {
return (
<View style={ { flex: 1 } } >
<Image
style={ { width: finalWidth, height: finalHeight } }
style={ { width: finalWidth, height: finalHeight, opacity } }
resizeMethod="scale"
source={ { uri: url } }
key={ url }
Expand All @@ -99,7 +196,7 @@ class ImageEdit extends Component {
style={ { textAlign: 'center' } }
underlineColorAndroid="transparent"
value={ caption }
placeholder={ 'Write caption…' }
placeholder={ __( 'Write caption…' ) }
onChangeText={ ( newCaption ) => setAttributes( { caption: newCaption } ) }
/>
</View>
Expand All @@ -108,5 +205,3 @@ class ImageEdit extends Component {
);
}
}

export default ImageEdit;
1 change: 1 addition & 0 deletions packages/components/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { default as Toolbar } from './toolbar';
export { default as ToolbarButton } from './toolbar-button';
export { default as withSpokenMessages } from './higher-order/with-spoken-messages';
export { default as IconButton } from './icon-button';
export { default as Spinner } from './spinner';
export { createSlotFill, Slot, Fill, Provider as SlotFillProvider } from './slot-fill';

// Higher-Order Components
Expand Down
13 changes: 13 additions & 0 deletions packages/components/src/spinner/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { View } from 'react-native';

export default function Spinner( props ) {
const { progress } = props;

const width = progress + '%';

return (
<View style={ { flex: 1, height: 5, backgroundColor: '#c8d7e1' } }>
<View style={ { width, height: 5, backgroundColor: '#0087be' } } />
</View>
);
}
10 changes: 7 additions & 3 deletions packages/editor/src/components/media-placeholder/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ import { View, Text, Button } from 'react-native';

import styles from './styles.scss';

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

function MediaPlaceholder( props ) {
return (
<View style={ styles.emptyStateContainer }>
<Text style={ styles.emptyStateTitle }>
Image
{ __( 'Image' ) }
</Text>
<Text style={ styles.emptyStateDescription }>
Select an image from your library.
{ __( 'Upload a new image or select a file from your library.' ) }
</Text>
<View style={ styles.emptyStateButtonsContainer }>
<Button title="Media Library" onPress={ props.onMediaLibraryPress } />
<Button title={ __( 'Device Library' ) } onPress={ props.onUploadMediaPressed } />
<Button title={ __( 'Take photo' ) } onPress={ props.onCapturePhotoPressed } />
</View>
<Button title={ __( 'Media Library' ) } onPress={ props.onMediaLibraryPressed } />
</View>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
}

.emptyStateButtonsContainer {
margin-top: 15;
margin-bottom: 15;
flex-direction: row;
align-items: center;
justify-content: space-evenly;
width: 100%;
}