Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup node JS
uses: actions/setup-node@v2
with:
node-version: 14
node-version: 18
Comment thread
sergeysozinov marked this conversation as resolved.
registry-url: https://registry.npmjs.org

- name: Setup local environment
Expand All @@ -39,7 +39,7 @@ jobs:
- name: Setup node JS
uses: actions/setup-node@v2
with:
node-version: 14
node-version: 18
registry-url: https://registry.npmjs.org

- name: Setup local environment
Expand Down
134 changes: 43 additions & 91 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,130 +1,82 @@
buildscript {
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['MindboxSdk_kotlinVersion']
ext.safeExtGet = { prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath('com.android.tools.build:gradle:8.6.0')
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', '1.9.22')}")
}
}

apply plugin: "com.facebook.react"
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

def getExtOrDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['MindboxSdk_' + name]
def readBooleanGradleProperty = { String name ->
def value = project.findProperty(name)
if (value == null) {
value = rootProject.findProperty(name)
}
if (value == null) {
return null
}
return value.toString().toBoolean()
}

def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['MindboxSdk_' + name]).toInteger()
def isNewArchEnabled = readBooleanGradleProperty("newArchEnabled")

if (isNewArchEnabled == false) {
throw new GradleException(
"${project.name}: Mindbox SDK supports only React Native New Architecture on Android.\n" +
"Remove `newArchEnabled=false` from gradle.properties or enable the New Architecture."
Comment thread
sergeysozinov marked this conversation as resolved.
)
}

android {
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
buildToolsVersion getExtOrDefault('buildToolsVersion')
namespace 'com.mindboxsdk'
compileSdkVersion safeExtGet('compileSdkVersion', 35)

defaultConfig {
minSdkVersion 21
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
minSdkVersion safeExtGet('minSdkVersion', 24)
targetSdkVersion safeExtGet('targetSdkVersion', 35)
versionCode 1
versionName "1.0"
versionName '1.0'
consumerProguardFiles 'consumer-rules.pro'
}

buildTypes {
release {
minifyEnabled false
}
}
lintOptions {
disable 'GradleCompatible'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}

repositories {
mavenCentral()
google()

def found = false
def defaultDir = null
def androidSourcesName = 'React Native sources'

if (rootProject.ext.has('reactNativeAndroidRoot')) {
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
} else {
defaultDir = new File(
projectDir,
'/../../../node_modules/react-native/android'
)
kotlinOptions {
jvmTarget = '17'
}

if (defaultDir.exists()) {
maven {
url defaultDir.toString()
name androidSourcesName
sourceSets {
main {
java.srcDirs += ["$buildDir/generated/source/codegen/java"]
}

logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
found = true
} else {
def parentDir = rootProject.projectDir

1.upto(5, {
if (found) return true
parentDir = parentDir.parentFile

def androidSourcesDir = new File(
parentDir,
'node_modules/react-native'
)

def androidPrebuiltBinaryDir = new File(
parentDir,
'node_modules/react-native/android'
)

if (androidPrebuiltBinaryDir.exists()) {
maven {
url androidPrebuiltBinaryDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
found = true
} else if (androidSourcesDir.exists()) {
maven {
url androidSourcesDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
found = true
}
})
}

if (!found) {
throw new GradleException(
"${project.name}: unable to locate React Native android sources. " +
"Ensure you have you installed React Native as a dependency in your project and try again."
)
lintOptions {
abortOnError false
}
}

def kotlin_version = getExtOrDefault('kotlinVersion')
repositories {
mavenCentral()
google()
}

dependencies {
// noinspection GradleDynamicVersion
api 'com.facebook.react:react-native:+'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.facebook.react:react-native:+'
Comment thread
sergeysozinov marked this conversation as resolved.
implementation "org.jetbrains.kotlin:kotlin-stdlib:${safeExtGet('kotlinVersion', '1.9.22')}"
api 'cloud.mindbox:mobile-sdk:2.15.0'
}
13 changes: 4 additions & 9 deletions android/src/main/java/com/mindboxsdk/MindboxEventEmitter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ package com.mindboxsdk

import android.app.Activity
import android.app.Application
import android.content.Context
import android.content.Intent
import android.util.Log
import com.facebook.react.ReactApplication
import com.facebook.react.ReactInstanceManager
import com.facebook.react.bridge.ReactContext
import com.facebook.react.ReactActivity
import cloud.mindbox.mobile_sdk.Mindbox
import cloud.mindbox.mobile_sdk.logger.Level

internal class MindboxEventEmitter (
private val application: Application
internal class MindboxEventEmitter(
private val application: Application,
) : MindboxEventSubscriber {

private var jsDelivery: MindboxJsDelivery? = null
Expand All @@ -33,7 +28,7 @@ internal class MindboxEventEmitter (
jsDelivery?.sendPushClicked(intent)
}

private fun handleActivityCreated(reactContext:ReactContext, activity: Activity) {
private fun handleActivityCreated(reactContext: ReactContext, activity: Activity) {
Mindbox.writeLog("[RN] Handle activity created", Level.INFO)
runCatching {
reactContext.let { reactContext ->
Expand All @@ -45,7 +40,7 @@ internal class MindboxEventEmitter (
private fun initializeAndSendIntent(context: ReactContext, activity: Activity) {
Mindbox.writeLog("[RN] Initialize MindboxJsDelivery", Level.INFO)
jsDelivery = MindboxJsDelivery.Shared.getInstance(context)
val currentActivity = context.currentActivity ?: activity
val currentActivity: Activity = context.currentActivity ?: activity
currentActivity.intent?.let { handleNewIntent(context, it) }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.mindboxsdk

internal interface MindboxEventSubscriber {
internal fun interface MindboxEventSubscriber {
fun onEvent(event: MindboxSdkLifecycleEvent)
}
83 changes: 37 additions & 46 deletions android/src/main/java/com/mindboxsdk/MindboxJsDelivery.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,58 @@ package com.mindboxsdk
import android.content.Intent
import android.os.Bundle
import com.facebook.react.bridge.ReactContext
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
import org.json.JSONObject
import kotlin.properties.Delegates
import cloud.mindbox.mobile_sdk.Mindbox
import cloud.mindbox.mobile_sdk.logger.Level

class MindboxJsDelivery private constructor(private val mReactContext: ReactContext) {
companion object Shared {
private var INSTANCE: MindboxJsDelivery? = null
private var delayedIntent: Intent? = null
companion object Shared {
private var INSTANCE: MindboxJsDelivery? = null
private var delayedIntent: Intent? = null

var hasListeners: Boolean by Delegates.observable(false) { _, _, newValue ->
if (newValue) {
delayedIntent?.let {
it.extras?.let {
Mindbox.writeLog("[RN] Send push data from delayed ${it}", Level.INFO)
var hasListeners: Boolean by Delegates.observable(false) { _, _, newValue ->
Mindbox.writeLog("[RN][MindboxJsDelivery] hasListeners=$newValue", Level.DEBUG)
if (newValue) {
delayedIntent?.let { intent ->
intent.extras?.let {
Mindbox.writeLog("[RN] Send push data from delayed ${it}", Level.INFO)
}
INSTANCE?.sendPushClicked(intent)
}
}
INSTANCE?.sendPushClicked(it)
delayedIntent = null
}
}
delayedIntent = null
}

fun getInstance(reactContext: ReactContext): MindboxJsDelivery? {
if (INSTANCE == null) {
synchronized(MindboxJsDelivery::class.java) {
if (INSTANCE == null) {
INSTANCE = MindboxJsDelivery(reactContext)
}
fun getInstance(reactContext: ReactContext): MindboxJsDelivery? {
if (INSTANCE == null) {
synchronized(MindboxJsDelivery::class.java) {
if (INSTANCE == null) {
INSTANCE = MindboxJsDelivery(reactContext)
}
}
}
return INSTANCE
}
}

return INSTANCE
}
}

private fun sendEvent(eventName: String, bundle: Bundle) {
if (mReactContext.hasActiveCatalystInstance()) {
var payload = JSONObject();
payload.put("pushUrl", bundle.getString("push_url", ""));
payload.put("pushPayload", bundle.getString("push_payload", ""));
Mindbox.writeLog("[RN] Send push data to listener with ${payload.toString()}", Level.INFO)
mReactContext
.getJSModule(RCTDeviceEventEmitter::class.java)
.emit(eventName, payload.toString())
private fun sendEvent(eventName: String, bundle: Bundle) {
Mindbox.writeLog("[RN][MindboxJsDelivery] sendEvent($eventName) push_url=${bundle.getString("push_url")}", Level.INFO)
MindboxSdkModule.deliverPushNotificationClickedFromExternal(bundle, mReactContext)
}
Comment thread
sergeysozinov marked this conversation as resolved.
}

fun sendPushClicked(intent: Intent) {
if (hasListeners) {
val bundle = intent.extras
if (bundle != null) {
val key = bundle.getString("uniq_push_key")
if (key != null) {
sendEvent("pushNotificationClicked", bundle)
fun sendPushClicked(intent: Intent) {
if (hasListeners) {
val bundle = intent.extras
if (bundle != null) {
val key = bundle.getString("uniq_push_key")
if (key != null) {
sendEvent("pushNotificationClicked", bundle)
} else {
Mindbox.writeLog("[RN] Push without uniq_push_key — ignored", Level.INFO)
}
}
} else {
Mindbox.writeLog("[RN] Push was received without uniq_push_key it is not our push", Level.INFO)
delayedIntent = intent
}
}
} else {
delayedIntent = intent
}
}
}
Loading
Loading