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

Add media edit icon to image block #1782

Merged
merged 26 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
24c44bd
Add MediaEditor as a media source
leandroalonso Jan 17, 2020
5cc7b7c
Adds Media Editor call in iOS and Android projects
leandroalonso Jan 17, 2020
723422e
Update submobule commit
leandroalonso Jan 17, 2020
fec309e
Update submodule commit
leandroalonso Jan 17, 2020
a19bc00
Update submodule reference
leandroalonso Jan 17, 2020
4afaf29
Implements requestMediaEditor bridge method for iOS
leandroalonso Jan 17, 2020
deef065
Adds requestMediaEditor bridge method for Android
leandroalonso Jan 17, 2020
6011985
Update gutenberg submodule
leandroalonso Jan 17, 2020
7702822
Merge branch 'develop' into issue/1583_add_overflow_menu_button_to_image
leandroalonso Jan 21, 2020
da9adaa
Point gutenberg to my fork
leandroalonso Jan 21, 2020
7dd6e18
Fix wrong merge change
leandroalonso Jan 21, 2020
e91b9f3
Update subproject commit
leandroalonso Jan 21, 2020
4928edf
Remove dash
leandroalonso Jan 21, 2020
5ca3c27
Only display the button when in development
leandroalonso Jan 22, 2020
4535a1b
Remove Media Editor as an internal source
leandroalonso Jan 22, 2020
1e3bd5f
Remove media editor as a media source
leandroalonso Jan 22, 2020
29fcef5
Update gutenberg commit
leandroalonso Jan 22, 2020
6228bb5
Update gutenberg commit
leandroalonso Jan 22, 2020
cce42b1
Update gutenberg
leandroalonso Jan 22, 2020
2257b1c
Calls the callback with a different image to check if it works
leandroalonso Jan 23, 2020
dd2e639
Merge branch 'develop' into issue/1583_add_overflow_menu_button_to_image
leandroalonso Jan 27, 2020
063ec30
Update gutenberg
leandroalonso Jan 27, 2020
d268e4e
Merge branch 'develop' into issue/1583_add_overflow_menu_button_to_image
leandroalonso Jan 27, 2020
bed0461
Update gutenberg
leandroalonso Jan 27, 2020
7dd42a9
Merge branch 'develop' into issue/1583_add_overflow_menu_button_to_image
leandroalonso Jan 28, 2020
999f0df
Update gutenberg
leandroalonso Jan 28, 2020
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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "gutenberg"]
path = gutenberg
url = ../../WordPress/gutenberg.git
url = ../../leandroalonso/gutenberg.git
[submodule "react-native-aztec"]
path = react-native-aztec-old-submodule
url = ../react-native-aztec.git
5 changes: 5 additions & 0 deletions android/app/src/main/java/com/gutenberg/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public void requestImageFullscreenPreview(String mediaUrl) {

}

@Override
public void requestMediaEditor(MediaUploadCallback mediaUploadCallback, String mediaUrl) {

}

