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] Simplify media insertion flow #25031

Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
67c84d9
automatically open the media options bottom sheet
jd-alexander Sep 2, 2020
e8940fd
remove the image if the cancel option is selected.
jd-alexander Sep 2, 2020
d795232
added the clear media option.
jd-alexander Sep 3, 2020
3c29025
fixed the order of the cancel button.
jd-alexander Sep 3, 2020
0bc20d7
put a newline to separate cancellation if logic from the code below
jd-alexander Sep 3, 2020
9f3269b
made variable names more meaningful.
jd-alexander Sep 3, 2020
7de89e0
shared the destructiveButton logic between the Image & Cover block.
jd-alexander Sep 3, 2020
d488ba8
Merge branch 'master' into rnmobile/simplify_image_insertion_flow
jd-alexander Sep 24, 2020
8163ce6
merging resolved conflicts.
jd-alexander Sep 24, 2020
6a9d981
reverted the Image Editing Button behavior to having the ability to …
jd-alexander Sep 29, 2020
3de9cf0
Reverted changes to the ImageComponent and passed in the Clear Media …
jd-alexander Sep 29, 2020
59c36db
remove the delete behavior from the image block.
jd-alexander Sep 29, 2020
3cdde20
Utilize a delay on iOS so that the inserter being closed doesn't dism…
jd-alexander Sep 29, 2020
60a3feb
remove unnecessary line.
jd-alexander Sep 29, 2020
8966c23
put the mediaPickerOptions back in the correct location to eliminate …
jd-alexander Sep 29, 2020
0bfe3d6
pass the autoOpenMediaUpload flag to the MediaUpload component so it …
jd-alexander Sep 30, 2020
f72c3ae
moved delaying logic to the MediaUpload onPickerPresent function.
jd-alexander Sep 30, 2020
0ce172c
Once the media is cleared then the picker should not be shown.
jd-alexander Sep 30, 2020
e608165
removed unneeded MEDIA_UPLOAD_CANCEL type
jd-alexander Sep 30, 2020
c104069
revert changes made to the Cover block with onClearMedia logic.
jd-alexander Sep 30, 2020
0628c3f
removed unneeded variable for autoOpenMediaUpload
jd-alexander Sep 30, 2020
4148aca
added auto open to the Video block.
jd-alexander Oct 1, 2020
cb8f9e0
added the auto open to the Image Gallery block.
jd-alexander Oct 1, 2020
ff3e869
removed unneeded state and passed the auto open logic as an expression.
jd-alexander Oct 1, 2020
3016466
paused auto open logic as an expression to autoOpenMediaUpload.
jd-alexander Oct 1, 2020
af882b8
added a comment about why the delay is necessary on iOS.
jd-alexander Oct 1, 2020
07cea7b
attempt at fixing tests.
jd-alexander Oct 2, 2020
7ad8fc8
Changed the iOS Picker's termination action text from Cancel to Dismiss.
jd-alexander Oct 8, 2020
3f113a7
changed button accessibility id from Cancel to Dismiss.
jd-alexander Oct 8, 2020
23dc6fe
Merge branch 'master' into rnmobile/simplify_image_insertion_flow
jd-alexander Oct 9, 2020
372306f
Merge branch 'master' into rnmobile/simplify_image_insertion_flow
jd-alexander Oct 9, 2020
f217d4a
use driver.sleep( 1000 ) to ensure that the bottom sheet is visible.
jd-alexander Oct 9, 2020
e598262
Merge branch 'master' into rnmobile/simplify_image_insertion_flow
jd-alexander Oct 12, 2020
e3d3eeb
Merge branch 'master' into rnmobile/simplify_image_insertion_flow
jd-alexander Oct 12, 2020
96d6b7a
Merge branch 'master' into rnmobile/simplify_image_insertion_flow
jd-alexander Oct 13, 2020
1b9656b
The Undo and clearMedia buttons do not trigger the media upload picker
jd-alexander Oct 14, 2020
653b416
bottom sheet is not triggered for undo operations on the video block.
jd-alexander Oct 16, 2020
252c74e
bottom sheet is not triggered for clear or undo gallery operations
jd-alexander Oct 16, 2020
458499a
Merge branch 'master' into rnmobile/simplify_image_insertion_flow
jd-alexander Oct 16, 2020
4691407
converted behavior to utilize hooks in the gallery component.
jd-alexander Oct 16, 2020
ae0c58c
added actions for the block insertion events.
jd-alexander Nov 11, 2020
7b49207
Updated actions, reducer and selectors to support block inserted.
jd-alexander Nov 12, 2020
6cf07a6
added block insertion event to menu.
jd-alexander Nov 12, 2020
206a83f
Added wasBlockJustInserted to utilize it to open the bottom sheet.
jd-alexander Nov 12, 2020
d3cfdfa
Removed already opened logic and bound the wasBlockJustInserted
jd-alexander Nov 12, 2020
2fcaaab
simplified redux approach for auto opening.
jd-alexander Nov 13, 2020
350aef7
removed unneeded true comparison
jd-alexander Nov 13, 2020
043a9b6
renamed the behavior from blockInsertionEvent to lastBlockInserted
jd-alexander Nov 14, 2020
20e79e4
added the wasBlockJustInserted call to the Image block.
jd-alexander Nov 14, 2020
2fec1cc
added wasBlockJustInserted functionality to the Gallery flow.
jd-alexander Nov 14, 2020
e396965
added wasBlockJustInserted to the Video component.
jd-alexander Nov 14, 2020
397b79f
Updated the comment so it's more meaningful.
jd-alexander Nov 14, 2020
ef86342
Merge branch 'master' into rnmobile/simplify_image_insertion_flow
jd-alexander Nov 14, 2020
cb7aeaf
improved the comment of the lastBlockInserted selector
jd-alexander Nov 14, 2020
6afbaf8
Update packages/editor/src/store/selectors.native.js
jd-alexander Nov 17, 2020
f114df8
Merge branch 'master' into rnmobile/simplify_image_insertion_flow
jd-alexander Mar 1, 2021
35b703b
fixed issues that arose during the merge.
jd-alexander Mar 1, 2021
fd49e34
removed optimist block from reducer combination.
jd-alexander Mar 1, 2021
d56673f
Merge branch 'trunk' into rnmobile/simplify_image_insertion_flow
jd-alexander Mar 1, 2021
f76fd03
Utilized the useDispatch hook approach for last block inserted.
jd-alexander Mar 1, 2021
fd0e7dd
fixed lint errors.
jd-alexander Mar 1, 2021
c1c0087
Utilized editorPage.driver instead of driver reference.
jd-alexander Mar 1, 2021
fb4d162
added unit tests for the selectors.
jd-alexander Mar 1, 2021
21ce189
renamed the title of test group to match with tests within the store
jd-alexander Mar 2, 2021
91556bc
removed unneeded client from CLEAR_LAST_BLOCK_INSERTED
jd-alexander Mar 2, 2021
7030c9d
added unit tests for the actions and reducers of the last block inserted
jd-alexander Mar 2, 2021
f664f27
made test values simpler.
jd-alexander Mar 2, 2021
d0a8610
added documentation for changes to the MediaPlaceholder component.
jd-alexander Mar 2, 2021
e23f7df
Merge branch 'trunk' into rnmobile/simplify_image_insertion_flow
jd-alexander Mar 2, 2021
ca7eee3
updated MediaUpload and MediaPlaceholder documentation.
jd-alexander Mar 2, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ function MediaPlaceholder( props ) {
height,
backgroundColor,
hideContent,
autoOpenMediaUpload,
onMediaUploadCanceled,
} = props;

