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] Add "Set as Featured Image" Button to Image Block (Android Only) #28854

Closed
wants to merge 72 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
a4a52fe
Add "set as featured image" button to image block
SiobhyB Feb 8, 2021
4040201
Add "setFeaturedImage" function in bridge code
Feb 11, 2021
6bcfbd9
Add setFeaturedImage function to MainApplication
Feb 12, 2021
0cff0d7
Add "OnSetFeaturedImageListener" listener
Feb 12, 2021
dbec57d
Update edit.native.js with small syntax correction
Feb 12, 2021
d66bd01
Set up "OnSetFeaturedImageListener" in WPAndroidGlue.java
Feb 12, 2021
d1ed155
Passing featured image ID from native (Android) to Gutenberg
Mar 3, 2021
6a57885
Merge branch 'trunk' into update/featured-image-button-in-image-block…
SiobhyB Mar 3, 2021
444f3e3
Restore missing curly brace
Mar 3, 2021
2cbe570
Updates to featured-banner.native.js
Mar 5, 2021
073fa92
Attempts to select featured image using getEditedPostAttribute()
Mar 15, 2021
64359b1
Update featured-banner.native.js
Mar 15, 2021
48f8ea1
Add featured banner to image/index.native.js
Mar 15, 2021
f114ade
Update featured image banner and button styles
Mar 15, 2021
46ba7e8
Create getFeaturedImageId function and cleanup
Mar 16, 2021
b8f05f4
Tidy up edit.native.js
Mar 16, 2021
c7d00f3
Update AndroidGlueCode
Mar 18, 2021
84a8850
retrigger checks
Mar 22, 2021
eb78dc4
Update setup.js
Mar 22, 2021
bed517e
retrigger checks
Mar 22, 2021
64b1c8b
Update function name from "featuredImageIdChange" to "featuredImageId…
Mar 23, 2021
d8c0824
Rename "featuredImageIdNotifier" to "onRequestFeaturedImageId"
Mar 23, 2021
32f134d
Create OnSetFeaturedImageListener
Mar 23, 2021
75de59f
Dismiss bottomsheet when "setFeaturedImage" is called
Mar 23, 2021
67369d3
Introduce "onRemoveFeatured" button and tidying up names
Mar 29, 2021
c9aba0a
Updates to function names
Mar 29, 2021
a9d051f
Convert FeaturedBanner to Badge component
Mar 30, 2021
a92525b
Update edit.native.js to correct merge conflict
Mar 30, 2021
54a5f14
Correct merge conflict with GutenbergBridgeJS2Parent.java
Mar 30, 2021
e99999c
retrigger checks
Mar 30, 2021
be31d63
retrigger checks
Mar 30, 2021
9795874
retrigger checks
Mar 30, 2021
2284524
retrigger checks
Mar 30, 2021
2736f33
Update edit.native.js to fix merge conflict
Mar 31, 2021
e9ebc69
Update edit.native.js to check if an image is featured uppn changes
Mar 31, 2021
2eb1979
Update styles.native.scss to add border to the top of featured button
Apr 1, 2021
a33b8b9
Update edit.native.js
Apr 1, 2021
0cdeadb
Introduce "featuredMedia" prop for use when editor loads
Apr 6, 2021
737627d
Fetch ID of post's initial featured image
Apr 7, 2021
9e524ea
Merge branch 'trunk' into update/featured-image-button-in-image-block…
SiobhyB Apr 8, 2021
6d53341
Updated featured state when image is replaced within block
Apr 8, 2021
cc00dc2
Remove checkIfFeaturedImage function
Apr 8, 2021
4dc6cef
Fix merge conflict
Apr 8, 2021
b335086
Fix merge conflict
Apr 8, 2021
3cbe30a
Add "setFeaturedImage" and "featuredImageIdCurrent" functions to Swif…
Apr 10, 2021
39303e4
Simplify this.state.isFeaturedImage by converting to a boolean inside…
Apr 10, 2021
0c69a62
Comment out iOS-specific changes to the bridge
Apr 12, 2021
cc4aa8d
Add iOS functions to bridge
Apr 12, 2021
d71d067
Flag featured image when editor mounts and comment out iOS methods fr…
Apr 12, 2021
28f19af
Comment out a bridge function for iOS (missing from previous commit).
Apr 12, 2021
262291f
Add set featured image functionality behind dev flag
Apr 13, 2021
a17e6e9
Move "set as featured" button behind devOnly and androidOnly flag
Apr 13, 2021
1c4b2ca
Calling "__DEV__" directly instead of defining a separate variable
Apr 13, 2021
ba7c283
Update changelog.md
Apr 13, 2021
206fede
Merge branch 'trunk' into update/featured-image-button-in-image-block…
SiobhyB Apr 13, 2021
1f844b6
Merge branch 'trunk' into update/featured-image-button-in-image-block…
SiobhyB Apr 20, 2021
9761c04
Merge branch 'trunk' into update/featured-image-button-in-image-block…
SiobhyB Apr 20, 2021
85844e4
Remove "subscribeFeaturedImageIdCurrent" functionality
Apr 20, 2021
1f61eb8
Remove featuredImageId check in componentDidMount()
Apr 20, 2021
35fa071
Remove isFeaturedImage functionality from image/index.native.js
Apr 20, 2021
590040b
Remove iOS functions from bridge
Apr 20, 2021
619f4f7
Remove android.util.Log import
Apr 20, 2021
dd6a63f
Remove redundant space
Apr 20, 2021
35f7023
Update CHANGELOG.md
Apr 20, 2021
2ed72bf
Tweak androidOnly const
Apr 20, 2021
c74e737
Merge branch 'trunk' into update/featured-image-button-in-image-block…
Apr 23, 2021
68ef75e
Refactor 'set as featured' button into its own function
Apr 27, 2021
fbe83c2
Merge branch 'update/featured-image-button-in-image-block-settings' o…
Apr 27, 2021
e3ba262
Merge branch 'trunk' into update/featured-image-button-in-image-block…
SiobhyB Apr 27, 2021
9caa86a
Fix syntax issue with onSetFeatured function
Apr 27, 2021
fe2c108
Merge remote-tracking branch 'upstream/trunk' into update/featured-im…
Apr 27, 2021
89a8c6c
Merge branch 'WordPress:trunk' into update/featured-image-button-in-i…
SiobhyB May 9, 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
75 changes: 71 additions & 4 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { View, TouchableWithoutFeedback } from 'react-native';
import { View, TouchableWithoutFeedback, Platform } from 'react-native';
import { isEmpty, get, find, map } from 'lodash';

