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 (iOS Only) #31415

Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8af6519
Set up "featuredImageId" as "initialProps" and send gutenbergFeatured…
Apr 29, 2021
ce205be
Set up "featuredImageIdNativeUpdated" to fetch details of an updated …
Apr 29, 2021
9fe8023
Removed isAndroid conditional surrounding "featuredImageIdNativeUpdat…
Apr 29, 2021
bece4b5
Update style.css to ensure badge is rounded on iOS
Apr 29, 2021
f32618a
Add gutenbergFeaturedImageId() to GutenbergDemo/GutenbergViewControll…
Apr 29, 2021
2dc0802
Merge branch 'add/featured-functionality-to-image-block-ios' into add…
Apr 30, 2021
8f5b80e
Remove androidOnly conditional surrounding "set as featured" button
May 3, 2021
d173d5d
Add "setFeaturedImage" method to bridge for iOS
May 3, 2021
8ff12dd
Update gutenbergDidRequestToSetFeaturedImage() in GutenbergDemo/Guten…
May 3, 2021
53f3ec5
Update WPAndroidGlueCode with setFeaturedImage() bridge functions
May 3, 2021
5cbeb7b
Merge branch 'add/featured-functionality-to-image-block-ios' into add…
May 6, 2021
0d6e69f
Merge branch 'add/featured-functionality-to-image-block-ios' into add…
May 13, 2021
0bcc7ca
Merge branch 'add/featured-functionality-to-image-block-ios' into add…
May 21, 2021
bd7bfa0
Merge branch 'add/featured-functionality-to-image-block-ios' into add…
May 27, 2021
5301306
Merge branch 'add/featured-functionality-to-image-block-ios' into add…
May 30, 2021
d173763
Update function name for clarity
Jun 2, 2021
ad77029
Merge branch 'add/featured-functionality-to-image-block-ios' into add…
Jun 2, 2021
f0d492a
Merge branch 'add/featured-functionality-to-image-block-ios' into add…
Jun 3, 2021
a6e0206
Remove androidOnly const
Jun 3, 2021
60d205c
Add upload check to 'canImageBeFeatured'
Jun 4, 2021
4437cac
Merge branch 'add/featured-functionality-to-image-block-ios' into add…
Jun 21, 2021
9063559
Merge branch 'add/featured-functionality-to-image-block-ios' into add…
Jun 21, 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
61 changes: 60 additions & 1 deletion packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,54 @@ export class ImageEdit extends Component {
this.onSetSizeSlug( newValue );
}

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

getSetFeaturedButton( isFeaturedImage ) {
guarani marked this conversation as resolved.
Show resolved Hide resolved
const { attributes, getStylesFromColorScheme } = this.props;

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

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

return (
<>
<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 Down Expand Up @@ -489,6 +540,7 @@ export class ImageEdit extends Component {
<PanelBody title={ __( 'Link Settings' ) }>
{ this.getLinkSettings( true ) }
</PanelBody>
{ this.getSetFeaturedButton( isFeaturedImage ) }
</InspectorControls>
);

Expand Down Expand Up @@ -633,5 +685,12 @@ export default compose( [
),
};
} ),
withDispatch( ( dispatch ) => {
return {
closeSettingsBottomSheet() {
dispatch( 'core/edit-post' ).closeGeneralSidebar();
},
};
} ),
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 @@ -85,6 +85,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 @@ -172,6 +173,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 @@ -317,6 +322,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 @@ -539,6 +549,7 @@ public void attachToContainer(ViewGroup viewGroup,
OnMediaLibraryButtonListener onMediaLibraryButtonListener,
OnReattachMediaUploadQueryListener onReattachMediaUploadQueryListener,
OnReattachMediaSavingQueryListener onReattachMediaSavingQueryListener,
OnSetFeaturedImageListener onSetFeaturedImageListener,
OnEditorMountListener onEditorMountListener,
OnEditorAutosaveListener onEditorAutosaveListener,
OnAuthHeaderRequestedListener onAuthHeaderRequestedListener,
Expand All @@ -557,6 +568,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 @@ -244,6 +244,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
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public protocol GutenbergBridgeDelegate: class {
///
func gutenbergDidRequestMediaUploadCancelation(for mediaID: Int32)

/// Tells the delegate that an image block requested for the featured image to be set.
///
func gutenbergDidRequestToSetFeaturedImage(for mediaID: Int32)

/// Tells the delegate that the Gutenberg module has finished loading.
///
func gutenbergDidLoad()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ @interface RCT_EXTERN_MODULE(RNReactNativeGutenbergBridge, NSObject)
RCT_EXTERN_METHOD(requestImageFailedRetryDialog:(int)mediaID)
RCT_EXTERN_METHOD(requestImageUploadCancelDialog:(int)mediaID)
RCT_EXTERN_METHOD(requestImageUploadCancel:(int)mediaID)
RCT_EXTERN_METHOD(setFeaturedImage:(int)mediaID)
RCT_EXTERN_METHOD(requestMediaImport:(NSString *)sourceURL callback:(RCTResponseSenderBlock)callback)
RCT_EXTERN_METHOD(editorDidLayout)
RCT_EXTERN_METHOD(editorDidMount:(NSArray *)unsupportedBlockNames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ public class RNReactNativeGutenbergBridge: RCTEventEmitter {
}
}

@objc
func setFeaturedImage(_ mediaID: Int32) {
DispatchQueue.main.async {
self.delegate?.gutenbergDidRequestToSetFeaturedImage(for: mediaID)
}
}

@objc
func editorDidLayout() {
DispatchQueue.main.async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,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
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ extension GutenbergViewController: GutenbergBridgeDelegate {
print("Gutenberg request for media uploads to be resync")
}

func gutenbergDidRequestToSetFeaturedImage(for mediaID: Int32) {
print("Gutenberg request to set featured image")
}

func gutenbergDidRequestMediaUploadActionDialog(for mediaID: Int32) {
guard let progress = mediaUploadCoordinator.progressForUpload(mediaID: mediaID) else {
return
Expand Down