Skip to content

Commit

Permalink
Wire up events, end, update
Browse files Browse the repository at this point in the history
  • Loading branch information
rlepinski committed Sep 27, 2024
1 parent eabb945 commit ade2867
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 52 deletions.
4 changes: 4 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Airship.addListener(EventType.NotificationResponse, (event) => {
console.log('NotificationResponse:', JSON.stringify(event));
});

Airship.addListener(EventType.IOSLiveActivitiesUpdated, (event) => {
console.log('IOSLiveActivitiesUpdated:', JSON.stringify(event));
});

Airship.addListener(EventType.PushReceived, (event) => {
console.log('PushReceived:', JSON.stringify(event));
});
Expand Down
135 changes: 85 additions & 50 deletions example/src/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ import {
KeyboardAvoidingView,
Platform,
TouchableOpacity,
Button
Button,
} 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 @@ -47,7 +50,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 [isEmbeddedReady, setEmbeddedReady] = useState(false);

const refreshTags = useCallback(async () => {
const fetchedTags = await Airship.channel.getTags();
Expand Down Expand Up @@ -85,7 +88,6 @@ export default function HomeScreen() {
}, []);

useEffect(() => {

// Add takeOff here

Airship.push
Expand All @@ -97,7 +99,7 @@ export default function HomeScreen() {
console.error('Error getting notification status:', error);
});

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

Airship.push.iOS
.getAuthorizedNotificationSettings()
Expand Down Expand Up @@ -145,9 +147,9 @@ export default function HomeScreen() {
}
);

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

return () => {
Expand All @@ -162,49 +164,81 @@ 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>
)}


{isEmbeddedReady ?
(
<View style={{ flex: 1 }}>
<AirshipEmbeddedView
embeddedId="test"
style={{ flex: 1 }}
/>
</View>
)
: (
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
<Button
onPress={async () => {
Airship.liveActivityManager.create({
typeReferenceId: 'Example',
content: {
state: {
emoji: '🙌',
},
relevanceScore: 0.0,
},
attributes: {
name: 'some-unique-name',
},
});
}}
>
<Image
style={[styles.backgroundIcon, { paddingBottom: 0 }]}
source={require('./../img/airship-mark.png')}
/>
</View>)}

<Button
onPress={async () => {
Airship.liveActivityManager.create({
typeReferenceId: "Example",
content: {
state: {
emoji: "🙌",
},
relevanceScore: 0.0
},
attributes: {
name: "some-unique-name"
}
})
} }
title="Start LA"
color="#841584"
/>
title="Start LA"
color="#841584"
/>

<Button
onPress={async () => {
const activities = await Airship.liveActivityManager.list({
typeReferenceId: 'Example',
});
activities.forEach((element) => {
Airship.liveActivityManager.end({
activityID: element.id,
typeReferenceId: 'Example',
});
});
}}
title="End All LA"
color="#841584"
/>

<Button
onPress={async () => {
const activities = await Airship.liveActivityManager.list({
typeReferenceId: 'Example',
});
activities.forEach((element) => {
Airship.liveActivityManager.update({
activityID: element.id,
typeReferenceId: 'Example',
content: {
state: {
emoji: element.content.state.emoji + '🙌',
},
relevanceScore: 0.0,
},
});
});
}}
title="Update All LA"
color="#841584"
/>

<View style={{ flexDirection: 'column' }}>
{channelId ? (
Expand Down Expand Up @@ -239,7 +273,8 @@ export default function HomeScreen() {
<View style={styles.warningView}>
<Text style={styles.warningTitleText}>Channel Unavailble</Text>
<Text style={styles.warningBodyText}>
Have you added the takeOff call with the correct app key and secret?
Have you added the takeOff call with the correct app key and
secret?
</Text>
</View>
)}
Expand Down
29 changes: 28 additions & 1 deletion ios/AirshipReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,32 @@ public extension AirshipReactNative {
throw error
}
}

@objc
func liveActivityUpdate(options: Any) async throws -> Void {
do {
if #available(iOS 16.1, *) {
try await LiveActivityManager.shared.update(try AirshipJSON.wrap(options).decode())
} else {
throw AirshipErrors.error("Not available before 16.1")
}
} catch {
throw error
}
}

@objc
func liveActivityEnd(options: Any) async throws -> Void {
do {
if #available(iOS 16.1, *) {
try await LiveActivityManager.shared.end(try AirshipJSON.wrap(options).decode())
} else {
throw AirshipErrors.error("Not available before 16.1")
}
} catch {
throw error
}
}
}

extension AirshipReactNative: AirshipProxyDelegate {
Expand Down Expand Up @@ -670,7 +696,8 @@ extension AirshipProxyEventType {
"com.airship.push_received": .pushReceived,
"com.airship.notification_status_changed": .notificationStatusChanged,
"com.airship.authorized_notification_settings_changed": .authorizedNotificationSettingsChanged,
"com.airship.pending_embedded_updated": .pendingEmbeddedUpdated
"com.airship.pending_embedded_updated": .pendingEmbeddedUpdated,
"com.airship.live_activities_updated": .liveActivitiesUpdated
]

public static func fromReactName(_ name: String) throws -> AirshipProxyEventType {
Expand Down
25 changes: 24 additions & 1 deletion ios/RTNAirship.mm
Original file line number Diff line number Diff line change
Expand Up @@ -787,11 +787,34 @@ + (BOOL)requiresMainQueueSetup {
reject:(RCTPromiseRejectBlock)reject) {

[AirshipReactNative.shared liveActivityCreateWithOptions:request
completionHandler:^(id result, NSError * _Nullable error) {
completionHandler:^(id result, NSError * _Nullable error) {
[self handleResult:result error:error resolve:resolve reject:reject];
}];
}

RCT_REMAP_METHOD(liveActivityUpdate,
liveActivityUpdateRequest:(NSDictionary *)request
liveActivityUpdate:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {

[AirshipReactNative.shared liveActivityUpdateWithOptions:request
completionHandler:^(NSError * _Nullable error) {
[self handleResult:nil error:error resolve:resolve reject:reject];
}];
}

RCT_REMAP_METHOD(liveActivityEnd,
liveActivityEndRequest:(NSDictionary *)request
liveActivityEnd:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {

[AirshipReactNative.shared liveActivityEndWithOptions:request
completionHandler:^(NSError * _Nullable error) {
[self handleResult:nil error:error resolve:resolve reject:reject];
}];
}





Expand Down

0 comments on commit ade2867

Please sign in to comment.