-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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] Add media edit icon to image block #19723
Merged
etoledom
merged 14 commits into
WordPress:master
from
leandroalonso:rnmobile/1583_add_overflow_menu_button_to_image
Jan 28, 2020
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d0338f8
Creates a MediaEdit component that shows a picker
leandroalonso 320753c
Add Gridicon's customize icon
leandroalonso a5e02a7
Show a button in images block that displays a picker
leandroalonso 2f7f12e
Fix lint issues
leandroalonso 9eedddd
Fix no-shadow error
leandroalonso 2ecc452
Fix the name of the params
leandroalonso 5969091
When "Edit" is selected, request the Media Editor
leandroalonso 0f936c0
Fix lint issues
leandroalonso 1f96853
Merge branch 'master' into rnmobile/1583_add_overflow_menu_button_to_…
leandroalonso 905656e
Change media editor ID to a constant
leandroalonso dd1c93e
When "Replace" is tapped, show all available media options
leandroalonso e72a22a
Fix lint issues
leandroalonso 360ef2b
Merge branch 'master' into rnmobile/1583_add_overflow_menu_button_to_…
leandroalonso e113310
Avoid destructuring
leandroalonso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/block-editor/src/components/media-edit/index.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
import { | ||
requestMediaEditor, | ||
mediaSources, | ||
} from 'react-native-gutenberg-bridge'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Picker } from '@wordpress/components'; | ||
|
||
export const MEDIA_TYPE_IMAGE = 'image'; | ||
|
||
export const MEDIA_EDITOR = 'MEDIA_EDITOR'; | ||
|
||
const editOption = { | ||
id: MEDIA_EDITOR, | ||
value: MEDIA_EDITOR, | ||
label: __( 'Edit' ), | ||
types: [ MEDIA_TYPE_IMAGE ], | ||
icon: 'admin-appearance', | ||
}; | ||
|
||
const replaceOption = { | ||
id: mediaSources.deviceLibrary, | ||
value: mediaSources.deviceLibrary, | ||
label: __( 'Replace' ), | ||
types: [ MEDIA_TYPE_IMAGE ], | ||
icon: 'update', | ||
}; | ||
|
||
const options = [ editOption, replaceOption ]; | ||
|
||
export class MediaEdit extends React.Component { | ||
constructor( props ) { | ||
super( props ); | ||
this.onPickerPresent = this.onPickerPresent.bind( this ); | ||
this.onPickerSelect = this.onPickerSelect.bind( this ); | ||
} | ||
|
||
getMediaOptionsItems() { | ||
return options; | ||
} | ||
|
||
onPickerPresent() { | ||
if ( this.picker ) { | ||
this.picker.presentPicker(); | ||
} | ||
} | ||
|
||
onPickerSelect( value ) { | ||
const { onSelect, multiple = false } = this.props; | ||
|
||
switch ( value ) { | ||
case MEDIA_EDITOR: | ||
requestMediaEditor( this.props.source.uri, ( media ) => { | ||
if ( ( multiple && media ) || ( media && media.id ) ) { | ||
onSelect( media ); | ||
} | ||
} ); | ||
break; | ||
default: | ||
this.props.openReplaceMediaOptions(); | ||
} | ||
} | ||
|
||
render() { | ||
const mediaOptions = () => ( | ||
<Picker | ||
hideCancelButton | ||
ref={ ( instance ) => this.picker = instance } | ||
options={ this.getMediaOptionsItems() } | ||
onChange={ this.onPickerSelect } | ||
/> | ||
); | ||
|
||
return this.props.render( { open: this.onPickerPresent, mediaOptions } ); | ||
} | ||
} | ||
|
||
export default MediaEdit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Path, SVG } from '@wordpress/components'; | ||
|
||
export default <SVG xmlns="http://www.w3.org/2000/svg"><Path d="M2 6c0-1.505.78-3.08 2-4 0 .845.69 2 2 2 1.657 0 3 1.343 3 3 0 .386-.08.752-.212 1.09.74.594 1.476 1.19 2.19 1.81L8.9 11.98c-.62-.716-1.214-1.454-1.807-2.192C6.753 9.92 6.387 10 6 10c-2.21 0-4-1.79-4-4zm12.152 6.848l1.34-1.34c.607.304 1.283.492 2.008.492 2.485 0 4.5-2.015 4.5-4.5 0-.725-.188-1.4-.493-2.007L18 9l-2-2 3.507-3.507C18.9 3.188 18.225 3 17.5 3 15.015 3 13 5.015 13 7.5c0 .725.188 1.4.493 2.007L3 20l2 2 6.848-6.848c1.885 1.928 3.874 3.753 5.977 5.45l1.425 1.148 1.5-1.5-1.15-1.425c-1.695-2.103-3.52-4.092-5.448-5.977z" /></SVG>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My personal preference would be to avoid destructuring and manually calling the
editImageComponent
function here. Since theeditImageComponent
function is only used here, I would destructure in that function (line 400):so that this
render
line could be compacted down torender={ editImageComponent }
.With that said, this is firmly in the realm of personal preference, and what you have is perfectly fine, so feel free to leave it as-is. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL!
Changed in e113310