Skip to content

Commit

Permalink
Wire up new listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
rlepinski committed Aug 30, 2024
1 parent 96527ff commit e9443dc
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 29 deletions.
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.1.2
Airship_airshipProxyVersion=7.3.0
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,11 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) :
}
}

@ReactMethod
override fun inAppResendPendingEmbeddedEvent() {
proxy.inApp.resendLastEmbeddedEvent()
}

@ReactMethod
override fun messageCenterGetUnreadCount(promise: Promise) {
promise.resolveResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ import android.content.pm.PackageManager
import com.urbanairship.UAirship
import com.urbanairship.analytics.Extension
import com.urbanairship.android.framework.proxy.BaseAutopilot
import com.urbanairship.android.framework.proxy.Event
import com.urbanairship.android.framework.proxy.EventType
import com.urbanairship.android.framework.proxy.ProxyLogger
import com.urbanairship.android.framework.proxy.ProxyStore
import com.urbanairship.android.framework.proxy.events.EventEmitter
import com.urbanairship.embedded.AirshipEmbeddedInfo
import com.urbanairship.embedded.AirshipEmbeddedObserver
import com.urbanairship.json.JsonMap
import com.urbanairship.json.jsonMapOf
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.launch
Expand All @@ -35,7 +41,13 @@ class ReactAutopilot : BaseAutopilot() {
}
}

// Set our custom notification provider
MainScope().launch {
AirshipEmbeddedObserver(filter = { true }).embeddedViewInfoFlow.collect {
EventEmitter.shared().addEvent(PendingEmbeddedUpdated(it))
}
}

// Set our custom notification providerr
val notificationProvider = ReactNotificationProvider(context, airship.airshipConfigOptions)
airship.pushManager.notificationProvider = notificationProvider

Expand Down Expand Up @@ -75,4 +87,12 @@ class ReactAutopilot : BaseAutopilot() {
companion object {
const val EXTENDER_MANIFEST_KEY = "com.urbanairship.reactnative.AIRSHIP_EXTENDER"
}
}

internal class PendingEmbeddedUpdated(pending: List<AirshipEmbeddedInfo>) : Event {
override val type = EventType.PENDING_EMBEDDED_UPDATED

override val body: JsonMap = jsonMapOf(
"pending" to pending.map { jsonMapOf( "embeddedId" to it.embeddedId ) }
)
}
3 changes: 2 additions & 1 deletion android/src/main/java/com/urbanairship/reactnative/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ object Utils {
EventType.FOREGROUND_PUSH_RECEIVED,
EventType.BACKGROUND_PUSH_RECEIVED
),
"com.airship.notification_status_changed" to listOf(EventType.NOTIFICATION_STATUS_CHANGED)
"com.airship.notification_status_changed" to listOf(EventType.NOTIFICATION_STATUS_CHANGED),
"com.airship.pending_embedded_updated" to listOf(EventType.PENDING_EMBEDDED_UPDATED)
)

