From 999672feb29660666d5ef27e79c1f0d42d1e1692 Mon Sep 17 00:00:00 2001 From: Matt Chowning Date: Fri, 22 May 2020 14:38:24 -0400 Subject: [PATCH] Add breadcrumb for invalid selection indices --- .../src/main/java/com/gutenberg/MainApplication.java | 2 +- .../mobile/ReactNativeAztec/ReactAztecManager.java | 11 ++++++----- .../mobile/ReactNativeAztec/ReactAztecPackage.java | 6 ++++-- .../mobile/WPAndroidGlue/WPAndroidGlueCode.java | 9 ++++++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/android/app/src/main/java/com/gutenberg/MainApplication.java b/android/app/src/main/java/com/gutenberg/MainApplication.java index c6463fef84..c3243c7358 100644 --- a/android/app/src/main/java/com/gutenberg/MainApplication.java +++ b/android/app/src/main/java/com/gutenberg/MainApplication.java @@ -151,7 +151,7 @@ protected List getPackages() { new ReactSliderPackage(), new ReactVideoPackage(), new SvgPackage(), - new ReactAztecPackage(null), + new ReactAztecPackage(null, null), new LinearGradientPackage(), mRnReactNativeGutenbergBridgePackage); } diff --git a/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecManager.java b/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecManager.java index 5ccee4cd2b..013b9794ea 100644 --- a/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecManager.java +++ b/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecManager.java @@ -54,14 +54,10 @@ import org.wordpress.aztec.plugins.wpcomments.HiddenGutenbergPlugin; import org.wordpress.aztec.plugins.wpcomments.WordPressCommentsPlugin; import org.wordpress.aztec.plugins.wpcomments.toolbar.MoreToolbarButton; -import org.wordpress.aztec.spans.UnknownHtmlSpan; -import java.util.List; import java.util.Map; import java.util.ArrayList; import java.util.Arrays; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public class ReactAztecManager extends BaseViewManager { @@ -82,9 +78,11 @@ public class ReactAztecManager extends BaseViewManager exceptionLogger; + @Nullable private final Consumer breadcrumbLogger; - public ReactAztecManager(@Nullable Consumer exceptionLogger) { + public ReactAztecManager(@Nullable Consumer exceptionLogger, @Nullable Consumer breadcrumbLogger) { this.exceptionLogger = exceptionLogger; + this.breadcrumbLogger = breadcrumbLogger; initializeFocusAndBlurCommandCodes(); } @@ -247,6 +245,9 @@ private void updateSelectionIfNeeded(ReactAztecText view, @Nullable ReadableMap if (exceptionLogger != null) { exceptionLogger.accept(customException); } + if (breadcrumbLogger != null) { + breadcrumbLogger.accept(customException.getMessage()); + } } catch (Exception e) { // Should never happen, but if it does don't let logging cause a crash e.printStackTrace(); diff --git a/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecPackage.java b/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecPackage.java index 361f402dfa..a970a68d23 100644 --- a/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecPackage.java +++ b/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecPackage.java @@ -14,15 +14,17 @@ public class ReactAztecPackage implements ReactPackage { private final Consumer exceptionLogger; + private final Consumer breadcrumbLogger; - public ReactAztecPackage(Consumer exceptionLogger) { + public ReactAztecPackage(Consumer exceptionLogger, Consumer breadcrumbLogger) { this.exceptionLogger = exceptionLogger; + this.breadcrumbLogger = breadcrumbLogger; } @Override public List createViewManagers(ReactApplicationContext reactContext) { List views = new ArrayList<>(); - views.add(new ReactAztecManager(exceptionLogger)); + views.add(new ReactAztecManager(exceptionLogger, breadcrumbLogger)); return views; } diff --git a/react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java b/react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java index 6ee50d47e8..609bf6ccb8 100644 --- a/react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java +++ b/react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java @@ -102,6 +102,7 @@ public class WPAndroidGlueCode { private static OkHttpClient sOkHttpClient = new OkHttpClient.Builder().addInterceptor(sAddCookiesInterceptor).build(); private boolean mIsDarkMode; private Consumer mExceptionLogger; + private Consumer mBreadcrumbLogger; public void onCreate(Context context) { SoLoader.init(context, /* native exopackage */ false); @@ -337,7 +338,7 @@ public void logUserEvent(GutenbergUserEvent event, ReadableMap eventProperties) new MainReactPackage(getMainPackageConfig(getImagePipelineConfig(sOkHttpClient))), new SvgPackage(), new LinearGradientPackage(), - new ReactAztecPackage(mExceptionLogger), + new ReactAztecPackage(mExceptionLogger, mBreadcrumbLogger), new ReactVideoPackage(), new ReactSliderPackage(), mRnReactNativeGutenbergBridgePackage); @@ -363,9 +364,11 @@ public void onCreateView(Context initContext, Bundle translations, int colorBackground, boolean isDarkMode, - Consumer exceptionLogger) { - mExceptionLogger = exceptionLogger; + Consumer exceptionLogger, + Consumer breadcrumbLogger) { mIsDarkMode = isDarkMode; + mExceptionLogger = exceptionLogger; + mBreadcrumbLogger = breadcrumbLogger; mReactRootView = new ReactRootView(new MutableContextWrapper(initContext)); mReactRootView.setBackgroundColor(colorBackground);