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 all 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
19 changes: 9 additions & 10 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, Platform } from 'react-native';
import { View, TouchableWithoutFeedback } from 'react-native';
import { isEmpty, get, find, map } from 'lodash';

/**
Expand Down Expand Up @@ -443,7 +443,7 @@ export class ImageEdit extends Component {
closeSettingsBottomSheet();
}

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

const setFeaturedButtonStyle = getStylesFromColorScheme(
Expand Down Expand Up @@ -500,15 +500,15 @@ export class ImageEdit extends Component {
] );

// By default, it's only possible to set images that have been uploaded to a site's library as featured.
// Images that haven't been uploaded to a site's library have an id of 'undefined', which the 'canImageBeFeatured' check filters out.
const canImageBeFeatured = typeof attributes.id !== 'undefined';
// The 'canImageBeFeatured' check filters out images that haven't been uploaded based on the following:
// - Images that are embedded in a post but are uploaded elsewhere have an id of 'undefined'.
// - Image that are uploading or have failed to upload are given a temporary negative ID.
const canImageBeFeatured =
typeof attributes.id !== 'undefined' && attributes.id > 0;

const isFeaturedImage =
canImageBeFeatured && featuredImageId === attributes.id;

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

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

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 @@ -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