Skip to content

Commit

Permalink
Add support for xpost suggestions on mobile (#26211)
Browse files Browse the repository at this point in the history
* Add support for xpost suggestions on mobile
* Check for trigger key codes at beginning of lines
* Add xposts capability handling
* Add Xpost to toolbar via long-press on @-mentions
* Long-pressing the @-mentions toolbar button will now let the user add an Xpost or an @-mention
* Dynamically update suggestions button
* Extract suggestions format button component
* Update mobile snapshot tests to remove Modal
* Enable xposts in Android demo app
* Enable xposts in iOS demo app
* Add change log item for cross-posts
Co-authored-by: Paul Von Schrottky <[email protected]>
  • Loading branch information
mchowning authored Dec 23, 2020
1 parent 4b14897 commit db9da4a
Show file tree
Hide file tree
Showing 16 changed files with 211 additions and 68 deletions.
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
4 changes: 4 additions & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ For each user feature we should also add a importance categorization label to i
* [*] Fix theme colors syncing with the editor [#26821]
* [**] Fix issue where a blocks would disappear when deleting all of the text inside without requiring the extra backspace to remove the block. [#27583]

## 1.44.0

* [***] Add support for cross-posting between sites

## 1.41.0

* [***] Faster editor start and overall operation on Android [#26732]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected Bundle getLaunchOptions() {
Bundle bundle = new Bundle();
Bundle capabilities = new Bundle();
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_MENTIONS, true);
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_XPOSTS, true);
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_UNSUPPORTED_BLOCK_EDITOR, true);
bundle.putBundle(GutenbergProps.PROP_CAPABILITIES, capabilities);
return bundle;
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");
}

@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"))
}

func gutenbergDidRequestStarterPageTemplatesTooltipShown() -> Bool {
return false;
}
Expand Down Expand Up @@ -298,6 +302,7 @@ extension GutenbergViewController: GutenbergBridgeDataSource {
func gutenbergCapabilities() -> [Capabilities : Bool] {
return [
.mentions: true,
.xposts: true,
.unsupportedBlockEditor: unsupportedBlockEnabled,
.canEnableUnsupportedBlockEditor: unsupportedBlockCanBeActivated,
.mediaFilesCollectionBlock: true,
Expand Down
Loading

0 comments on commit db9da4a

Please sign in to comment.