Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rlepinski committed Sep 27, 2024
1 parent 9271e76 commit eabb945
Show file tree
Hide file tree
Showing 17 changed files with 486 additions and 29 deletions.
202 changes: 192 additions & 10 deletions example/ios/AirshipExample.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions example/ios/AirshipExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<!-- Do not change NSAllowsArbitraryLoads to true, or you will risk app rejection! -->
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSAllowsLocalNetworking</key>
<true/>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
Expand All @@ -56,5 +55,7 @@
<array>
<string>Fonts/MaterialIcons.ttf</string>
</array>
<key>NSSupportsLiveActivities</key>
<true/>
</dict>
</plist>
23 changes: 11 additions & 12 deletions example/ios/AirshipExtender.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import AirshipKit

import AirshipFrameworkProxy
import ActivityKit

@objc
public class AirshipExtender: NSObject {
Expand All @@ -11,19 +12,17 @@ public class AirshipExtender: NSObject {
@objc
@MainActor
public class func setup() {
if (Airship.isFlying) {
self.shared.airshipReady()
} else {
NotificationCenter.default.addObserver(forName: AirshipNotifications.AirshipReady.name, object: nil, queue: nil) { _ in
Task { @MainActor in
self.shared.airshipReady()
if #available(iOS 16.1, *) {
// Can only call this once. It only throws on second call
try? LiveActivityManager.shared.setup { configurator in

// Call per widget
await configurator.register(forType: Activity<ExampleWidgetsAttributes>.self, typeReferenceID: "Example") { attributes in
// Track this property as the Airship name for updates
attributes.name
}

}
}
}

@MainActor
private func airshipReady() {
// Make restore call here
}
}
18 changes: 18 additions & 0 deletions example/ios/ExampleWidgets/AppIntent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// AppIntent.swift
// ExampleWidgets
//
// Created by Ryan Lepinski on 9/26/24.
//

import WidgetKit
import AppIntents

struct ConfigurationAppIntent: WidgetConfigurationIntent {
static var title: LocalizedStringResource { "Configuration" }
static var description: IntentDescription { "This is an example widget." }

// An example configurable parameter.
@Parameter(title: "Favorite Emoji", default: "😃")
var favoriteEmoji: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "tinted"
}
],
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions example/ios/ExampleWidgets/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
18 changes: 18 additions & 0 deletions example/ios/ExampleWidgets/ExampleWidgetsAttributes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ExampleWidgetsAttributes.swift
// AirshipExample
//
// Created by Ryan Lepinski on 9/26/24.
//
import ActivityKit


struct ExampleWidgetsAttributes: ActivityAttributes {
public struct ContentState: Codable, Hashable {
// Dynamic stateful properties about your activity go here!
var emoji: String
}

// Fixed non-changing properties about your activity go here!
var name: String
}
16 changes: 16 additions & 0 deletions example/ios/ExampleWidgets/ExampleWidgetsBundle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// ExampleWidgetsBundle.swift
// ExampleWidgets
//
// Created by Ryan Lepinski on 9/26/24.
//

import WidgetKit
import SwiftUI

@main
struct ExampleWidgetsBundle: WidgetBundle {
var body: some Widget {
ExampleWidgetsLiveActivity()
}
}
72 changes: 72 additions & 0 deletions example/ios/ExampleWidgets/ExampleWidgetsLiveActivity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// ExampleWidgetsLiveActivity.swift
// ExampleWidgets
//
// Created by Ryan Lepinski on 9/26/24.
//

import ActivityKit
import WidgetKit
import SwiftUI



struct ExampleWidgetsLiveActivity: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: ExampleWidgetsAttributes.self) { context in
// Lock screen/banner UI goes here
VStack {
Text("Hello \(context.state.emoji)")
}
.activityBackgroundTint(Color.cyan)
.activitySystemActionForegroundColor(Color.black)

} dynamicIsland: { context in
DynamicIsland {
// Expanded UI goes here. Compose the expanded UI through
// various regions, like leading/trailing/center/bottom
DynamicIslandExpandedRegion(.leading) {
Text("Leading")
}
DynamicIslandExpandedRegion(.trailing) {
Text("Trailing")
}
DynamicIslandExpandedRegion(.bottom) {
Text("Bottom \(context.state.emoji)")
// more content
}
} compactLeading: {
Text("L")
} compactTrailing: {
Text("T \(context.state.emoji)")
} minimal: {
Text(context.state.emoji)
}
.widgetURL(URL(string: "http://www.apple.com"))
.keylineTint(Color.red)
}
}
}