// use ref to keep media array current for callbacks during rerenders
Expand Down Expand Up @@ -147,6 +149,7 @@ function MediaPlaceholder( props ) {
<MediaUpload
allowedTypes={ allowedTypes }
onSelect={ setMedia }
onMediaUploadCanceled={ onMediaUploadCanceled }
__experimentalOnlyMediaLibrary={
__experimentalOnlyMediaLibrary
}
Expand Down Expand Up @@ -178,6 +181,7 @@ function MediaPlaceholder( props ) {
] }
>
{ getMediaOptions() }
{ autoOpenMediaUpload && open() }
{ ! hideContent && renderContent() }
</View>
</TouchableWithoutFeedback>
Expand Down
33 changes: 30 additions & 3 deletions packages/block-editor/src/components/media-upload/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ import {
requestMediaPicker,
mediaSources,
} from '@wordpress/react-native-bridge';
import { capturePhoto, captureVideo, image, wordpress } from '@wordpress/icons';
import {
capturePhoto,
captureVideo,
image,
wordpress,
close,
} from '@wordpress/icons';

export const MEDIA_TYPE_IMAGE = 'image';
export const MEDIA_TYPE_VIDEO = 'video';
export const MEDIA_UPLOAD_CANCEL = `cancel_media_upload`;
jd-alexander marked this conversation as resolved.
Show resolved Hide resolved

export const OPTION_TAKE_VIDEO = __( 'Take a Video' );
export const OPTION_TAKE_PHOTO = __( 'Take a Photo' );
Expand Down Expand Up @@ -85,14 +92,23 @@ export class MediaUpload extends React.Component {
mediaLibrary: true,
};

const cancelMediaUpload = {
value: MEDIA_UPLOAD_CANCEL,
label: __( 'Cancel' ),
types: [ MEDIA_TYPE_IMAGE ],
icon: close,
};
jd-alexander marked this conversation as resolved.
Show resolved Hide resolved

const internalSources = [
deviceLibrarySource,
cameraImageSource,
cameraVideoSource,
siteLibrarySource,
];

return internalSources.concat( this.state.otherMediaOptions );
return internalSources
.concat( this.state.otherMediaOptions )
.concat( cancelMediaUpload );
}

