diff --git a/example/src/App.tsx b/example/src/App.tsx index 4de350c..84f1d95 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -55,7 +55,10 @@ export const App = () => { Shortcuts.addShortcut({ id, title, - iconName + iconName, + userInfo: { + key: 'test' + } }) .then((response) => Alert.alert( diff --git a/ios/RNShortcuts.mm b/ios/RNShortcuts.mm index 77f1f1c..78d0462 100644 --- a/ios/RNShortcuts.mm +++ b/ios/RNShortcuts.mm @@ -51,6 +51,7 @@ - (NSDictionary *)convertShortcutParamsToDictionary:(JS::NativeShortcuts::Shortc dict[@"title"] = params.title() ?: @""; dict[@"subTitle"] = params.subTitle() ?: @""; dict[@"longLabel"] = params.longLabel() ?: @""; + dict[@"userInfo"] = params.userInfo() ?: nil; return [dict copy]; } diff --git a/ios/RNShortcutsImpl.swift b/ios/RNShortcutsImpl.swift index 9786206..c72e3f5 100644 --- a/ios/RNShortcutsImpl.swift +++ b/ios/RNShortcutsImpl.swift @@ -78,20 +78,20 @@ public class RNShortcutsImpl: NSObject { return } - let shortcutItem = createShortcutItem(id: id, title: title, subtitle: params["subTitle"] as? String, iconName: params["iconName"] as? String) + let shortcutItem = createShortcutItem(id: id, title: title, subtitle: params["subTitle"] as? String, iconName: params["iconName"] as? String, userInfo: params["userInfo"] as? [String : any NSSecureCoding]) DispatchQueue.main.async { operation(shortcutItem) } } - private func createShortcutItem(id: String, title: String, subtitle: String?, iconName: String?) -> UIApplicationShortcutItem { + private func createShortcutItem(id: String, title: String, subtitle: String?, iconName: String?, userInfo: [String : any NSSecureCoding]?) -> UIApplicationShortcutItem { return UIApplicationShortcutItem( type: id, localizedTitle: title, localizedSubtitle: subtitle, icon: getUIApplicationShortcutIcon(iconName: iconName), - userInfo: nil + userInfo: userInfo ) } @@ -116,14 +116,27 @@ public class RNShortcutsImpl: NSObject { guard let iconName = iconName else { return nil} return UIApplicationShortcutIcon(templateImageName: iconName) } + + private func convertToSecureCodingDictionary(from object: NSObject) -> [String: any NSSecureCoding]? { + guard let dictionary = object as? [String: Any] else { return nil } + + var secureCodingDict = [String: any NSSecureCoding]() + + for (key, value) in dictionary { + secureCodingDict[key] = value as? any NSSecureCoding + } + + return secureCodingDict + } } private extension UIApplicationShortcutItem { - func toDictionary() -> [String: String?] { + func toDictionary() -> [String: Any?] { return [ "id": type, "title": localizedTitle, - "subtitle": localizedSubtitle + "subtitle": localizedSubtitle, + "userInfo": userInfo ] } } diff --git a/lib/typescript/commonjs/src/NativeShortcuts.d.ts b/lib/typescript/commonjs/src/NativeShortcuts.d.ts index a373157..569e6f2 100644 --- a/lib/typescript/commonjs/src/NativeShortcuts.d.ts +++ b/lib/typescript/commonjs/src/NativeShortcuts.d.ts @@ -4,6 +4,9 @@ export interface ShortcutResponseType { title: string; subTitle?: string; longLabel?: string; + userInfo?: { + [key: string]: string | number; + }; } export interface ShortcutParamsType extends ShortcutResponseType { iconName?: string; diff --git a/lib/typescript/module/src/NativeShortcuts.d.ts b/lib/typescript/module/src/NativeShortcuts.d.ts index a373157..569e6f2 100644 --- a/lib/typescript/module/src/NativeShortcuts.d.ts +++ b/lib/typescript/module/src/NativeShortcuts.d.ts @@ -4,6 +4,9 @@ export interface ShortcutResponseType { title: string; subTitle?: string; longLabel?: string; + userInfo?: { + [key: string]: string | number; + }; } export interface ShortcutParamsType extends ShortcutResponseType { iconName?: string; diff --git a/src/NativeShortcuts.tsx b/src/NativeShortcuts.tsx index ad100a8..73b7d02 100644 --- a/src/NativeShortcuts.tsx +++ b/src/NativeShortcuts.tsx @@ -5,6 +5,9 @@ export interface ShortcutResponseType { title: string; subTitle?: string; longLabel?: string; + userInfo?: { + [key: string]: string | number; + }; } export interface ShortcutParamsType extends ShortcutResponseType { @@ -20,8 +23,8 @@ export interface Spec extends TurboModule { isShortcutExists(id: string): Promise; isShortcutSupported(): Promise; getInitialShortcutId(): Promise; - addListener: (eventType: string) => void; + addListener: (eventType: string) => void; removeListeners: (count: number) => void; } -export default TurboModuleRegistry.getEnforcing("RNShortcuts"); \ No newline at end of file +export default TurboModuleRegistry.getEnforcing("RNShortcuts");