Skip to content
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

Live Activities #595

Merged
merged 7 commits into from
Sep 30, 2024
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
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Airship_minSdkVersion=21
Airship_targetSdkVersion=34
Airship_compileSdkVersion=34
Airship_ndkversion=26.1.10909125
Airship_airshipProxyVersion=7.3.0
Airship_airshipProxyVersion=8.3.0
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.urbanairship.reactnative

import android.annotation.SuppressLint
import android.os.Build
import com.facebook.react.bridge.*
import com.facebook.react.modules.core.RCTNativeAppEventEmitter
import com.urbanairship.PendingResult
Expand Down Expand Up @@ -51,6 +53,7 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) :
}
}

@SuppressLint("RestrictedApi")
override fun initialize() {
super.initialize()

Expand Down Expand Up @@ -119,6 +122,7 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) :
}
}

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

@ReactMethod
override fun pushEnableUserNotifications(promise: Promise) {
promise.resolvePending {
promise.resolveSuspending(scope) {
proxy.push.enableUserPushNotifications()
}
}

@ReactMethod
override fun pushGetNotificationStatus(promise: Promise) {
promise.resolveResult {
promise.resolveSuspending(scope) {
proxy.push.getNotificationStatus()
}
}
Expand Down Expand Up @@ -340,8 +344,12 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) :

@ReactMethod
override fun pushAndroidIsNotificationChannelEnabled(channel: String?, promise: Promise) {
promise.resolveResult {
proxy.push.isNotificationChannelEnabled(requireNotNull(channel))
promise.resolveSuspending(scope) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
proxy.push.isNotificationChannelEnabled(requireNotNull(channel))
} else {
true
}
}
}

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

@ReactMethod
override fun featureFlagManagerFlag(flagName: String?, promise: Promise) {
promise.resolveDeferred { callback ->
scope.launch {
try {
requireNotNull(flagName)
val flag = proxy.featureFlagManager.flag(flagName)
callback(flag, null)
} catch (e: Exception) {
callback(null, e)
}
}
promise.resolveSuspending(scope) {
requireNotNull(flagName)
proxy.featureFlagManager.flag(flagName)
}
}

Expand All @@ -692,6 +693,30 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) :
}
}

override fun liveActivityList(request: ReadableMap?, promise: Promise) {
promise.resolveResult {
throw IllegalStateException("Not supported on Android")
}
}

override fun liveActivityCreate(request: ReadableMap?, promise: Promise) {
promise.resolveResult {
throw IllegalStateException("Not supported on Android")
}
}

override fun liveActivityUpdate(request: ReadableMap?, promise: Promise) {
promise.resolveResult {
throw IllegalStateException("Not supported on Android")
}
}

override fun liveActivityEnd(request: ReadableMap?, promise: Promise) {
promise.resolveResult {
throw IllegalStateException("Not supported on Android")
}
}

private fun notifyPending() {
if (context.hasActiveReactInstance()) {
val appEventEmitter = context.getJSModule(RCTNativeAppEventEmitter::class.java)
Expand Down Expand Up @@ -720,6 +745,30 @@ internal fun Promise.resolveResult(function: () -> Any?) {
resolveDeferred<Any> { callback -> callback(function(), null) }
}

internal fun Promise.resolveSuspending(scope: CoroutineScope, function: suspend () -> Any?) {
scope.launch {
try {
when (val result = function()) {
is Unit -> {
[email protected](null)
}
is JsonSerializable -> {
[email protected](result.toReactType())
}
is Number -> {
[email protected](result.toDouble())
}
else -> {
[email protected](result)
}
}
} catch (e: Exception) {
[email protected]("AIRSHIP_ERROR", e)
}
}

}

internal fun <T> Promise.resolveDeferred(function: ((T?, Exception?) -> Unit) -> Unit) {
try {
function { result, error ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,22 @@ abstract class AirshipSpec internal constructor(context: ReactApplicationContext
@ReactMethod
@com.facebook.proguard.annotations.DoNotStrip
abstract fun featureFlagManagerTrackInteraction(flag: ReadableMap?, promise: Promise)

@ReactMethod
@com.facebook.proguard.annotations.DoNotStrip
abstract fun liveActivityList(request: ReadableMap?, promise: Promise)

@ReactMethod
@com.facebook.proguard.annotations.DoNotStrip
abstract fun liveActivityCreate(request: ReadableMap?, promise: Promise)

@ReactMethod
@com.facebook.proguard.annotations.DoNotStrip
abstract fun liveActivityUpdate(request: ReadableMap?, promise: Promise)

@ReactMethod
@com.facebook.proguard.annotations.DoNotStrip
abstract fun liveActivityEnd(request: ReadableMap?, promise: Promise)
}


Loading
Loading