Skip to content

Commit

Permalink
Embedded
Browse files Browse the repository at this point in the history
  • Loading branch information
rlepinski committed Aug 30, 2024
1 parent 75f68af commit 00b9b7a
Show file tree
Hide file tree
Showing 26 changed files with 557 additions and 30 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 @@ -36,6 +36,6 @@ class AirshipPackage : TurboReactPackage() {


override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
return listOf<ViewManager<*, *>>(ReactMessageViewManager())
return listOf<ViewManager<*, *>>(ReactMessageViewManager(), ReactEmbeddedViewManager())
}
}
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 ) }
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Copyright Airship and Contributors */

package com.urbanairship.reactnative

import android.content.Context
import android.graphics.Color
import android.view.View
import android.widget.FrameLayout
import androidx.core.view.doOnAttach
import com.facebook.react.bridge.LifecycleEventListener
import com.urbanairship.embedded.AirshipEmbeddedView

class ReactEmbeddedView(context: Context) : FrameLayout(context) {

private var embeddedId: String? = null

fun load(embeddedId: String) {
if (this.embeddedId == embeddedId) {
return
}

removeAllViews()
this.embeddedId = embeddedId
addView(AirshipEmbeddedView(context, embeddedId))
}

override fun requestLayout() {
super.requestLayout()

// This view relies on a measure + layout pass happening after it calls requestLayout().
// https://github.com/facebook/react-native/issues/4990#issuecomment-180415510
// https://stackoverflow.com/questions/39836356/react-native-resize-custom-ui-component
post(measureAndLayout)
}

private val measureAndLayout = Runnable {
measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY))
layout(left, top, right, bottom)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Copyright Airship and Contributors */

package com.urbanairship.reactnative

import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.viewmanagers.RTNAirshipEmbeddedViewManagerDelegate
import com.facebook.react.viewmanagers.RTNAirshipEmbeddedViewManagerInterface


class ReactEmbeddedViewManager : SimpleViewManager<ReactEmbeddedView>(),
RTNAirshipEmbeddedViewManagerInterface<ReactEmbeddedView> {

private val delegate = RTNAirshipEmbeddedViewManagerDelegate(this)

override fun getName(): String {
return REACT_CLASS
}

override fun getDelegate(): ViewManagerDelegate<ReactEmbeddedView?> {
return delegate
}

override fun createViewInstance(reactContext: ThemedReactContext): ReactEmbeddedView {
return ReactEmbeddedView(reactContext)
}

@ReactProp(name = "embeddedId")
override fun setEmbeddedId(view: ReactEmbeddedView, embeddedId: String?) {
embeddedId?.let {
view.load(it)
}
}


companion object {
const val REACT_CLASS = "RTNAirshipEmbeddedView"
}
}
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
5 changes: 3 additions & 2 deletions example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#Tue Aug 06 09:31:04 PDT 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
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
36 changes: 29 additions & 7 deletions example/src/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
Image,
KeyboardAvoidingView,
Platform,
TouchableOpacity,
TouchableOpacity
} from 'react-native';
import Airship, { EventType } 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,18 +161,32 @@ export default function HomeScreen() {
keyboardVerticalOffset={Platform.OS === 'ios' ? 200 : 0}
>
<View style={{ flex: 1, flexShrink: 0, padding: 20 }}>


{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>
<Image
style={[styles.backgroundIcon, { paddingBottom: 0 }]}
source={require('./../img/airship-mark.png')}
/>
</View>)}



<View style={{ flexDirection: 'column' }}>
{channelId ? (
Expand Down
Loading

0 comments on commit 00b9b7a

Please sign in to comment.