Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Refactor edit.native.js to make it similar to web
  • Loading branch information
pinarol committed Nov 12, 2018
commit 6e40f936daaf231723f361c41d1b955688540741
41 changes: 13 additions & 28 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,13 @@ import RNReactNativeGutenbergBridge from 'react-native-gutenberg-bridge';
* Internal dependencies
*/
import { MediaPlaceholder, RichText, BlockFormatControls } from '@wordpress/editor';
import { Toolbar } from '@wordpress/components';
import { Toolbar, IconButton } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

const TOOLBAR_BUTTON_TAG_EDIT = 'edit';

const TOOLBAR_BUTTONS = [
{
icon: 'edit',
title: __( 'Edit image' ),
tag: TOOLBAR_BUTTON_TAG_EDIT,
},
];

export default function ImageEdit( props ) {
const { attributes, isSelected, setAttributes } = props;
const { url, caption } = attributes;

const toggleToolbarButton = ( tag ) => {
return () => {
switch ( tag ) {
case TOOLBAR_BUTTON_TAG_EDIT:
onMediaLibraryPress();
break;
}
};
};

const toolbarControls = TOOLBAR_BUTTONS.map( ( control ) => ( {
...control,
onClick: toggleToolbarButton( control.tag ),
isActive: true,
} ) );

const onUploadPress = () => {
// This method should present an image picker from
// the device.
Expand All @@ -64,10 +38,21 @@ export default function ImageEdit( props ) {
);
}

const toolbarEditButton = (
<Toolbar>
<IconButton
className="components-toolbar__control"
label={ __( 'Edit image' ) }
icon="edit"
onClick={ onMediaLibraryPress }
/>
</Toolbar>
);

return (
<View style={ { flex: 1 } }>
<BlockFormatControls>
<Toolbar controls={ toolbarControls } />
{ toolbarEditButton }
</BlockFormatControls>
<Image
style={ { width: '100%', height: 200 } }
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './primitives';
export { default as Dashicon } from './dashicon';
export { default as Toolbar } from './toolbar';
export { default as withSpokenMessages } from './higher-order/with-spoken-messages';
export { default as IconButton } from './icon-button';
export { createSlotFill, Slot, Fill, Provider as SlotFillProvider } from './slot-fill';

// Higher-Order Components
Expand Down