From a7482fd09b7aed5e50392d287df60cbfc6a3cd72 Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Sun, 7 Jul 2024 13:37:51 +0200 Subject: [PATCH] Fix #1831: Run MethodChannel messages on UI Thread --- packages/stripe_android/CHANGELOG.md | 4 ++++ .../react/modules/core/DeviceEventManagerModule.java | 6 +++++- packages/stripe_android/pubspec.yaml | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/stripe_android/CHANGELOG.md b/packages/stripe_android/CHANGELOG.md index 6dbf2ec72..7f8896449 100644 --- a/packages/stripe_android/CHANGELOG.md +++ b/packages/stripe_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 10.2.1 +**Fixes** +- Run method channel messages on UI Thread to prevent crash (#1831) + ## 10.2.0 **Features** diff --git a/packages/stripe_android/android/src/main/kotlin/com/facebook/react/modules/core/DeviceEventManagerModule.java b/packages/stripe_android/android/src/main/kotlin/com/facebook/react/modules/core/DeviceEventManagerModule.java index b75e763ac..d86c5f732 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/facebook/react/modules/core/DeviceEventManagerModule.java +++ b/packages/stripe_android/android/src/main/kotlin/com/facebook/react/modules/core/DeviceEventManagerModule.java @@ -1,11 +1,15 @@ package com.facebook.react.modules.core; +import android.os.Handler; +import android.os.Looper; + import com.facebook.react.bridge.WritableMap; import io.flutter.plugin.common.MethodChannel; public class DeviceEventManagerModule { public static class RCTDeviceEventEmitter { + private Handler uiThreadHandler = new Handler(Looper.getMainLooper()); private final MethodChannel channel; @@ -14,7 +18,7 @@ public RCTDeviceEventEmitter(MethodChannel channel) { } public void emit(String eventName, WritableMap params) { - channel.invokeMethod(eventName, params); + uiThreadHandler.post(() -> channel.invokeMethod(eventName, params)); } } } diff --git a/packages/stripe_android/pubspec.yaml b/packages/stripe_android/pubspec.yaml index ae6506668..28d370ca3 100644 --- a/packages/stripe_android/pubspec.yaml +++ b/packages/stripe_android/pubspec.yaml @@ -1,6 +1,6 @@ name: stripe_android description: Stripe platform implementation for Android -version: 10.2.0 +version: 10.2.1 repository: https://github.com/flutter-stripe/flutter_stripe homepage: https://pub.dev/packages/flutter_stripe