-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] Add media edit icon to image block (#19723)
* Creates a MediaEdit component that shows a picker * Add Gridicon's customize icon * Show a button in images block that displays a picker * Fix lint issues * Fix no-shadow error * Fix the name of the params * When "Edit" is selected, request the Media Editor * Fix lint issues * Change media editor ID to a constant * When "Replace" is tapped, show all available media options * Fix lint issues * Avoid destructuring
- Loading branch information
1 parent
a911562
commit a38b633
Showing
5 changed files
with
130 additions
and
0 deletions.
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