/**
Expand All @@ -14,6 +14,7 @@ import {
requestImageFailedRetryDialog,
requestImageUploadCancelDialog,
requestImageFullscreenPreview,
setFeaturedImage,
} from '@wordpress/react-native-bridge';
import {
CycleSelectControl,
Expand All @@ -24,6 +25,7 @@ import {
Image,
WIDE_ALIGNMENTS,
LinkSettingsNavigation,
BottomSheet,
BottomSheetTextControl,
FooterMessageLink,
Badge,
Expand All @@ -44,7 +46,7 @@ import { __, sprintf } from '@wordpress/i18n';
import { getProtocol, hasQueryArg } 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 {
image as placeholderIcon,
replace,
Expand Down Expand Up @@ -89,6 +91,7 @@ export class ImageEdit extends Component {
this.onSetNewTab = this.onSetNewTab.bind( this );
this.onSetSizeSlug = this.onSetSizeSlug.bind( this );
this.onImagePressed = this.onImagePressed.bind( this );
this.onSetFeatured = this.onSetFeatured.bind( this );
this.onFocusCaption = this.onFocusCaption.bind( this );
this.updateAlignment = this.updateAlignment.bind( this );
this.accessibilityLabelCreator = this.accessibilityLabelCreator.bind(
Expand Down Expand Up @@ -430,6 +433,62 @@ export class ImageEdit extends Component {
this.onSetSizeSlug( newValue );
}

onSetFeatured( mediaId ) {
const { closeSettingsBottomSheet } = this.props;
setFeaturedImage( mediaId );
closeSettingsBottomSheet();
}

getSetFeaturedButton( isFeaturedImage ) {
const { attributes, getStylesFromColorScheme } = this.props;

// eslint-disable-next-line no-unused-vars
const androidOnly = Platform.OS === 'android';

const featuredButtonStyle = getStylesFromColorScheme(
styles.featuredButton,
styles.featuredButtonDark
);

const setFeaturedButtonStyle = getStylesFromColorScheme(
styles.setFeaturedButton,
styles.setFeaturedButtonDark
);

return (
<>
{
// eslint-disable-next-line no-undef
androidOnly && (
<PanelBody>
{ isFeaturedImage ? (
<BottomSheet.Cell
label={ __( 'Remove as Featured Image ' ) }
labelStyle={ [
featuredButtonStyle,
styles.removeFeaturedButton,
] }
onPress={ () => this.onSetFeatured( 0 ) }
/>
) : (
<BottomSheet.Cell
label={ __( 'Set as Featured Image ' ) }
labelStyle={ [
featuredButtonStyle,
setFeaturedButtonStyle,
] }
onPress={ () =>
this.onSetFeatured( attributes.id )
}
/>
) }
</PanelBody>
)
}
</>
);
}

render() {
const { isCaptionSelected } = this.state;
const {
Expand All @@ -443,13 +502,13 @@ export class ImageEdit extends Component {
} = this.props;
const { align, url, alt, id, sizeSlug, className } = attributes;

const isFeaturedImage = featuredImageId === attributes.id;
hypest marked this conversation as resolved.
Show resolved Hide resolved

const sizeOptionsValid = find( this.sizeOptions, [
'value',
imageDefaultSize,
] );

const isFeaturedImage = featuredImageId === attributes.id;

const getToolbarEditButton = ( open ) => (
<BlockControls>
<ToolbarGroup>
Expand Down Expand Up @@ -487,6 +546,7 @@ export class ImageEdit extends Component {
<PanelBody title={ __( 'Link Settings' ) }>
{ this.getLinkSettings( true ) }
</PanelBody>
{ this.getSetFeaturedButton( isFeaturedImage ) }
</InspectorControls>
);

Expand Down Expand Up @@ -631,5 +691,12 @@ export default compose( [
),
};
} ),
withDispatch( ( dispatch ) => {
return {
closeSettingsBottomSheet() {
dispatch( 'core/edit-post' ).closeGeneralSidebar();
hypest marked this conversation as resolved.
Show resolved Hide resolved
},
};
} ),
withPreferredColorScheme,
] )( ImageEdit );
23 changes: 23 additions & 0 deletions packages/block-library/src/image/styles.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,26 @@
padding-right: 0;
padding-bottom: $grid-unit;
}

.featuredButton {
border-top-width: $border-width;
border-top-color: $light-gray-400;
padding: $grid-unit-20;
text-align: center;
}

.featuredButtonDark {
border-top-color: $gray-70;
}

.setFeaturedButton {
color: $blue-50;
}

.setFeaturedButtonDark {
color: $blue-30;
}

.removeFeaturedButton {
color: $alert-red;
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public static MediaType getEnum(String value) {

void requestImageUploadCancel(int mediaId);

void setFeaturedImage(int mediaId);

void editorDidEmitLog(String message, LogLevel logLevel);

void editorDidAutosave();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ public void requestImageUploadCancel(final int mediaId) {
mGutenbergBridgeJS2Parent.requestImageUploadCancel(mediaId);
}

@ReactMethod
public void setFeaturedImage(final int mediaId) {
mGutenbergBridgeJS2Parent.setFeaturedImage(mediaId);
}

@ReactMethod
public void requestImageFullscreenPreview(String mediaUrl) {
mGutenbergBridgeJS2Parent.requestImageFullscreenPreview(mediaUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class WPAndroidGlueCode {
private OnMediaLibraryButtonListener mOnMediaLibraryButtonListener;
private OnReattachMediaUploadQueryListener mOnReattachMediaUploadQueryListener;
private OnReattachMediaSavingQueryListener mOnReattachMediaSavingQueryListener;
private OnSetFeaturedImageListener mOnSetFeaturedImageListener;
private OnEditorMountListener mOnEditorMountListener;
private OnEditorAutosaveListener mOnEditorAutosaveListener;
private OnImageFullscreenPreviewListener mOnImageFullscreenPreviewListener;
Expand Down Expand Up @@ -171,6 +172,10 @@ public interface OnReattachMediaSavingQueryListener {
void onQueryCurrentProgressForSavingMedia();
}

public interface OnSetFeaturedImageListener {
void onSetFeaturedImageButtonClicked(int mediaId);
}

public interface OnEditorMountListener {
void onEditorDidMount(ArrayList<Object> unsupportedBlockNames);
}
Expand Down Expand Up @@ -316,6 +321,11 @@ public void requestImageUploadCancel(int mediaId) {
mOnMediaLibraryButtonListener.onCancelUploadForMediaDueToDeletedBlock(mediaId);
}

@Override
public void setFeaturedImage(int mediaId) {
mOnSetFeaturedImageListener.onSetFeaturedImageButtonClicked(mediaId);
}

@Override
public void editorDidMount(ReadableArray unsupportedBlockNames) {
mOnEditorMountListener.onEditorDidMount(unsupportedBlockNames.toArrayList());
Expand Down Expand Up @@ -537,6 +547,7 @@ public void attachToContainer(ViewGroup viewGroup,
OnMediaLibraryButtonListener onMediaLibraryButtonListener,
OnReattachMediaUploadQueryListener onReattachMediaUploadQueryListener,
OnReattachMediaSavingQueryListener onReattachMediaSavingQueryListener,
OnSetFeaturedImageListener onSetFeaturedImageListener,
OnEditorMountListener onEditorMountListener,
OnEditorAutosaveListener onEditorAutosaveListener,
OnAuthHeaderRequestedListener onAuthHeaderRequestedListener,
Expand All @@ -555,6 +566,7 @@ public void attachToContainer(ViewGroup viewGroup,
mOnMediaLibraryButtonListener = onMediaLibraryButtonListener;
mOnReattachMediaUploadQueryListener = onReattachMediaUploadQueryListener;
mOnReattachMediaSavingQueryListener = onReattachMediaSavingQueryListener;
mOnSetFeaturedImageListener = onSetFeaturedImageListener;
mOnEditorMountListener = onEditorMountListener;
mOnEditorAutosaveListener = onEditorAutosaveListener;
mRequestExecutor = fetchExecutor;
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native-bridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ export function requestImageUploadCancel( mediaId ) {
return RNReactNativeGutenbergBridge.requestImageUploadCancel( mediaId );
}

export function setFeaturedImage( mediaId ) {
return RNReactNativeGutenbergBridge.setFeaturedImage( mediaId );
}

export function getOtherMediaOptions( filter, callback ) {
return RNReactNativeGutenbergBridge.getOtherMediaOptions(
filter,
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ For each user feature we should also add a importance categorization label to i

- [***] Search block now available on mobile! [https://github.com/WordPress/gutenberg/pull/30783]
- [*] Image block: Add a "featured" banner. (Android only) [#30806]
- [*] Image block: "Set as featured" button within image block settings. (Android only) [#28854]
- [**] The media upload options of the Image, Video and Gallery block automatically opens when the respective block is inserted. [#29546]
- [**] The media upload options of the File and Audio block automatically opens when the respective block is inserted. [#31025]
- [*] Fixed a bug where the Search block was stealing focus from the Image block upon updating image asset [#31393]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public void requestImageUploadCancelDialog(int mediaId) {
public void requestImageUploadCancel(int mediaId) {
}

@Override
public void setFeaturedImage(int mediaId) {
}

@Override
public void editorDidMount(ReadableArray unsupportedBlockNames) {
}
Expand Down