fun convertArray(array: ReadableArray?): JsonValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ abstract class AirshipSpec internal constructor(context: ReactApplicationContext
@com.facebook.proguard.annotations.DoNotStrip
abstract fun inAppIsPaused(promise: Promise)

@ReactMethod
@com.facebook.proguard.annotations.DoNotStrip
abstract fun inAppResendPendingEmbeddedEvent()

@ReactMethod
@com.facebook.proguard.annotations.DoNotStrip
abstract fun messageCenterGetUnreadCount(promise: Promise)
Expand Down
1 change: 0 additions & 1 deletion example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ rootProject.name = 'AirshipExample'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')
includeBuild('./../../../android-library-dev')
12 changes: 6 additions & 6 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ PODS:
- Airship/Core
- Airship/PreferenceCenter (18.7.2):
- Airship/Core
- AirshipFrameworkProxy (7.1.2):
- AirshipFrameworkProxy (7.3.0):
- Airship (= 18.7.2)
- AirshipServiceExtension (18.7.2)
- boost (1.83.0)
Expand Down Expand Up @@ -907,8 +907,8 @@ PODS:
- React-Mapbuffer (0.73.4):
- glog
- React-debug
- react-native-airship (19.2.0):
- AirshipFrameworkProxy (= 7.1.2)
- react-native-airship (19.3.0):
- AirshipFrameworkProxy (= 7.3.0)
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
Expand Down Expand Up @@ -1280,7 +1280,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Airship: bb32ff2c5a811352da074480357d9f02dbb8f327
AirshipFrameworkProxy: dbd862dc6fb21b13e8b196458d626123e2a43a50
AirshipFrameworkProxy: 88a5e374efb5841e8cd84e63983c1ded123fe073
AirshipServiceExtension: 9c73369f426396d9fb9ff222d86d842fac76ba46
boost: d3f49c53809116a5d38da093a8aa78bf551aed09
DoubleConversion: fea03f2699887d960129cc54bba7e52542b6f953
Expand Down Expand Up @@ -1311,7 +1311,7 @@ SPEC CHECKSUMS:
React-jsinspector: 9ac353eccf6ab54d1e0a33862ba91221d1e88460
React-logger: 0a57b68dd2aec7ff738195f081f0520724b35dab
React-Mapbuffer: 63913773ed7f96b814a2521e13e6d010282096ad
react-native-airship: 54a39240587b06b2f683769a2ab838b7ee25b2e6
react-native-airship: 7fcefeebfac490aab222b93521e08ebd5b3d4581
react-native-safe-area-context: b97eb6f9e3b7f437806c2ce5983f479f8eb5de4b
React-nativeconfig: d7af5bae6da70fa15ce44f045621cf99ed24087c
React-NativeModulesApple: 0123905d5699853ac68519607555a9a4f5c7b3ac
Expand Down Expand Up @@ -1342,4 +1342,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: dbd88b0cf2e018eeff600431486ded3ce68933fb

COCOAPODS: 1.12.1
COCOAPODS: 1.15.2
6 changes: 6 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
const Tab = createBottomTabNavigator();
const MessageCenterStack = createStackNavigator();

Airship.takeOff({
default: {
appKey: "VWDwdOFjRTKLRxCeXTVP6g",
appSecret: "5Ifi5rYgTm2QHey9JkP0WA"
}
})
Airship.addListener(EventType.NotificationResponse, (event) => {
console.log('NotificationResponse:', JSON.stringify(event));
});
Expand Down
40 changes: 32 additions & 8 deletions example/src/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Platform,
TouchableOpacity
} from 'react-native';
import Airship, { EventType, AirshipEmbeddedView } from '@ua/react-native-airship';
import Airship, { EventType, AirshipEmbeddedView} from '@ua/react-native-airship';

