Skip to content

Commit

Permalink
Merge pull request #37 from allboatsrise/chore/expo-51-support
Browse files Browse the repository at this point in the history
chore - add expo 51 support
  • Loading branch information
andrejpavlovic authored May 17, 2024
2 parents 92c6f16 + 1ae7b9a commit 33c8920
Show file tree
Hide file tree
Showing 4 changed files with 971 additions and 672 deletions.
96 changes: 25 additions & 71 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,99 +1,53 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'maven-publish'

group = 'expo.modules.marketingcloudsdk'
version = '50.2.1'

buildscript {
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
if (expoModulesCorePlugin.exists()) {
apply from: expoModulesCorePlugin
applyKotlinExpoModulesCorePlugin()
}

// Simple helper that allows the root project to override versions declared by this library.
ext.safeExtGet = { prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

// Ensures backward compatibility
ext.getKotlinVersion = {
if (ext.has("kotlinVersion")) {
ext.kotlinVersion()
} else {
ext.safeExtGet("kotlinVersion", "1.8.10")
version = '51.0.0'

def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
apply from: expoModulesCorePlugin
applyKotlinExpoModulesCorePlugin()
useCoreDependencies()
useExpoPublishing()

// If you want to use the managed Android SDK versions from expo-modules-core, set this to true.
// The Android SDK versions will be bumped from time to time in SDK releases and may introduce breaking changes in your module code.
// Most of the time, you may like to manage the Android SDK versions yourself.
def useManagedAndroidSdkVersions = false
if (useManagedAndroidSdkVersions) {
useDefaultAndroidSdkVersions()
} else {
buildscript {
// Simple helper that allows the root project to override versions declared by this library.
ext.safeExtGet = { prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
}

repositories {
mavenCentral()
}

dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
}
}

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release
}
}
repositories {
maven {
url = mavenLocal().url
}
project.android {
compileSdkVersion safeExtGet("compileSdkVersion", 34)
defaultConfig {
minSdkVersion safeExtGet("minSdkVersion", 21)
targetSdkVersion safeExtGet("targetSdkVersion", 34)
}
}
}

android {
compileSdkVersion safeExtGet("compileSdkVersion", 33)

def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
if (agpVersion.tokenize('.')[0].toInteger() < 8) {
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.majorVersion
freeCompilerArgs += [
"-Xjvm-default=all",
]
}
}

namespace "expo.modules.marketingcloudsdk"
defaultConfig {
minSdkVersion safeExtGet("minSdkVersion", 21)
targetSdkVersion safeExtGet("targetSdkVersion", 34)
versionCode 1
versionName "50.2.1"
versionName "51.0.0"
}
lintOptions {
abortOnError false
}
publishing {
singleVariant("release") {
withSourcesJar()
}
}
}

repositories {
mavenCentral()
maven { url "https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/repository" }
}

dependencies {
implementation project(":expo-modules-core")
implementation project(":expo-notifications")
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
implementation 'com.facebook.react:react-native:+'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3"
api "com.salesforce.marketingcloud:marketingcloudsdk:8.1.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import java.text.SimpleDateFormat


class ExpoMarketingCloudSdkModule : Module() {
private var numberOfListeners = 0
private var logListener : LogListener? = null
private var inboxResponseListener : InboxResponseListener? = null
private var registrationListener : RegistrationEventListener? = null
Expand Down Expand Up @@ -189,9 +188,7 @@ class ExpoMarketingCloudSdkModule : Module() {
}
}

Function("addListener") {eventName: String ->
numberOfListeners++

AsyncFunction("startObserving") {eventName: String? ->
when (eventName) {
"onLog" -> {
if (logListener == null) {
Expand Down Expand Up @@ -268,35 +265,40 @@ class ExpoMarketingCloudSdkModule : Module() {
}
}

Function("removeListeners") {count: Int ->
numberOfListeners -= count
AsyncFunction("stopObserving") {eventName: String? ->

if (numberOfListeners == 0) {
if (logListener != null) {
logListener = null
SFMCSdk.setLogging(LogLevel.WARN, null)
when (eventName) {
"onLog" -> {
if (logListener != null) {
logListener = null
SFMCSdk.setLogging(LogLevel.WARN, null)
}
}

val listener = inboxResponseListener
if (listener != null) {
inboxResponseListener = null
whenPushModuleReady(null) { mp ->
try {
mp.inboxMessageManager.unregisterInboxResponseListener(listener)
} catch (ex: Throwable) {
throw ex
"onInboxResponse" -> {
val listener = inboxResponseListener
if (listener != null) {
inboxResponseListener = null
whenPushModuleReady(null) { mp ->
try {
mp.inboxMessageManager.unregisterInboxResponseListener(listener)
} catch (ex: Throwable) {
throw ex
}
}
}
}

val listener2 = registrationListener
if (listener2 != null) {
registrationListener = null
whenPushModuleReady(null) { mp ->
try {
mp.registrationManager.unregisterForRegistrationEvents(listener2)
} catch (ex: Throwable) {
throw ex
"onRegistrationResponseSucceeded" -> {
val listener2 = registrationListener
if (listener2 != null) {
registrationListener = null
whenPushModuleReady(null) { mp ->
try {
mp.registrationManager.unregisterForRegistrationEvents(listener2)
} catch (ex: Throwable) {
throw ex
}
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@allboatsrise/expo-marketingcloudsdk",
"author": "All Boats Rise Inc.",
"version": "50.2.1",
"version": "51.0.0",
"license": "MIT",
"description": "Expo module for Salesforce Marketing Cloud SDK",
"homepage": "https://github.com/allboatsrise/expo-marketingcloudsdk",
Expand Down Expand Up @@ -46,14 +46,14 @@
},
"dependencies": {},
"devDependencies": {
"expo": "^50.0.6",
"expo-module-scripts": "^3.4.1",
"expo-notifications": "^0.27.6",
"expo": "^51.0.5",
"expo-module-scripts": "^3.5.1",
"expo-notifications": "^0.28.1",
"zod": "~3.15.0"
},
"peerDependencies": {
"expo": ">=50.0.6",
"expo-notifications": ">=0.27.6",
"expo": ">=51.0.5",
"expo-notifications": ">=0.28.1",
"zod": "^3.15.0"
},
"peerDependenciesMeta": {
Expand Down
Loading

0 comments on commit 33c8920

Please sign in to comment.