getMediaOptionsItems() {
Expand Down Expand Up @@ -138,7 +154,18 @@ export class MediaUpload extends React.Component {
}

onPickerSelect( value ) {
const { allowedTypes = [], onSelect, multiple = false } = this.props;
const {
allowedTypes = [],
onSelect,
multiple = false,
onMediaUploadCanceled,
} = this.props;

if ( value === MEDIA_UPLOAD_CANCEL ) {
onMediaUploadCanceled();
return;
}

const mediaSource = this.getAllSources()
.filter( ( source ) => source.value === value )
.shift();
Expand Down
11 changes: 1 addition & 10 deletions packages/block-library/src/cover/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,16 +486,7 @@ const Cover = ( {
<ImageEditingButton
onSelectMediaUploadOption={ onSelectMedia }
openMediaOptions={ openMediaOptionsRef.current }
pickerOptions={ [
{
destructiveButton: true,
id: 'clearMedia',
label: __( 'Clear Media' ),
onPress: onClearMedia,
separated: true,
value: 'clearMedia',
},
] }
onClearMedia={ onClearMedia }
url={ url }
/>
</View>
Expand Down
32 changes: 29 additions & 3 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { __, sprintf } from '@wordpress/i18n';
import { getProtocol } from '@wordpress/url';
import { doAction, hasAction } from '@wordpress/hooks';
import { compose, withPreferredColorScheme } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';
import { withSelect, withDispatch } from '@wordpress/data';
import {
external,
link,
Expand All @@ -64,8 +64,12 @@ export class ImageEdit extends React.Component {
constructor( props ) {
super( props );

const { attributes, isSelected } = this.props;
const { url } = attributes;
const autoOpenMediaUpload = isSelected && ! url;
this.state = {
isCaptionSelected: false,
autoOpenMediaUpload,
};

this.finishMediaUploadWithSuccess = this.finishMediaUploadWithSuccess.bind(
Expand All @@ -90,6 +94,7 @@ export class ImageEdit extends React.Component {
this.accessibilityLabelCreator = this.accessibilityLabelCreator.bind(
this
);
this.onClearMedia = this.onClearMedia.bind( this );
}

componentDidMount() {
Expand Down Expand Up @@ -307,6 +312,11 @@ export class ImageEdit extends React.Component {
}
}

onClearMedia() {
this.props.setAttributes( { id: null, url: null } );
this.setState( { autoOpenMediaUpload: false } );
}

getPlaceholderIcon() {
return (
<Icon
Expand All @@ -320,8 +330,14 @@ export class ImageEdit extends React.Component {
}

render() {
const { isCaptionSelected } = this.state;
const { attributes, isSelected, image, imageSizes } = this.props;
const { isCaptionSelected, autoOpenMediaUpload } = this.state;
const {
attributes,
isSelected,
image,
imageSizes,
onDelete,
} = this.props;
const {
align,
url,
Expand Down Expand Up @@ -407,6 +423,8 @@ export class ImageEdit extends React.Component {
onSelect={ this.onSelectMediaUploadOption }
icon={ this.getPlaceholderIcon() }
onFocus={ this.props.onFocus }
autoOpenMediaUpload={ autoOpenMediaUpload }
onMediaUploadCanceled={ onDelete }
/>
</View>
);
Expand Down Expand Up @@ -465,6 +483,7 @@ export class ImageEdit extends React.Component {
onSelectMediaUploadOption={
this.onSelectMediaUploadOption
}
onClearMedia={ this.onClearMedia }
openMediaOptions={ openMediaOptions }
retryMessage={ retryMessage }
url={ url }
Expand Down Expand Up @@ -517,5 +536,12 @@ export default compose( [
imageSizes,
};
} ),
withDispatch( ( dispatch, { clientId, rootClientId, onDelete } ) => {
const { removeBlock } = dispatch( 'core/block-editor' );
return {
onDelete:
onDelete || ( () => removeBlock( clientId, rootClientId ) ),
jd-alexander marked this conversation as resolved.
Show resolved Hide resolved
};
} ),
withPreferredColorScheme,
] )( ImageEdit );
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TouchableWithoutFeedback, View } from 'react-native';
* WordPress dependencies
*/
import { Icon } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
Expand All @@ -18,7 +19,7 @@ import styles from './style.scss';
const ImageEditingButton = ( {
onSelectMediaUploadOption,
openMediaOptions,
pickerOptions,
onClearMedia,
url,
} ) => {
return (
Expand All @@ -40,7 +41,16 @@ const ImageEditingButton = ( {
</View>
</TouchableWithoutFeedback>
) }
pickerOptions={ pickerOptions }
pickerOptions={ [
{
destructiveButton: true,
id: 'clearMedia',
label: __( 'Clear Media' ),
onPress: onClearMedia,
separated: true,
value: 'clearMedia',
},
] }
/>
);
};
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/mobile/image/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ const ImageComponent = ( {
isSelected,
isUploadFailed,
isUploadInProgress,
mediaPickerOptions,
onSelectMediaUploadOption,
openMediaOptions,
onClearMedia,
resizeMode,
retryMessage,
url,
Expand Down Expand Up @@ -225,7 +225,7 @@ const ImageComponent = ( {
}
openMediaOptions={ openMediaOptions }
url={ url }
pickerOptions={ mediaPickerOptions }
onClearMedia={ onClearMedia }
jd-alexander marked this conversation as resolved.
Show resolved Hide resolved
/>
) }
</View>
Expand Down