Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ios): add Dynamic Island support (#13625)
* feat(ios): add basic dynamic island support * fix(docs): fix invalid description in parameter * fix(ios): generate .swiftinterface files * fix: define default version * chore: move files to main target So it can be better included via the widget (still will require some CLI changes) * chore: move some logic * fix: fix linting errors * fix: fix generic parameter call from ObjC -> Swift
- Loading branch information
1 parent
51288dd
commit f000f3b
Showing
11 changed files
with
197 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
name: Titanium.App.iOS.ActivityAttributes | ||
summary: | | ||
Use this module to communicate with the native iOS 16+ Dynamic Island APIs. | ||
description: | | ||
To properly use these APIs, you need to habe your Widget Extension ready. | ||
You can follow this [sample repository](https://github.com/hansemannn/titanium-widget-kit-sample-app) for an extended example. | ||
since: "12.0.0" | ||
platforms: [iphone, ipad] | ||
|
||
methods: | ||
- name: startActivity | ||
summary: Starts a new activity (aka the Dynamic Island) with the provided parameters | ||
parameters: | ||
- name: value | ||
summary: | | ||
The values to pass to your extension. For maximum flexibility, this parameter should be passed | ||
as a String-based Object, e.g. | ||
``` | ||
{ | ||
"param1": "Hello", | ||
"param2": "World" | ||
} | ||
If you need to pass other types, please serialize them to a valid JSON object and pass it's | ||
stringified representation to this method. | ||
type: Object | ||
|
||
examples: | ||
- title: Start a new activity | ||
example: | | ||
``` js | ||
const attributes = Ti.App.iOS.createActivityAttributes(); | ||
attributes.startActivity({ | ||
param1: "Hello", | ||
param2: "World", | ||
data: JSON.stringify({ intKey: 1, boolKey: true }) | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright TiDev, Inc. 04/07/2022-Present. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
#if canImport(ActivityKit) | ||
import Foundation | ||
import ActivityKit | ||
|
||
public struct TiActivityAttributes: ActivityAttributes { | ||
public typealias Status = ContentState | ||
public struct ContentState: Codable, Hashable { | ||
var value: [String: String] | ||
} | ||
} | ||
#endif |
36 changes: 36 additions & 0 deletions
36
iphone/Classes/TiAppiOSActivityAttributesProxy+startActivity.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright TiDev, Inc. 04/07/2022-Present. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
import TitaniumKit | ||
#if canImport(ActivityKit) | ||
import ActivityKit | ||
#endif | ||
|
||
extension TiAppiOSActivityAttributesProxy { | ||
|
||
@objc(_startActivity:) | ||
class func _startActivity(args: Any) { | ||
guard let params = args as? [String: String] else { | ||
fatalError("Invalid parameters passed to \"startActivity\" method!") | ||
} | ||
|
||
#if canImport(ActivityKit) | ||
let attributes = TiActivityAttributes() | ||
let contentState = TiActivityAttributes.Status(value: params) | ||
|
||
do { | ||
if #available(iOS 16.1, *) { | ||
_ = try Activity<TiActivityAttributes>.request(attributes: attributes, contentState: contentState) | ||
} | ||
} catch let error { | ||
NSLog("[ERROR] Cannot start activity: \(error.localizedDescription)") | ||
} | ||
#else | ||
NSLog("[ERROR] Cannot call \"startActivity\" on iOS < 16.1. Please add a guard to prevent this error log!") | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Axway Titanium | ||
* Copyright (c) 2009-present by Axway Appcelerator. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
#import <TitaniumKit/TitaniumKit.h> | ||
|
||
@interface TiAppiOSActivityAttributesProxy : TiProxy | ||
|
||
- (void)startActivity:(id)args; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Axway Titanium | ||
* Copyright (c) 2009-present by Axway Appcelerator. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
#import "TiAppiOSActivityAttributesProxy.h" | ||
|
||
@implementation TiAppiOSActivityAttributesProxy | ||
|
||
- (void)startActivity:(id)args | ||
{ | ||
ENSURE_SINGLE_ARG(args, NSDictionary); | ||
[TiAppiOSActivityAttributesProxy _startActivity:args]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
iphone/TitaniumKit/TitaniumKit/Sources/Misc/TiActivityAttributes.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright TiDev, Inc. 04/07/2022-Present. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
#if canImport(ActivityKit) | ||
import Foundation | ||
import ActivityKit | ||
|
||
public struct TiActivityAttributes: ActivityAttributes { | ||
public typealias Status = ContentState | ||
public struct ContentState: Codable, Hashable { | ||
var value: [String: String] | ||
} | ||
} | ||
#endif |
32 changes: 32 additions & 0 deletions
32
iphone/TitaniumKit/TitaniumKit/Sources/Misc/TiAppiOSActivityAttributesProxy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright TiDev, Inc. 04/07/2022-Present. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
#if canImport(ActivityKit) | ||
import TitaniumKit | ||
import ActivityKit | ||
|
||
@objc(TiAppiOSActivityAttributesProxy) | ||
public class TiAppiOSActivityAttributesProxy : TiProxy { | ||
|
||
@objc(startActivity:) | ||
@available(iOS 16.1, *) | ||
func startActivity(args: [Any]) { | ||
guard let params = args.first as? [String: String] else { | ||
fatalError("Missing required parameters") | ||
} | ||
|
||
let attributes = TiActivityAttributes() | ||
let contentState = TiActivityAttributes.Status(value: params) | ||
|
||
do { | ||
let _ = try Activity<TiActivityAttributes>.request(attributes: attributes, contentState: contentState) | ||
} catch (let error) { | ||
NSLog("[ERROR] Cannot start activity: \(error.localizedDescription)") | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// | ||
// Use this file to import your target's public headers that you would like to expose to Swift. | ||
// | ||
|
||
#import "TiAppiOSActivityAttributesProxy.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters