-
Couldn't load subscription status.
- Fork 1
Upgrade react native 0.79.4 + Removed Mixpanel from Native Android/IOS SDKs #106
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
base: development
Are you sure you want to change the base?
Changes from 27 commits
9c53b71
b30f6fa
f4d0333
6acd2e4
2f9c755
129e071
24b1ca8
94a5d70
75bd9c3
0fc855d
145a91d
c70b0b1
63378d4
4eb3933
0e0091a
44ad07b
2a2b64d
f82d8c1
2a319f7
08de62a
42eb202
ca7ed39
8008365
767a0c2
46d9821
3691d60
9ee02e7
2b62d03
b55d7e3
d29aba7
9d19442
2832b51
27eb4fb
1e7f2a0
a17eac1
8292030
4f1a28e
4fe94b8
4949c3e
3891eee
b26c64b
eff311e
8697b0b
09f4c52
25e9221
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ buildscript { | |
| } | ||
|
|
||
| dependencies { | ||
| //noinspection GradlePluginVersion | ||
| classpath 'com.android.tools.build:gradle:3.5.3' | ||
| // noinspection DifferentKotlinGradleVersion | ||
| classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||
|
|
@@ -57,6 +58,12 @@ android { | |
| } | ||
| } | ||
|
|
||
| // Ensure React Native Android sources are locatable when opening this library standalone | ||
| if (!rootProject.ext.has('reactNativeAndroidRoot')) { | ||
| // Absolute or relative path to the app's RN Android directory | ||
| rootProject.ext.reactNativeAndroidRoot = file('../../smart_investing_react_native/node_modules/react-native/android') | ||
| } | ||
|
|
||
indrajit-roy-sc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| repositories { | ||
| mavenCentral() | ||
| google() | ||
|
|
@@ -69,7 +76,7 @@ repositories { | |
| password "reactNativeUser123" | ||
| } | ||
| } | ||
|
|
||
indrajit-roy-sc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| maven { | ||
| url "https://artifactory.smallcase.com/artifactory/SCGateway-internal" | ||
| credentials { | ||
|
|
@@ -149,8 +156,8 @@ def kotlin_version = getExtOrDefault('kotlinVersion') | |
| dependencies { | ||
| //noinspection GradleDynamicVersion | ||
| implementation 'com.facebook.react:react-native:+' // From node_modules | ||
| implementation 'com.smallcase.gateway:sdk:4.2.2' | ||
| implementation 'com.smallcase.loans:sdk:3.1.1' | ||
| implementation 'com.smallcase.gateway:sdk-sdk-extract-mixpanel-from-sdk:4.2.2-3183-release' | ||
| implementation 'com.smallcase.loans:sdk-sdk-extract-mixpanel-from-sdk:3.1.1-72-release' | ||
|
||
| implementation "androidx.core:core-ktx:1.3.1" | ||
| implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| package com.reactnativesmallcasegateway | ||
|
|
||
| import android.util.Log | ||
| import com.facebook.react.bridge.* | ||
| import com.facebook.react.modules.core.DeviceEventManagerModule | ||
| import com.facebook.react.bridge.UiThreadUtil | ||
| import com.smallcase.gateway.data.listeners.NotificationCenter | ||
| import com.smallcase.gateway.data.listeners.Notification | ||
| import com.smallcase.gateway.portal.SmallcaseGatewaySdk | ||
| import com.smallcase.gateway.portal.ScgNotification | ||
|
|
||
| class SCGatewayBridgeEmitter(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { | ||
|
|
||
| companion object { | ||
| const val TAG = "SCGatewayBridgeEmitter" | ||
| const val ANALYTICS_EVENT = ScgNotification.ANALYTICS_EVENT | ||
| const val SUPER_PROPERTIES_UPDATED = ScgNotification.SUPER_PROPS_UPDATED | ||
| const val USER_RESET = ScgNotification.USER_RESET | ||
| const val USER_IDENTIFY = ScgNotification.USER_IDENTIFY | ||
indrajit-roy-sc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
indrajit-roy-sc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private var notificationObserver: ((Notification) -> Unit)? = null | ||
|
|
||
| private val isListening: Boolean | ||
| get() = notificationObserver != null | ||
|
|
||
| override fun getName(): String = "SCGatewayBridgeEmitter" | ||
|
|
||
| override fun getConstants(): MutableMap<String, Any> { | ||
| return hashMapOf( | ||
| "ANALYTICS_EVENT" to ScgNotification.ANALYTICS_EVENT, | ||
| "SUPER_PROPERTIES_UPDATED" to ScgNotification.SUPER_PROPS_UPDATED, | ||
| "USER_RESET" to ScgNotification.USER_RESET, | ||
| "USER_IDENTIFY" to ScgNotification.USER_IDENTIFY | ||
| ) | ||
| } | ||
|
|
||
| init { | ||
| UiThreadUtil.runOnUiThread { | ||
| startListening() | ||
| } | ||
| } | ||
|
|
||
| @ReactMethod | ||
| fun startListening(promise: Promise? = null) { | ||
| try { | ||
| Log.d(TAG, "startListening called") | ||
|
|
||
| if (isListening) { | ||
| Log.d(TAG, "Already listening to events") | ||
| promise?.resolve("Already listening") | ||
| return | ||
| } | ||
|
|
||
| UiThreadUtil.runOnUiThread { | ||
| try { | ||
| Log.d(TAG, "Starting listener on thread: ${Thread.currentThread().name}") | ||
|
|
||
| notificationObserver = { notification -> | ||
| Log.d(TAG, "Received notification: ${notification.name}") | ||
|
|
||
| try { | ||
| processScgNotification(notification) | ||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Error processing notification: ${notification.name}", e) | ||
| } | ||
| } | ||
|
|
||
| notificationObserver?.let { observer -> | ||
| NotificationCenter.addObserver(observer) | ||
| Log.d(TAG, "Successfully started listening for notifications") | ||
| promise?.resolve("Started listening successfully") | ||
| } ?: run { | ||
| promise?.reject("START_LISTENING_ERROR", "Failed to create observer") | ||
| } | ||
|
|
||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Error starting listener", e) | ||
| promise?.reject("START_LISTENING_ERROR", e.message ?: "Unknown error", e) | ||
| } | ||
| } | ||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Error in startListening", e) | ||
| promise?.reject("START_LISTENING_ERROR", e.message ?: "Unknown error", e) | ||
| } | ||
| } | ||
|
|
||
| private fun processScgNotification(notification: Notification) { | ||
| try { | ||
| val jsonString = notification.userInfo?.get(ScgNotification.STRINGIFIED_PAYLOAD_KEY) as? String | ||
| if (jsonString == null) { | ||
| Log.e(TAG, "SCGatewayBridgeEmitter: Invalid notification object - expected JSON string") | ||
| return | ||
| } | ||
|
|
||
| sendEvent(SmallcaseGatewaySdk.SCG_NOTIFICATION_NAME, jsonString) | ||
|
|
||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Error processing SCG notification", e) | ||
| } | ||
| } | ||
|
|
||
| private fun sendEvent(eventName: String, jsonString: String) { | ||
| try { | ||
| if (reactContext.hasActiveCatalystInstance()) { | ||
| reactContext | ||
| .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) | ||
| .emit(eventName, jsonString) | ||
| } else { | ||
| Log.w(TAG, "React context not active, cannot send event: $eventName") | ||
| } | ||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Error sending event to React Native: $eventName", e) | ||
| } | ||
| } | ||
|
|
||
| @ReactMethod | ||
| fun stopListening(promise: Promise) { | ||
| try { | ||
| if (!isListening) { | ||
| promise.resolve("Not listening") | ||
| return | ||
| } | ||
|
|
||
| UiThreadUtil.runOnUiThread { | ||
| try { | ||
| notificationObserver?.let { observer -> | ||
| NotificationCenter.removeObserver(observer) | ||
| notificationObserver = null | ||
| promise.resolve("Stopped listening successfully") | ||
| } ?: run { | ||
| promise.resolve("No observer to remove") | ||
| } | ||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Error stopping listener", e) | ||
| promise.reject("STOP_LISTENING_ERROR", e.message ?: "Unknown error", e) | ||
| } | ||
| } | ||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Error in stopListening", e) | ||
| promise.reject("STOP_LISTENING_ERROR", e.message ?: "Unknown error", e) | ||
| } | ||
| } | ||
|
|
||
| override fun onCatalystInstanceDestroy() { | ||
| super.onCatalystInstanceDestroy() | ||
| try { | ||
| if (isListening) { | ||
| notificationObserver?.let { observer -> | ||
| NotificationCenter.removeObserver(observer) | ||
| } | ||
| notificationObserver = null | ||
| } | ||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Error during cleanup", e) | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| package com.reactnativesmallcasegateway | ||
|
|
||
| import android.util.Log | ||
| import com.facebook.react.bridge.* | ||
| import com.facebook.react.modules.core.DeviceEventManagerModule | ||
| import com.facebook.react.bridge.UiThreadUtil | ||
| import com.smallcase.loans.data.listeners.NotificationCenter | ||
| import com.smallcase.loans.data.listeners.Notification | ||
| import com.smallcase.loans.core.external.ScLoanNotification | ||
|
|
||
|
|
||
| class SCLoansBridgeEmitter(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { | ||
|
|
||
| companion object { | ||
| const val TAG = "SCLoansBridgeEmitter" | ||
|
|
||
| const val ANALYTICS_EVENT = ScLoanNotification.ANALYTICS_EVENT | ||
| const val SUPER_PROPERTIES_UPDATED = ScLoanNotification.SUPER_PROPS_UPDATED | ||
indrajit-roy-sc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private var notificationObserver: ((Notification) -> Unit)? = null | ||
|
|
||
| private val isListening: Boolean | ||
| get() = notificationObserver != null | ||
|
|
||
| override fun getName(): String = "SCLoansBridgeEmitter" | ||
|
|
||
| override fun getConstants(): MutableMap<String, Any> { | ||
| return hashMapOf( | ||
| "ANALYTICS_EVENT" to ScLoanNotification.ANALYTICS_EVENT, | ||
| "SUPER_PROPERTIES_UPDATED" to ScLoanNotification.SUPER_PROPS_UPDATED, | ||
| ) | ||
| } | ||
|
|
||
| init { | ||
| UiThreadUtil.runOnUiThread { | ||
| startListening() | ||
| } | ||
| } | ||
|
|
||
| @ReactMethod | ||
| fun startListening(promise: Promise? = null) { | ||
| try { | ||
| Log.d(TAG, "startListening called") | ||
|
|
||
| if (isListening) { | ||
| Log.d(TAG, "Already listening to events") | ||
| promise?.resolve("Already listening") | ||
| return | ||
| } | ||
|
|
||
| UiThreadUtil.runOnUiThread { | ||
| try { | ||
| Log.d(TAG, "Starting listener on thread: ${Thread.currentThread().name}") | ||
|
|
||
| notificationObserver = { notification -> | ||
| Log.d(TAG, "Received notification: ${notification.name}") | ||
|
|
||
| try { | ||
| processScLoansNotification(notification) | ||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Error processing notification: ${notification.name}", e) | ||
| } | ||
| } | ||
|
|
||
| notificationObserver?.let { observer -> | ||
| NotificationCenter.addObserver(observer) | ||
| Log.d(TAG, "Successfully started listening for notifications") | ||
| promise?.resolve("Started listening successfully") | ||
| } ?: run { | ||
| promise?.reject("START_LISTENING_ERROR", "Failed to create observer") | ||
| } | ||
|
|
||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Error starting listener", e) | ||
| promise?.reject("START_LISTENING_ERROR", e.message ?: "Unknown error", e) | ||
| } | ||
| } | ||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Error in startListening", e) | ||
| promise?.reject("START_LISTENING_ERROR", e.message ?: "Unknown error", e) | ||
| } | ||
| } | ||
|
|
||
| @ReactMethod | ||
| fun stopListening(promise: Promise) { | ||
| try { | ||
| if (!isListening) { | ||
| promise.resolve("Not listening") | ||
| return | ||
| } | ||
|
|
||
| UiThreadUtil.runOnUiThread { | ||
| try { | ||
| notificationObserver?.let { observer -> | ||
| NotificationCenter.removeObserver(observer) | ||
| notificationObserver = null | ||
| promise.resolve("Stopped listening successfully") | ||
| } ?: run { | ||
| promise.resolve("No observer to remove") | ||
| } | ||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Error stopping listener on UI thread", e) | ||
| promise.reject("STOP_LISTENING_ERROR", e.message, e) | ||
| } | ||
| } | ||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Error scheduling stopListening on UI thread", e) | ||
| promise.reject("STOP_LISTENING_ERROR", e.message, e) | ||
| } | ||
| } | ||
|
|
||
| @ReactMethod | ||
| fun getListeningStatus(promise: Promise) { | ||
| try { | ||
| val status = Arguments.createMap().apply { | ||
| putBoolean("isListening", isListening) | ||
| putBoolean("hasNotificationObserver", notificationObserver != null) | ||
indrajit-roy-sc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| promise.resolve(status) | ||
| } catch (e: Exception) { | ||
| promise.reject("STATUS_ERROR", e.message, e) | ||
| } | ||
| } | ||
|
|
||
| private fun processScLoansNotification(notification: Notification) { | ||
| try { | ||
| val jsonString = notification.userInfo?.get(ScLoanNotification.STRINGIFIED_PAYLOAD_KEY) as? String | ||
| if (jsonString == null) { | ||
| Log.e(TAG, "SCLoansBridgeEmitter: Invalid notification object - expected JSON string") | ||
| return | ||
| } | ||
|
|
||
| sendEvent("scloans_notification", jsonString) | ||
|
|
||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Error processing SCLoans notification", e) | ||
| } | ||
| } | ||
|
|
||
| private fun sendEvent(eventName: String, jsonString: String) { | ||
| try { | ||
| if (reactContext.hasActiveCatalystInstance()) { | ||
| reactContext | ||
| .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) | ||
| .emit(eventName, jsonString) | ||
indrajit-roy-sc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } else { | ||
| Log.w(TAG, "React context not active, cannot send event: $eventName") | ||
| } | ||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Error sending event to React Native: $eventName", e) | ||
| } | ||
| } | ||
indrajit-roy-sc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| override fun onCatalystInstanceDestroy() { | ||
| super.onCatalystInstanceDestroy() | ||
| try { | ||
| if (isListening) { | ||
| notificationObserver?.let { observer -> | ||
| NotificationCenter.removeObserver(observer) | ||
| } | ||
| notificationObserver = null | ||
| } | ||
| } catch (e: Exception) { | ||
| Log.e(TAG, "Error during cleanup", e) | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.