Skip to content

Commit 3a0ca80

Browse files
authored
Live Activities (#595)
* Add LA support * Fixes * Use attributesType to match iOS APNS api * Update docs * Update latest proxy * Fix android * Use actual pod
1 parent aefacc5 commit 3a0ca80

File tree

32 files changed

+934
-147
lines changed

32 files changed

+934
-147
lines changed

android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ Airship_minSdkVersion=21
33
Airship_targetSdkVersion=34
44
Airship_compileSdkVersion=34
55
Airship_ndkversion=26.1.10909125
6-
Airship_airshipProxyVersion=7.3.0
6+
Airship_airshipProxyVersion=8.3.0

android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.urbanairship.reactnative
22

3+
import android.annotation.SuppressLint
4+
import android.os.Build
35
import com.facebook.react.bridge.*
46
import com.facebook.react.modules.core.RCTNativeAppEventEmitter
57
import com.urbanairship.PendingResult
@@ -51,6 +53,7 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) :
5153
}
5254
}
5355

56+
@SuppressLint("RestrictedApi")
5457
override fun initialize() {
5558
super.initialize()
5659

@@ -119,6 +122,7 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) :
119122
}
120123
}
121124

125+
@SuppressLint("RestrictedApi")
122126
@ReactMethod
123127
override fun takePendingEvents(eventName: String?, isHeadlessJS: Boolean, promise: Promise) {
124128
promise.resolveResult {
@@ -235,14 +239,14 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) :
235239

236240
@ReactMethod
237241
override fun pushEnableUserNotifications(promise: Promise) {
238-
promise.resolvePending {
242+
promise.resolveSuspending(scope) {
239243
proxy.push.enableUserPushNotifications()
240244
}
241245
}
242246

243247
@ReactMethod
244248
override fun pushGetNotificationStatus(promise: Promise) {
245-
promise.resolveResult {
249+
promise.resolveSuspending(scope) {
246250
proxy.push.getNotificationStatus()
247251
}
248252
}
@@ -340,8 +344,12 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) :
340344

341345
@ReactMethod
342346
override fun pushAndroidIsNotificationChannelEnabled(channel: String?, promise: Promise) {
343-
promise.resolveResult {
344-
proxy.push.isNotificationChannelEnabled(requireNotNull(channel))
347+
promise.resolveSuspending(scope) {
348+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
349+
proxy.push.isNotificationChannelEnabled(requireNotNull(channel))
350+
} else {
351+
true
352+
}
345353
}
346354
}
347355

@@ -671,16 +679,9 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) :
671679

672680
@ReactMethod
673681
override fun featureFlagManagerFlag(flagName: String?, promise: Promise) {
674-
promise.resolveDeferred { callback ->
675-
scope.launch {
676-
try {
677-
requireNotNull(flagName)
678-
val flag = proxy.featureFlagManager.flag(flagName)
679-
callback(flag, null)
680-
} catch (e: Exception) {
681-
callback(null, e)
682-
}
683-
}
682+
promise.resolveSuspending(scope) {
683+
requireNotNull(flagName)
684+
proxy.featureFlagManager.flag(flagName)
684685
}
685686
}
686687

@@ -692,6 +693,30 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) :
692693
}
693694
}
694695

696+
override fun liveActivityList(request: ReadableMap?, promise: Promise) {
697+
promise.resolveResult {
698+
throw IllegalStateException("Not supported on Android")
699+
}
700+
}
701+
702+
override fun liveActivityCreate(request: ReadableMap?, promise: Promise) {
703+
promise.resolveResult {
704+
throw IllegalStateException("Not supported on Android")
705+
}
706+
}
707+
708+
override fun liveActivityUpdate(request: ReadableMap?, promise: Promise) {
709+
promise.resolveResult {
710+
throw IllegalStateException("Not supported on Android")
711+
}
712+
}
713+
714+
override fun liveActivityEnd(request: ReadableMap?, promise: Promise) {
715+
promise.resolveResult {
716+
throw IllegalStateException("Not supported on Android")
717+
}
718+
}
719+
695720
private fun notifyPending() {
696721
if (context.hasActiveReactInstance()) {
697722
val appEventEmitter = context.getJSModule(RCTNativeAppEventEmitter::class.java)
@@ -720,6 +745,30 @@ internal fun Promise.resolveResult(function: () -> Any?) {
720745
resolveDeferred<Any> { callback -> callback(function(), null) }
721746
}
722747

748+
internal fun Promise.resolveSuspending(scope: CoroutineScope, function: suspend () -> Any?) {
749+
scope.launch {
750+
try {
751+
when (val result = function()) {
752+
is Unit -> {
753+
this@resolveSuspending.resolve(null)
754+
}
755+
is JsonSerializable -> {
756+
this@resolveSuspending.resolve(result.toReactType())
757+
}
758+
is Number -> {
759+
this@resolveSuspending.resolve(result.toDouble())
760+
}
761+
else -> {
762+
this@resolveSuspending.resolve(result)
763+
}
764+
}
765+
} catch (e: Exception) {
766+
this@resolveSuspending.reject("AIRSHIP_ERROR", e)
767+
}
768+
}
769+
770+
}
771+
723772
internal fun <T> Promise.resolveDeferred(function: ((T?, Exception?) -> Unit) -> Unit) {
724773
try {
725774
function { result, error ->

android/src/oldarch/java/com/urbanairship/reactnative/AirshipSpec.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,22 @@ abstract class AirshipSpec internal constructor(context: ReactApplicationContext
404404
@ReactMethod
405405
@com.facebook.proguard.annotations.DoNotStrip
406406
abstract fun featureFlagManagerTrackInteraction(flag: ReadableMap?, promise: Promise)
407+
408+
@ReactMethod
409+
@com.facebook.proguard.annotations.DoNotStrip
410+
abstract fun liveActivityList(request: ReadableMap?, promise: Promise)
411+
412+
@ReactMethod
413+
@com.facebook.proguard.annotations.DoNotStrip
414+
abstract fun liveActivityCreate(request: ReadableMap?, promise: Promise)
415+
416+
@ReactMethod
417+
@com.facebook.proguard.annotations.DoNotStrip
418+
abstract fun liveActivityUpdate(request: ReadableMap?, promise: Promise)
419+
420+
@ReactMethod
421+
@com.facebook.proguard.annotations.DoNotStrip
422+
abstract fun liveActivityEnd(request: ReadableMap?, promise: Promise)
407423
}
408424

409425

0 commit comments

Comments
 (0)