@sentiance-react-native/core 6.15.0-rc.3 → 6.15.0-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ sentiance_sdk_env_var_version = ENV["SENTIANCE_RN_IOS_SDK_VERSION"]
5
5
 
6
6
  Pod::Spec.new do |s|
7
7
  s.name = "RNSentianceCore"
8
- s.version = "6.15.0-rc.3"
8
+ s.version = "6.15.0-rc.5"
9
9
  s.summary = "RNSentianceCore"
10
10
  s.description = <<-DESC
11
11
  RNSentianceCore
@@ -1,14 +1,26 @@
1
1
  plugins {
2
- id "com.android.library"
2
+ id "com.android.library"
3
3
  }
4
4
 
5
5
  android {
6
- namespace "com.sentiance.react.bridge.core"
6
+ namespace "com.sentiance.react.bridge.core"
7
7
 
8
- compileOptions {
9
- sourceCompatibility JavaVersion.VERSION_1_8
10
- targetCompatibility JavaVersion.VERSION_1_8
11
- }
8
+ compileOptions {
9
+ sourceCompatibility JavaVersion.VERSION_1_8
10
+ targetCompatibility JavaVersion.VERSION_1_8
11
+ }
12
+
13
+ buildFeatures {
14
+ buildConfig = true
15
+ }
16
+
17
+ def isNewArchEnabled =
18
+ (project.findProperty('newArchEnabled') ?: "false").toBoolean()
19
+
20
+ defaultConfig {
21
+ consumerProguardFiles 'rules-consumer.pro'
22
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchEnabled.toString()
23
+ }
12
24
  }
13
25
 
14
26
  apply from: "$project.projectDir/package-json-reader.gradle"
@@ -19,12 +31,12 @@ applyAndroidVersionsFrom(packageJson)
19
31
  def sentianceSdkVersion = getSentianceSdkVersion()
20
32
 
21
33
  dependencies {
22
- implementation(platform("com.sentiance:sdk-bom:${sentianceSdkVersion}"))
23
- api("com.sentiance:sdk") { transitive = true }
34
+ implementation(platform("com.sentiance:sdk-bom:${sentianceSdkVersion}"))
35
+ api("com.sentiance:sdk") { transitive = true }
24
36
 
25
- if (findProject(':test-common')) {
26
- testImplementation project(':test-common')
27
- }
37
+ if (findProject(':test-common')) {
38
+ testImplementation project(':test-common')
39
+ }
28
40
  }
29
41
 
30
42
  applyReactNativeDependency()
@@ -0,0 +1,4 @@
1
+ -keepclassmembers class com.sentiance.react.bridge.core.BuildConfig {
2
+ public static final boolean IS_NEW_ARCHITECTURE_ENABLED;
3
+ }
4
+ -keep class com.sentiance.react.bridge.core.BuildConfig
@@ -4,56 +4,53 @@ import android.content.Context;
4
4
  import android.os.Handler;
5
5
  import android.os.Looper;
6
6
 
7
- import com.facebook.react.ReactApplication;
8
- import com.facebook.react.ReactNativeHost;
7
+ import androidx.annotation.NonNull;
8
+ import androidx.annotation.Nullable;
9
+
9
10
  import com.facebook.react.bridge.ReactContext;
10
11
  import com.facebook.react.bridge.WritableMap;
11
12
  import com.facebook.react.modules.core.DeviceEventManagerModule;
13
+ import com.sentiance.react.bridge.core.common.util.ReactContextProvider;
12
14
 