@Override
public void editorDidEmitLog(String message, LogLevel logLevel) {
switch (logLevel) {
Expand Down
2 changes: 1 addition & 1 deletion gutenberg
4 changes: 4 additions & 0 deletions ios/gutenberg/GutenbergViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ extension GutenbergViewController: GutenbergBridgeDelegate {
func gutenbergDidRequestImagePreview(with fullSizeUrl: URL, thumbUrl: URL?) {
print("Gutenberg requested fullscreen image preview for " + fullSizeUrl.absoluteString)
}

func gutenbergDidRequestMediaEditor(with mediaUrl: URL, callback: @escaping MediaPickerDidPickMediaCallback) {
print("Gutenberg requested media editor for " + mediaUrl.absoluteString)
leandroalonso marked this conversation as resolved.
Show resolved Hide resolved
}
}

extension GutenbergViewController: GutenbergBridgeDataSource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,6 @@ public static MediaType getEnum(String value) {
void requestMediaPickFrom(String mediaSource, MediaUploadCallback mediaUploadCallback, Boolean allowMultipleSelection);

void requestImageFullscreenPreview(String mediaUrl);

void requestMediaEditor(MediaUploadCallback mediaUploadCallback, String mediaUrl);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModu
private static final String MEDIA_SOURCE_MEDIA_LIBRARY = "SITE_MEDIA_LIBRARY";
private static final String MEDIA_SOURCE_DEVICE_LIBRARY = "DEVICE_MEDIA_LIBRARY";
private static final String MEDIA_SOURCE_DEVICE_CAMERA = "DEVICE_CAMERA";
private static final String MEDIA_SOURCE_MEDIA_EDITOR = "MEDIA_EDITOR";


public RNReactNativeGutenbergBridgeModule(ReactApplicationContext reactContext,
Expand Down Expand Up @@ -170,6 +171,11 @@ public void requestImageFullscreenPreview(String mediaUrl) {
mGutenbergBridgeJS2Parent.requestImageFullscreenPreview(mediaUrl);
}

@ReactMethod
public void requestMediaEditor(String mediaUrl, final Callback onUploadMediaSelected) {
mGutenbergBridgeJS2Parent.requestMediaEditor(getNewUploadMediaCallback(false, onUploadMediaSelected), mediaUrl);
}

@ReactMethod
public void editorDidEmitLog(String message, int logLevel) {
mGutenbergBridgeJS2Parent.editorDidEmitLog(message, GutenbergBridgeJS2Parent.LogLevel.valueOf(logLevel));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class WPAndroidGlueCode {
private OnEditorMountListener mOnEditorMountListener;
private OnEditorAutosaveListener mOnEditorAutosaveListener;
private OnImageFullscreenPreviewListener mOnImageFullscreenPreviewListener;
private OnMediaEditorListener mOnMediaEditorListener;
private boolean mIsEditorMounted;

private String mContentHtml = "";
Expand Down Expand Up @@ -149,6 +150,10 @@ public interface OnEditorAutosaveListener {
void onEditorAutosave();
}

public interface OnMediaEditorListener {
void onMediaEditorClicked(String mediaUrl);
}

public void mediaSelectionCancelled() {
mAppendsMultipleSelectedToSiblingBlocks = false;
}
Expand Down Expand Up @@ -305,6 +310,13 @@ public void performRequest(String pathFromJS, Consumer<String> onSuccess, Consum
public void requestImageFullscreenPreview(String mediaUrl) {
mOnImageFullscreenPreviewListener.onImageFullscreenPreviewClicked(mediaUrl);
}

@Override
public void requestMediaEditor(MediaUploadCallback mediaUploadCallback, String mediaUrl) {
mMediaPickedByUserOnBlock = true;
mPendingMediaUploadCallback = mediaUploadCallback;
mOnMediaEditorListener.onMediaEditorClicked(mediaUrl);
}
});

return Arrays.asList(
Expand Down Expand Up @@ -378,7 +390,8 @@ public void attachToContainer(ViewGroup viewGroup, OnMediaLibraryButtonListener
OnEditorAutosaveListener onEditorAutosaveListener,
OnAuthHeaderRequestedListener onAuthHeaderRequestedListener,
RequestExecutor fetchExecutor,
OnImageFullscreenPreviewListener onImageFullscreenPreviewListener) {
OnImageFullscreenPreviewListener onImageFullscreenPreviewListener,
OnMediaEditorListener onMediaEditorListener) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need a PR to WPAndroid that adds this new parameter where GutenbergContainerFragment calls this method. Otherwise, merging this will break building Gutenberg from source on WPAndroid (i.e., building with wp.BUILD_GUTENBERG_FROM_SOURCE=true added to WPAndroid's gradle.properties file).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MutableContextWrapper contextWrapper = (MutableContextWrapper) mReactRootView.getContext();
contextWrapper.setBaseContext(viewGroup.getContext());

Expand All @@ -388,6 +401,7 @@ public void attachToContainer(ViewGroup viewGroup, OnMediaLibraryButtonListener
mOnEditorAutosaveListener = onEditorAutosaveListener;
mRequestExecutor = fetchExecutor;
mOnImageFullscreenPreviewListener = onImageFullscreenPreviewListener;
mOnMediaEditorListener = onMediaEditorListener;

sAddCookiesInterceptor.setOnAuthHeaderRequestedListener(onAuthHeaderRequestedListener);

Expand Down
7 changes: 7 additions & 0 deletions react-native-gutenberg-bridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ export const mediaSources = {
deviceLibrary: 'DEVICE_MEDIA_LIBRARY',
deviceCamera: 'DEVICE_CAMERA',
siteMediaLibrary: 'SITE_MEDIA_LIBRARY',
mediaEditor: 'MEDIA_EDITOR',
};

export const showMediaEditorButton = isIOS;
leandroalonso marked this conversation as resolved.
Show resolved Hide resolved

// Console polyfill from react-native

export function nativeLoggingHook( message, logLevel ) {
Expand Down Expand Up @@ -108,6 +111,10 @@ export function requestImageFullscreenPreview( currentImageUrl, originalImageUrl
return RNReactNativeGutenbergBridge.requestImageFullscreenPreview( originalImageUrl || currentImageUrl );
}

export function requestMediaEditor( mediaUrl, callback ) {
return RNReactNativeGutenbergBridge.requestMediaEditor( mediaUrl, callback );
}

export function fetchRequest( path ) {
return RNReactNativeGutenbergBridge.fetchRequest( path );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ extension Gutenberg.MediaSource {
public static let mediaLibrary = Gutenberg.MediaSource(id: "SITE_MEDIA_LIBRARY", label: "", types: [.image, .video])
public static let deviceLibrary = Gutenberg.MediaSource(id: "DEVICE_MEDIA_LIBRARY", label: "", types: [.image, .video])
public static let deviceCamera = Gutenberg.MediaSource(id: "DEVICE_CAMERA", label: "", types: [.image, .video])
public static let mediaEditor = Gutenberg.MediaSource(id: "MEDIA_EDITOR", label: "", types: [.image])

static var registeredInternalSources: [Gutenberg.MediaSource] {
return [
.deviceCamera,
.deviceLibrary,
.mediaLibrary,
.mediaEditor,
leandroalonso marked this conversation as resolved.
Show resolved Hide resolved
]
}
}
Expand Down Expand Up @@ -133,7 +135,11 @@ public protocol GutenbergBridgeDelegate: class {

/// Tells the delegate to display a fullscreen image from a given URL
///
func gutenbergDidRequestImagePreview(with fullSizeUrl: URL, thumbUrl: URL?)
func gutenbergDidRequestImagePreview(with mediaUrl: URL, thumbUrl: URL?)

/// Tells the delegate to display the media editor from a given URL
///
func gutenbergDidRequestMediaEditor(with mediaUrl: URL, callback: @escaping MediaPickerDidPickMediaCallback)
leandroalonso marked this conversation as resolved.
Show resolved Hide resolved
}

// MARK: - Optional GutenbergBridgeDelegate methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ @interface RCT_EXTERN_MODULE(RNReactNativeGutenbergBridge, NSObject)
RCT_EXTERN_METHOD(editorDidAutosave)
RCT_EXTERN_METHOD(fetchRequest:(NSString *)path resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(requestImageFullscreenPreview:(NSString *)currentImageUrlString originalImageUrlString:(NSString *)originalImageUrlString)
RCT_EXTERN_METHOD(requestMediaEditor:(NSString *)mediaUrl callback:(RCTResponseSenderBlock)callback)

@end
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,31 @@ public class RNReactNativeGutenbergBridge: RCTEventEmitter {
}
}

@objc
func requestMediaEditor(_ urlString: String, callback: @escaping RCTResponseSenderBlock) {
guard let url = URL(string: urlString) else {
assertionFailure("Given String is not a URL")
return
}

DispatchQueue.main.async {
self.delegate?.gutenbergDidRequestMediaEditor(with: url) { media in
guard let media = media else {
callback(nil)
return
}

let mediaToReturn = media
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? Maybe we could usemedia directly


let jsFormattedMedia = mediaToReturn.map { mediaInfo in
return mediaInfo.encodeForJS()
}

callback(jsFormattedMedia)
}
}
}

private func shouldLog(with level: Int) -> Bool {
return level >= RCTGetLogThreshold().rawValue
}
Expand Down