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 support for xpost suggestions on mobile #26211

Merged
merged 22 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
48f1a4a
Add support for xpost suggestions on mobile
mchowning Oct 16, 2020
409e549
Add xpost bridge methods for iOS
guarani Oct 19, 2020
259b3ec
Update @mention toolbar button callback
guarani Oct 19, 2020
b1040b0
Check for trigger key codes at beginning of lines
mchowning Nov 12, 2020
cf73fbd
Add xposts capability handling
mchowning Nov 18, 2020
fd7945e
Merge branch 'master' into rnmobile/xpost_initial_implementation
guarani Nov 30, 2020
df7bf4b
added xposts capability for iOS
guarani Nov 30, 2020
b860b16
Merge branch 'master' into rnmobile/xpost_initial_implementation
guarani Dec 3, 2020
e730f2e
Add Xpost to toolbar via long-press on @-mentions
guarani Dec 3, 2020
3f2d0c2
Updated code formatting
guarani Dec 3, 2020
269d39a
Merge remote-tracking branch 'origin/master' into rnmobile/xpost_init…
mchowning Dec 4, 2020
7e3662a
Dynamically update suggestions button
mchowning Dec 8, 2020
5b4d356
Update snapshot tests broken by xpost modal
mchowning Dec 9, 2020
1df18c8
Extract suggestions format button component
mchowning Dec 10, 2020
056125f
Make suggestions toolbar button generic
mchowning Dec 10, 2020
d7ef2ad
Replace Toolbar with ToolbarGroup
mchowning Dec 10, 2020
ec51eb5
Update mobile snapshot tests to remove Modal
mchowning Dec 10, 2020
cb3df6c
Enable xposts in Android demo app
mchowning Dec 14, 2020
bb6ecb5
Enable xposts in ios demo app
mchowning Dec 14, 2020
f8027c5
Add change log item for cross-posts
guarani Dec 17, 2020
fe630ab
Merge branch 'master' into rnmobile/xpost_initial_implementation
guarani Dec 17, 2020
b8a2fa1
Merge branch 'master' into rnmobile/xpost_initial_implementation
guarani Dec 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ void gutenbergDidRequestUnsupportedBlockFallback(ReplaceUnsupportedBlockCallback

void gutenbergDidSendButtonPressedAction(String buttonType);

void onAddMention(Consumer<String> onSuccess);
void onShowUserSuggestions(Consumer<String> onResult);

void onShowXpostSuggestions(Consumer<String> onResult);

void setStarterPageTemplatesTooltipShown(boolean tooltipShown);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,13 @@ private OtherMediaOptionsReceivedCallback getNewOtherMediaReceivedCallback(final
}

@ReactMethod
public void addMention(Promise promise) {
mGutenbergBridgeJS2Parent.onAddMention(promise::resolve);
public void showUserSuggestions(Promise promise) {
mGutenbergBridgeJS2Parent.onShowUserSuggestions(promise::resolve);
}

@ReactMethod
public void showXpostSuggestions(Promise promise) {
mGutenbergBridgeJS2Parent.onShowXpostSuggestions(promise::resolve);
}

@ReactMethod
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
data class GutenbergProps @JvmOverloads constructor(
val enableMediaFilesCollectionBlocks: Boolean,
val enableMentions: Boolean,
val enableXPosts: Boolean,
val enableUnsupportedBlockEditor: Boolean,
val canEnableUnsupportedBlockEditor: Boolean,
val localeSlug: String,
Expand Down Expand Up @@ -38,6 +39,7 @@ data class GutenbergProps @JvmOverloads constructor(

fun getUpdatedCapabilitiesProps() = Bundle().apply {
putBoolean(PROP_CAPABILITIES_MENTIONS, enableMentions)
putBoolean(PROP_CAPABILITIES_XPOSTS, enableXPosts)
putBoolean(PROP_CAPABILITIES_MEDIAFILES_COLLECTION_BLOCK, enableMediaFilesCollectionBlocks)
putBoolean(PROP_CAPABILITIES_UNSUPPORTED_BLOCK_EDITOR, enableUnsupportedBlockEditor)
putBoolean(PROP_CAPABILITIES_CAN_ENABLE_UNSUPPORTED_BLOCK_EDITOR, canEnableUnsupportedBlockEditor)
Expand Down Expand Up @@ -68,6 +70,7 @@ data class GutenbergProps @JvmOverloads constructor(
const val PROP_CAPABILITIES = "capabilities"
const val PROP_CAPABILITIES_MEDIAFILES_COLLECTION_BLOCK = "mediaFilesCollectionBlock"
const val PROP_CAPABILITIES_MENTIONS = "mentions"
const val PROP_CAPABILITIES_XPOSTS = "xposts"
const val PROP_CAPABILITIES_UNSUPPORTED_BLOCK_EDITOR = "unsupportedBlockEditor"
const val PROP_CAPABILITIES_CAN_ENABLE_UNSUPPORTED_BLOCK_EDITOR = "canEnableUnsupportedBlockEditor"
const val PROP_CAPABILITIES_MODAL_LAYOUT_PICKER = "modalLayoutPicker"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.wordpress.mobile.WPAndroidGlue;

import androidx.core.util.Consumer;

public interface ShowSuggestionsUtil {
void showUserSuggestions(Consumer<String> onResult);
void showXpostSuggestions(Consumer<String> onResult);
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class WPAndroidGlueCode {
private CountDownLatch mGetContentCountDownLatch;
private WeakReference<View> mLastFocusedView = null;
private RequestExecutor mRequestExecutor;
private AddMentionUtil mAddMentionUtil;
private ShowSuggestionsUtil mShowSuggestionsUtil;
private @Nullable Bundle mEditorTheme = null;

private static OkHttpHeaderInterceptor sAddCookiesInterceptor = new OkHttpHeaderInterceptor();
Expand Down Expand Up @@ -411,8 +411,12 @@ public void gutenbergDidSendButtonPressedAction(String buttonType) {
}

@Override
public void onAddMention(Consumer<String> onSuccess) {
mAddMentionUtil.getMention(onSuccess);
public void onShowUserSuggestions(Consumer<String> onResult) {
mShowSuggestionsUtil.showUserSuggestions(onResult);
}

@Override public void onShowXpostSuggestions(Consumer<String> onResult) {
mShowSuggestionsUtil.showXpostSuggestions(onResult);
}

@Override
Expand Down Expand Up @@ -531,7 +535,7 @@ public void attachToContainer(ViewGroup viewGroup,
OnLogGutenbergUserEventListener onLogGutenbergUserEventListener,
OnGutenbergDidRequestUnsupportedBlockFallbackListener onGutenbergDidRequestUnsupportedBlockFallbackListener,
OnGutenbergDidSendButtonPressedActionListener onGutenbergDidSendButtonPressedActionListener,
AddMentionUtil addMentionUtil,
ShowSuggestionsUtil showSuggestionsUtil,
OnStarterPageTemplatesTooltipShownEventListener onStarterPageTemplatesTooltipListener,
OnMediaFilesCollectionBasedBlockEditorListener onMediaFilesCollectionBasedBlockEditorListener,
boolean isDarkMode) {
Expand All @@ -549,7 +553,7 @@ public void attachToContainer(ViewGroup viewGroup,
mOnLogGutenbergUserEventListener = onLogGutenbergUserEventListener;
mOnGutenbergDidRequestUnsupportedBlockFallbackListener = onGutenbergDidRequestUnsupportedBlockFallbackListener;
mOnGutenbergDidSendButtonPressedActionListener = onGutenbergDidSendButtonPressedActionListener;
mAddMentionUtil = addMentionUtil;
mShowSuggestionsUtil = showSuggestionsUtil;
mOnStarterPageTemplatesTooltipShownListener = onStarterPageTemplatesTooltipListener;
mOnMediaFilesCollectionBasedBlockEditorListener = onMediaFilesCollectionBasedBlockEditorListener;

Expand Down
8 changes: 6 additions & 2 deletions packages/react-native-bridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,12 @@ export function logUserEvent( event, properties ) {
return RNReactNativeGutenbergBridge.logUserEvent( event, properties );
}

export function addMention() {
return RNReactNativeGutenbergBridge.addMention();
export function showUserSuggestions() {
return RNReactNativeGutenbergBridge.showUserSuggestions();
}

export function showXpostSuggestions() {
return RNReactNativeGutenbergBridge.showXpostSuggestions();
}

export function requestStarterPageTemplatesTooltipShown( callback ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public struct MediaInfo: Encodable {
public enum Capabilities: String {
case mediaFilesCollectionBlock
case mentions
case xposts
case unsupportedBlockEditor
case canEnableUnsupportedBlockEditor
case modalLayoutPicker
Expand Down Expand Up @@ -225,6 +226,10 @@ public protocol GutenbergBridgeDelegate: class {
/// - Parameter callback: Completion handler to be called with an user mention or an error
func gutenbergDidRequestMention(callback: @escaping (Swift.Result<String, NSError>) -> Void)

/// Tells the delegate that the editor requested a mention
/// - Parameter callback: Completion handler to be called with an xpost or an error
func gutenbergDidRequestXpost(callback: @escaping (Swift.Result<String, NSError>) -> Void)

/// Tells the delegate that the editor requested to show the tooltip
func gutenbergDidRequestStarterPageTemplatesTooltipShown() -> Bool

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ @interface RCT_EXTERN_MODULE(RNReactNativeGutenbergBridge, NSObject)
RCT_EXTERN_METHOD(requestMediaEditor:(NSString *)mediaUrl callback:(RCTResponseSenderBlock)callback)
RCT_EXTERN_METHOD(logUserEvent:(NSString *)event properties:(NSDictionary *)properties)
RCT_EXTERN_METHOD(requestUnsupportedBlockFallback:(NSString *)content blockId:(NSString *)blockId blockName:(NSString *)blockName blockTitle:(NSString *)blockTitle)
RCT_EXTERN_METHOD(addMention:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)rejecter)
RCT_EXTERN_METHOD(showUserSuggestions:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)rejecter)
RCT_EXTERN_METHOD(showXpostSuggestions:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)rejecter)
RCT_EXTERN_METHOD(requestStarterPageTemplatesTooltipShown:(RCTResponseSenderBlock)callback)
RCT_EXTERN_METHOD(setStarterPageTemplatesTooltipShown:(BOOL)tooltipShown)
RCT_EXTERN_METHOD(requestMediaFilesEditorLoad:(NSArray<NSString *> *)mediaFiles blockId:(NSString *)blockId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public class RNReactNativeGutenbergBridge: RCTEventEmitter {
}

@objc
func addMention(_ resolver: @escaping RCTPromiseResolveBlock, rejecter: @escaping RCTPromiseRejectBlock) {
func showUserSuggestions(_ resolver: @escaping RCTPromiseResolveBlock, rejecter: @escaping RCTPromiseRejectBlock) {
self.delegate?.gutenbergDidRequestMention(callback: { (result) in
switch result {
case .success(let mention):
Expand All @@ -278,6 +278,18 @@ public class RNReactNativeGutenbergBridge: RCTEventEmitter {
})
}

@objc
func showXpostSuggestions(_ resolver: @escaping RCTPromiseResolveBlock, rejecter: @escaping RCTPromiseRejectBlock) {
self.delegate?.gutenbergDidRequestXpost(callback: { (result) in
switch result {
case .success(let mention):
resolver([mention])
case .failure(let error):
rejecter(error.domain, "\(error.code)", error)
}
})
}

@objc
func requestStarterPageTemplatesTooltipShown(_ callback: @escaping RCTResponseSenderBlock) {
callback([self.delegate?.gutenbergDidRequestStarterPageTemplatesTooltipShown() ?? false])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,13 @@ public void gutenbergDidRequestUnsupportedBlockFallback(ReplaceUnsupportedBlockC
}

@Override
public void onAddMention(Consumer<String> onSuccess) {
onSuccess.accept("matt");
public void onShowUserSuggestions(Consumer<String> onResult) {
onResult.accept("matt");
}

@Override
public void onShowXpostSuggestions(Consumer<String> onResult) {
onResult.accept("ma.tt");
guarani marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ extension GutenbergViewController: GutenbergBridgeDelegate {
callback(.success("matt"))
}

func gutenbergDidRequestXpost(callback: @escaping (Result<String, NSError>) -> Void) {
callback(.success("ma.tt"))
guarani marked this conversation as resolved.
Show resolved Hide resolved
}

func gutenbergDidRequestStarterPageTemplatesTooltipShown() -> Bool {
return false;
}
Expand Down
Loading