extension ExampleWidgetsAttributes {
fileprivate static var preview: ExampleWidgetsAttributes {
ExampleWidgetsAttributes(name: "World")
}
}

extension ExampleWidgetsAttributes.ContentState {
fileprivate static var smiley: ExampleWidgetsAttributes.ContentState {
ExampleWidgetsAttributes.ContentState(emoji: "😀")
}

fileprivate static var starEyes: ExampleWidgetsAttributes.ContentState {
ExampleWidgetsAttributes.ContentState(emoji: "🤩")
}
}

#Preview("Notification", as: .content, using: ExampleWidgetsAttributes.preview) {
ExampleWidgetsLiveActivity()
} contentStates: {
ExampleWidgetsAttributes.ContentState.smiley
ExampleWidgetsAttributes.ContentState.starEyes
}
11 changes: 11 additions & 0 deletions example/ios/ExampleWidgets/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widgetkit-extension</string>
</dict>
</dict>
</plist>
22 changes: 20 additions & 2 deletions example/src/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
Image,
KeyboardAvoidingView,
Platform,
TouchableOpacity
TouchableOpacity,
Button
} from 'react-native';
import Airship, { EventType, AirshipEmbeddedView} from '@ua/react-native-airship';

Expand Down Expand Up @@ -186,7 +187,24 @@ export default function HomeScreen() {
/>
</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"
/>

<View style={{ flexDirection: 'column' }}>
{channelId ? (
Expand Down
29 changes: 29 additions & 0 deletions ios/AirshipReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,35 @@ public extension AirshipReactNative {
}
}


// Live Activity
@objc
public extension AirshipReactNative {
@objc
func liveActivityList(options: Any) async throws -> Any {
if #available(iOS 16.1, *) {
let result = try await LiveActivityManager.shared.list(try AirshipJSON.wrap(options).decode())
return try AirshipJSON.wrap(result).unWrap() as Any
} else {
throw AirshipErrors.error("Not available before 16.1")
}
}

@objc
func liveActivityCreate(options: Any) async throws -> Any {
do {
if #available(iOS 16.1, *) {
let result = try await LiveActivityManager.shared.create(try AirshipJSON.wrap(options).decode())
return try AirshipJSON.wrap(result).unWrap() as Any
} else {
throw AirshipErrors.error("Not available before 16.1")
}
} catch {
throw error
}
}
}

extension AirshipReactNative: AirshipProxyDelegate {
public func migrateData(store: ProxyStore) {
ProxyDataMigrator().migrateData(store: store)
Expand Down
26 changes: 26 additions & 0 deletions ios/RTNAirship.mm
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,32 @@ + (BOOL)requiresMainQueueSetup {
}];
}

RCT_REMAP_METHOD(liveActivityList,
liveActivityListRequest:(NSDictionary *)request
liveActivityList:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {

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

RCT_REMAP_METHOD(liveActivityCreate,
liveActivityCreateRequest:(NSDictionary *)request
liveActivityCreate:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {

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





-(void)handleResult:(id)result
error:(NSError *)error
resolve:(RCTPromiseResolveBlock)resolve
Expand Down
3 changes: 3 additions & 0 deletions src/AirshipRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { AirshipFeatureFlagManager } from './AirshipFeatureFlagManager';

import { AirshipConfig, EventTypeMap, EventType } from './types';
import { Subscription, UAEventEmitter } from './UAEventEmitter';
import { AirshipLiveActivityManager } from './AirshipLiveActivityManager';

/**
* Airship
Expand All @@ -28,6 +29,7 @@ export class AirshipRoot {
public readonly privacyManager: AirshipPrivacyManager;
public readonly push: AirshipPush;
public readonly featureFlagManager: AirshipFeatureFlagManager;
public readonly liveActivityManager: AirshipLiveActivityManager;

private readonly eventEmitter: UAEventEmitter;

Expand All @@ -45,6 +47,7 @@ export class AirshipRoot {
this.privacyManager = new AirshipPrivacyManager(module);
this.push = new AirshipPush(module);
this.featureFlagManager = new AirshipFeatureFlagManager(module);
this.liveActivityManager = new AirshipLiveActivityManager(module);
}

/**
Expand Down
Loading

0 comments on commit eabb945

Please sign in to comment.