import styles from '../Styles';
import NamedUserManagerCell from './Home Elements/NamedUserManagerCell';
Expand Down Expand Up @@ -46,6 +46,7 @@ export default function HomeScreen() {
const [tags, setTags] = useState<string[]>([]);
const [tagText, setTagText] = useState('');
const [notificationsEnabled, setNotificationsEnabled] = useState(false);
const [isEmbeddedReady, setEmbeddedReady] = useState(false)

const refreshTags = useCallback(async () => {
const fetchedTags = await Airship.channel.getTags();
Expand Down Expand Up @@ -95,6 +96,8 @@ export default function HomeScreen() {
console.error('Error getting notification status:', error);
});

setEmbeddedReady(Airship.inApp.isEmbeddedReady("test"))

Airship.push.iOS
.getAuthorizedNotificationSettings()
.then((id) => {
Expand Down Expand Up @@ -141,6 +144,11 @@ export default function HomeScreen() {
}
);

Airship.inApp.addEmbeddedReadyListener("test", (isReady) => {
console.log("Test " + isReady)
setEmbeddedReady(isReady)
});

return () => {
subscription.remove();
};
Expand All @@ -153,15 +161,31 @@ export default function HomeScreen() {
keyboardVerticalOffset={Platform.OS === 'ios' ? 200 : 0}
>
<View style={{ flex: 1, flexShrink: 0, padding: 20 }}>
<View style={{ flex: 1, flexShrink: 0, padding: 40 }}>

<AirshipEmbeddedView
embeddedId="test"
style={{ flex: 1 }}
/>

{isEmbeddedReady ?
(
<View style={{ flex: 1 }}>
<AirshipEmbeddedView
embeddedId="test"
style={{ flex: 1 }}
/>
</View>


)
: (
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}
>
<Image
style={[styles.backgroundIcon, { paddingBottom: 0 }]}
source={require('./../img/airship-mark.png')}
/>
</View>)}



<View style={{ flexDirection: 'column' }}>
Expand Down
18 changes: 15 additions & 3 deletions ios/AirshipReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public class AirshipReactNative: NSObject {
@objc
public static let overridePresentationOptionsEventName = "com.airship.ios.override_presentation_options"


@objc
public static let pendingEmbeddedUpdated = "com.airship.iax.pending_embedded_updated"

var lock = AirshipLock()
var pendingPresentationRequests: [String: PresentationOptionsOverridesRequest] = [:]

Expand Down Expand Up @@ -56,6 +58,7 @@ public class AirshipReactNative: NSObject {
}



AirshipProxy.shared.push.presentationOptionOverrides = { request in
guard self.overridePresentationOptionsEnabled else {
request.result(options: nil)
Expand Down Expand Up @@ -409,30 +412,38 @@ public extension AirshipReactNative {
// InApp
@objc
public extension AirshipReactNative {

@objc
@MainActor
func inAppIsPaused() throws -> NSNumber {
return try NSNumber(
value: AirshipProxy.shared.inApp.isPaused()
)
}

@objc
@MainActor
func inAppSetPaused(_ paused: Bool) throws {
try AirshipProxy.shared.inApp.setPaused(paused)
}

@objc
@MainActor
func inAppSetDisplayInterval(milliseconds: Double) throws {
try AirshipProxy.shared.inApp.setDisplayInterval(Int(milliseconds))
}

@objc
@MainActor
func inAppGetDisplayInterval() throws -> NSNumber {
return try NSNumber(
value: AirshipProxy.shared.inApp.getDisplayInterval()
)
}

@objc
func inAppResendPendingEmbeddedEvent() {
AirshipProxy.shared.inApp.resendLastEmbeddedEvent()
}
}

// Locale
Expand Down Expand Up @@ -624,7 +635,8 @@ extension AirshipProxyEventType {
"com.airship.notification_response": .notificationResponseReceived,
"com.airship.push_received": .pushReceived,
"com.airship.notification_status_changed": .notificationStatusChanged,
"com.airship.authorized_notification_settings_changed": .authorizedNotificationSettingsChanged
"com.airship.authorized_notification_settings_changed": .authorizedNotificationSettingsChanged,
"com.airship.pending_embedded_updated": .pendingEmbeddedUpdated
]

public static func fromReactName(_ name: String) throws -> AirshipProxyEventType {
Expand Down
12 changes: 9 additions & 3 deletions ios/RTNAirship.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ @implementation RTNAirship
RCT_EXPORT_MODULE()

- (NSArray<NSString *> *)supportedEvents {
return @[AirshipReactNative.pendingEventsEventName, AirshipReactNative.overridePresentationOptionsEventName];
return @[
AirshipReactNative.pendingEventsEventName,
AirshipReactNative.overridePresentationOptionsEventName,
AirshipReactNative.pendingEmbeddedUpdated
];
}

-(void)startObserving {
Expand Down Expand Up @@ -239,8 +243,6 @@ + (BOOL)requiresMainQueueSetup {
pushIosSetBadgeNumber:(double)badgeNumber
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
NSError *error;

[AirshipReactNative.shared pushSetBadgeNumber:badgeNumber completionHandler:^(NSError *error) {
[self handleResult:nil
error:error
Expand Down Expand Up @@ -514,6 +516,10 @@ + (BOOL)requiresMainQueueSetup {
[self handleResult:nil error:error resolve:resolve reject:reject];
}

RCT_EXPORT_METHOD(inAppResendPendingEmbeddedEvent) {
[AirshipReactNative.shared inAppResendPendingEmbeddedEvent];
}

RCT_REMAP_METHOD(localeClearLocaleOverride,
localeClearLocaleOverride:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ua/react-native-airship",
"version": "19.2.1",
"version": "19.3.0",
"description": "Airship plugin for React Native apps.",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
2 changes: 1 addition & 1 deletion react-native-airship.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ Pod::Spec.new do |s|
s.dependency "React-Core"
end

s.dependency "AirshipFrameworkProxy", "7.1.2"
s.dependency "AirshipFrameworkProxy", "7.3.0"
end
Loading

0 comments on commit e9443dc

Please sign in to comment.