13
15
  public abstract class AbstractSentianceEmitter {
14
16
 
15
- protected final Handler mHandler = new Handler(Looper.getMainLooper());
16
- protected ReactContext reactContext;
17
- protected ReactNativeHost reactNativeHost;
18
-
19
- protected AbstractSentianceEmitter(Context context) {
20
- ReactApplication reactApplication = ((ReactApplication) context.getApplicationContext());
21
- reactNativeHost = reactApplication.getReactNativeHost();
22
- reactContext = createReactContext();
23
- }
24
-
25
- protected ReactContext createReactContext() {
26
- if (!reactNativeHost.getReactInstanceManager().hasStartedCreatingInitialContext())
27
- reactNativeHost.getReactInstanceManager().createReactContextInBackground();
28
- return reactNativeHost.getReactInstanceManager().getCurrentReactContext();
29
- }
30
-
31
- protected void sendEvent(final String key, final WritableMap map) {
32
- if (reactContext != null && reactContext.hasActiveCatalystInstance()) {
33
- this.reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(key, map);
34
- } else {
35
- // add delay
36
- final Counter retry = new Counter(20);
37
- mHandler.postDelayed(new Runnable() {
38
- @Override
39
- public void run() {
40
- if (AbstractSentianceEmitter.this.reactContext == null)
41
- AbstractSentianceEmitter.this.reactContext = createReactContext();
42
- if (AbstractSentianceEmitter.this.reactContext != null && AbstractSentianceEmitter.this.reactContext.hasActiveCatalystInstance()) {
43
- AbstractSentianceEmitter.this.reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(key, map);
44
- } else if (retry.count-- > 0) {
45
- mHandler.postDelayed(this, 500);
46
- }
17
+ protected final Handler mHandler = new Handler(Looper.getMainLooper());
18
+ @Nullable
19
+ protected ReactContext reactContext;
20
+ @NonNull
21
+ protected ReactContextProvider reactContextProvider;
22
+
23
+ protected AbstractSentianceEmitter(Context context) {
24
+ reactContextProvider = new ReactContextProvider(context.getApplicationContext());
25
+ reactContext = reactContextProvider.createReactContext();
26
+ }
27
+
28
+ protected void sendEvent(final String key, final WritableMap map) {
29
+ if (reactContext != null && reactContext.hasActiveCatalystInstance()) {
30
+ this.reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(key, map);
31
+ } else {
32
+ // add delay
33
+ final Counter retry = new Counter(20);
34
+ mHandler.postDelayed(new Runnable() {
35
+ @Override
36
+ public void run() {
37
+ if (AbstractSentianceEmitter.this.reactContext == null)
38
+ AbstractSentianceEmitter.this.reactContext = reactContextProvider.createReactContext();
39
+ if (AbstractSentianceEmitter.this.reactContext != null && AbstractSentianceEmitter.this.reactContext.hasActiveCatalystInstance()) {
40
+ AbstractSentianceEmitter.this.reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(key, map);
41
+ } else if (retry.count-- > 0) {
42
+ mHandler.postDelayed(this, 500);
43
+ }
44
+ }
45
+ }, 500);
47
46
  }
48
- }, 500);
49
47
  }
50
- }
51
48
 
52
- private static class Counter {
53
- int count;
49
+ private static class Counter {
50
+ int count;
54
51
 
55
- Counter(int count) {
56
- this.count = count;
52
+ Counter(int count) {
53
+ this.count = count;
54
+ }
57
55
  }
58
- }
59
56
  }
@@ -0,0 +1,72 @@
1
+ package com.sentiance.react.bridge.core.common.util;
2
+
3
+ import android.content.Context;
4
+ import android.util.Log;
5
+
6
+ import androidx.annotation.Nullable;
7
+
8
+ import com.facebook.react.ReactApplication;
9
+ import com.facebook.react.ReactNativeHost;
10
+ import com.facebook.react.bridge.ReactContext;
11
+ import com.sentiance.react.bridge.core.BuildConfig;
12
+
13
+ public final class ReactContextProvider {
14
+
15
+ private static final String TAG = "ReactNativeContextProvider";
16
+
17
+ private final ReactApplication mReactApplication;
18
+
19
+ public ReactContextProvider(Context applicationContext) {
20
+ mReactApplication = (ReactApplication) applicationContext;
21
+ }
22
+
23
+ /**
24
+ * Triggers the initialization of a React context if it is not initializing already,
25
+ * or returns the current React context if it is already initialized.
26
+ *
27
+ * If this call does end up triggering the initialization of a React context,
28
+ * then it will probably return <code>null</code> since the operation is asynchronous.
29
+ *
30
+ * @return a ReactContext if it exists, null otherwise.
31
+ */
32
+ @Nullable
33
+ public ReactContext createReactContext() {
34
+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
35
+ return createReactContextInNewArchMode();
36
+ } else {
37
+ return createReactContextInLegacyArchMode();
38
+ }
39
+ }
40
+
41
+ @Nullable
42
+ private ReactContext createReactContextInNewArchMode() {
43
+ try {
44
+ java.lang.reflect.Method getReactHost = mReactApplication.getClass().getMethod("getReactHost");
45
+ Object reactHost = getReactHost.invoke(mReactApplication);
46
+ Class<?> reactHostClass = Class.forName("com.facebook.react.ReactHost");
47
+
48
+ java.lang.reflect.Method start = reactHostClass.getMethod("start");
49
+ java.lang.reflect.Method getCurrentReactContext = reactHostClass.getMethod("getCurrentReactContext");
50
+
51
+ // Trigger the initialization of a React context, should be safe to call multiple times
52
+ // https://github.com/facebook/react-native/blob/main/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.kt#L723
53
+ start.invoke(reactHost);
54
+
55
+ return (ReactContext) getCurrentReactContext.invoke(reactHost);
56
+ } catch (Throwable t) {
57
+ Log.d(TAG, "Failed to create React context");
58
+ return null;
59
+ }
60
+ }
61
+
62
+ @Nullable
63
+ private ReactContext createReactContextInLegacyArchMode() {
64
+ ReactNativeHost reactNativeHost = mReactApplication.getReactNativeHost();
65
+
66
+ // Trigger the initialization of a React context
67
+ if (!reactNativeHost.getReactInstanceManager().hasStartedCreatingInitialContext())
68
+ reactNativeHost.getReactInstanceManager().createReactContextInBackground();
69
+
70
+ return reactNativeHost.getReactInstanceManager().getCurrentReactContext();
71
+ }
72
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentiance-react-native/core",
3
- "version": "6.15.0-rc.3",
3
+ "version": "6.15.0-rc.5",
4
4
  "description": "The Sentiance Core library",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",