expo-targets 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +2 -0
- package/README.md +244 -0
- package/android/build.gradle +22 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsLogger.kt +98 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsReceiver.kt +136 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsRemoteViewsProvider.kt +72 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetProvider.kt +47 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetSync.kt +78 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetUpdateReceiver.kt +30 -0
- package/android/src/main/java/expo/modules/targets/extension/ExpoTargetsExtensionModule.kt +27 -0
- package/android/src/main/java/expo/modules/targets/messages/ExpoTargetsMessagesModule.kt +40 -0
- package/android/src/main/java/expo/modules/targets/storage/ExpoTargetsStorageModule.kt +119 -0
- package/app.plugin.js +1 -0
- package/build/metro/src/index.d.ts +2 -0
- package/build/metro/src/index.d.ts.map +1 -0
- package/build/metro/src/index.js +6 -0
- package/build/metro/src/index.js.map +1 -0
- package/build/metro/src/withTargetsMetro.d.ts +6 -0
- package/build/metro/src/withTargetsMetro.d.ts.map +1 -0
- package/build/metro/src/withTargetsMetro.js +171 -0
- package/build/metro/src/withTargetsMetro.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.js +56 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.js +70 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.js +41 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.js +75 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.d.ts +28 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.js +28 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.js +86 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.js +23 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.js.map +1 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.d.ts +7 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.js +31 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.js.map +1 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.d.ts +3 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.js +24 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.js.map +1 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.d.ts +3 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.js +27 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.js.map +1 -0
- package/build/plugin/src/android/withAndroidTarget.d.ts +10 -0
- package/build/plugin/src/android/withAndroidTarget.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidTarget.js +22 -0
- package/build/plugin/src/android/withAndroidTarget.js.map +1 -0
- package/build/plugin/src/android/withAndroidWidget.d.ts +13 -0
- package/build/plugin/src/android/withAndroidWidget.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidWidget.js +564 -0
- package/build/plugin/src/android/withAndroidWidget.js.map +1 -0
- package/build/plugin/src/config.d.ts +141 -0
- package/build/plugin/src/config.d.ts.map +1 -0
- package/build/plugin/src/config.js +54 -0
- package/build/plugin/src/config.js.map +1 -0
- package/build/plugin/src/index.d.ts +9 -0
- package/build/plugin/src/index.d.ts.map +1 -0
- package/build/plugin/src/index.js +11 -0
- package/build/plugin/src/index.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.d.ts +11 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.js +49 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.d.ts +17 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.js +152 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.d.ts +8 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.js +25 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.d.ts +8 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.js +52 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.d.ts +12 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.js +162 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.d.ts +15 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.js +646 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.js.map +1 -0
- package/build/plugin/src/ios/target.d.ts +41 -0
- package/build/plugin/src/ios/target.d.ts.map +1 -0
- package/build/plugin/src/ios/target.js +574 -0
- package/build/plugin/src/ios/target.js.map +1 -0
- package/build/plugin/src/ios/utils/asset.d.ts +60 -0
- package/build/plugin/src/ios/utils/asset.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/asset.js +375 -0
- package/build/plugin/src/ios/utils/asset.js.map +1 -0
- package/build/plugin/src/ios/utils/file.d.ts +33 -0
- package/build/plugin/src/ios/utils/file.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/file.js +88 -0
- package/build/plugin/src/ios/utils/file.js.map +1 -0
- package/build/plugin/src/ios/utils/index.d.ts +12 -0
- package/build/plugin/src/ios/utils/index.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/index.js +38 -0
- package/build/plugin/src/ios/utils/index.js.map +1 -0
- package/build/plugin/src/ios/utils/paths.d.ts +128 -0
- package/build/plugin/src/ios/utils/paths.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/paths.js +141 -0
- package/build/plugin/src/ios/utils/paths.js.map +1 -0
- package/build/plugin/src/ios/utils/plist.d.ts +29 -0
- package/build/plugin/src/ios/utils/plist.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/plist.js +114 -0
- package/build/plugin/src/ios/utils/plist.js.map +1 -0
- package/build/plugin/src/ios/utils/podfile.d.ts +82 -0
- package/build/plugin/src/ios/utils/podfile.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/podfile.js +408 -0
- package/build/plugin/src/ios/utils/podfile.js.map +1 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.d.ts +11 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.js +263 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.js.map +1 -0
- package/build/plugin/src/ios/utils/xcode.d.ts +185 -0
- package/build/plugin/src/ios/utils/xcode.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/xcode.js +706 -0
- package/build/plugin/src/ios/utils/xcode.js.map +1 -0
- package/build/plugin/src/logger.d.ts +10 -0
- package/build/plugin/src/logger.d.ts.map +1 -0
- package/build/plugin/src/logger.js +62 -0
- package/build/plugin/src/logger.js.map +1 -0
- package/build/plugin/src/parseTargetConfig.d.ts +3 -0
- package/build/plugin/src/parseTargetConfig.d.ts.map +1 -0
- package/build/plugin/src/parseTargetConfig.js +113 -0
- package/build/plugin/src/parseTargetConfig.js.map +1 -0
- package/build/plugin/src/withTargetsDir.d.ts +6 -0
- package/build/plugin/src/withTargetsDir.d.ts.map +1 -0
- package/build/plugin/src/withTargetsDir.js +90 -0
- package/build/plugin/src/withTargetsDir.js.map +1 -0
- package/build/src/Target.d.ts +43 -0
- package/build/src/Target.d.ts.map +1 -0
- package/build/src/Target.js +128 -0
- package/build/src/Target.js.map +1 -0
- package/build/src/index.d.ts +9 -0
- package/build/src/index.d.ts.map +1 -0
- package/build/src/index.js +27 -0
- package/build/src/index.js.map +1 -0
- package/build/src/modules/extension/index.d.ts +18 -0
- package/build/src/modules/extension/index.d.ts.map +1 -0
- package/build/src/modules/extension/index.js +44 -0
- package/build/src/modules/extension/index.js.map +1 -0
- package/build/src/modules/messages/index.d.ts +40 -0
- package/build/src/modules/messages/index.d.ts.map +1 -0
- package/build/src/modules/messages/index.js +94 -0
- package/build/src/modules/messages/index.js.map +1 -0
- package/build/src/modules/storage/index.d.ts +16 -0
- package/build/src/modules/storage/index.d.ts.map +1 -0
- package/build/src/modules/storage/index.js +122 -0
- package/build/src/modules/storage/index.js.map +1 -0
- package/expo-module.config.json +17 -0
- package/ios/ExpoTargetsExtension.podspec +23 -0
- package/ios/ExpoTargetsExtensionModule.swift +181 -0
- package/ios/ExpoTargetsMessages.podspec +23 -0
- package/ios/ExpoTargetsMessagesModule.swift +267 -0
- package/ios/ExpoTargetsStorage.podspec +23 -0
- package/ios/ExpoTargetsStorageModule.swift +91 -0
- package/ios/Tests/.swiftlint.yml +52 -0
- package/ios/Tests/Helpers/MockExtensionContext.swift +58 -0
- package/ios/Tests/Helpers/MockUserDefaults.swift +70 -0
- package/ios/Tests/Helpers/MockWidgetCenter.swift +71 -0
- package/ios/Tests/Helpers/TestHelpers.swift +90 -0
- package/ios/Tests/Integration/TargetIntegrationTests.swift +478 -0
- package/ios/Tests/Main/AllTests.swift +80 -0
- package/ios/Tests/Package.swift +66 -0
- package/ios/Tests/Performance/StoragePerformanceTests.swift +461 -0
- package/ios/Tests/Unit/Extension/ExpoTargetsExtensionModuleTests.swift +501 -0
- package/ios/Tests/Unit/Storage/ExpoTargetsStorageModuleTests.swift +578 -0
- package/ios/Tests/Unit/Template/ShareExtensionTemplateTests.swift +421 -0
- package/ios/Tests/XCTestPlan.xctestplan +87 -0
- package/metro/src/index.ts +1 -0
- package/metro/src/withTargetsMetro.ts +247 -0
- package/metro/tsconfig.build.json +9 -0
- package/package.json +74 -0
- package/plugin/src/android/withAndroidAppBuildGradle.ts +34 -0
- package/plugin/src/android/withAndroidTarget.ts +26 -0
- package/plugin/src/android/withAndroidWidget.ts +778 -0
- package/plugin/src/config.ts +255 -0
- package/plugin/src/index.ts +19 -0
- package/plugin/src/ios/config-plugins/withEntitlements.ts +69 -0
- package/plugin/src/ios/config-plugins/withIOSTarget.ts +179 -0
- package/plugin/src/ios/config-plugins/withIosColorset.ts +29 -0
- package/plugin/src/ios/config-plugins/withIosStickerPack.ts +65 -0
- package/plugin/src/ios/config-plugins/withPodfile.ts +238 -0
- package/plugin/src/ios/config-plugins/withXcodeChanges.ts +891 -0
- package/plugin/src/ios/target.ts +668 -0
- package/plugin/src/ios/templates/MessagesViewController.swift +120 -0
- package/plugin/src/ios/templates/ReactNativeViewController.swift +240 -0
- package/plugin/src/ios/templates/action-extension-data.swift +106 -0
- package/plugin/src/ios/templates/clip-extension-data.swift +28 -0
- package/plugin/src/ios/templates/messages-extension-data.swift +28 -0
- package/plugin/src/ios/templates/share-extension-data.swift +113 -0
- package/plugin/src/ios/utils/asset.ts +490 -0
- package/plugin/src/ios/utils/file.ts +80 -0
- package/plugin/src/ios/utils/index.ts +12 -0
- package/plugin/src/ios/utils/paths.ts +253 -0
- package/plugin/src/ios/utils/plist.ts +101 -0
- package/plugin/src/ios/utils/podfile.ts +534 -0
- package/plugin/src/ios/utils/reactNativeSwift.ts +283 -0
- package/plugin/src/ios/utils/xcode.ts +989 -0
- package/plugin/src/logger.ts +63 -0
- package/plugin/src/parseTargetConfig.ts +115 -0
- package/plugin/src/types/normalize-colors.d.ts +3 -0
- package/plugin/src/withTargetsDir.ts +120 -0
- package/plugin/tsconfig.build.json +9 -0
- package/plugin/tsconfig.json +9 -0
- package/src/Target.ts +239 -0
- package/src/index.ts +52 -0
- package/src/modules/extension/index.ts +54 -0
- package/src/modules/messages/index.ts +124 -0
- package/src/modules/storage/index.ts +126 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
import Messages
|
|
3
|
+
import UIKit
|
|
4
|
+
|
|
5
|
+
public class ExpoTargetsMessagesModule: Module {
|
|
6
|
+
private var notificationObserver: NSObjectProtocol?
|
|
7
|
+
|
|
8
|
+
deinit {
|
|
9
|
+
if let observer = notificationObserver {
|
|
10
|
+
NotificationCenter.default.removeObserver(observer)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public func definition() -> ModuleDefinition {
|
|
15
|
+
Name("ExpoTargetsMessages")
|
|
16
|
+
|
|
17
|
+
OnCreate {
|
|
18
|
+
self.notificationObserver = NotificationCenter.default.addObserver(
|
|
19
|
+
forName: NSNotification.Name("MSMessagesAppPresentationStyleDidChange"),
|
|
20
|
+
object: nil,
|
|
21
|
+
queue: .main
|
|
22
|
+
) { [weak self] notification in
|
|
23
|
+
if let style = notification.userInfo?["presentationStyle"] as? String {
|
|
24
|
+
self?.sendEvent("onPresentationStyleChange", [
|
|
25
|
+
"presentationStyle": style
|
|
26
|
+
])
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Get current presentation style
|
|
32
|
+
Function("getPresentationStyle") { () -> String? in
|
|
33
|
+
guard let msViewController = self.findMessagesViewController() else {
|
|
34
|
+
return nil
|
|
35
|
+
}
|
|
36
|
+
return msViewController.presentationStyle == .compact ? "compact" : "expanded"
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Request presentation style change
|
|
40
|
+
Function("requestPresentationStyle") { (style: String) -> Void in
|
|
41
|
+
DispatchQueue.main.async {
|
|
42
|
+
guard let msViewController = self.findMessagesViewController() else {
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let presentationStyle: MSMessagesAppPresentationStyle =
|
|
47
|
+
style == "compact" ? .compact : .expanded
|
|
48
|
+
msViewController.requestPresentationStyle(presentationStyle)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Send message with full layout options
|
|
53
|
+
Function("sendMessage") { (layout: [String: Any]) -> Void in
|
|
54
|
+
DispatchQueue.main.async {
|
|
55
|
+
guard let msViewController = self.findMessagesViewController(),
|
|
56
|
+
let conversation = msViewController.activeConversation else {
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let message = MSMessage()
|
|
61
|
+
let messageLayout = MSMessageTemplateLayout()
|
|
62
|
+
|
|
63
|
+
if let caption = layout["caption"] as? String {
|
|
64
|
+
messageLayout.caption = caption
|
|
65
|
+
}
|
|
66
|
+
if let subcaption = layout["subcaption"] as? String {
|
|
67
|
+
messageLayout.subcaption = subcaption
|
|
68
|
+
}
|
|
69
|
+
if let trailing = layout["trailingCaption"] as? String {
|
|
70
|
+
messageLayout.trailingCaption = trailing
|
|
71
|
+
}
|
|
72
|
+
if let trailingSub = layout["trailingSubcaption"] as? String {
|
|
73
|
+
messageLayout.trailingSubcaption = trailingSub
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Handle image (SF Symbol or local file)
|
|
77
|
+
if let imageUrl = layout["imageUrl"] as? String {
|
|
78
|
+
if imageUrl.starts(with: "file://") || imageUrl.starts(with: "/") {
|
|
79
|
+
messageLayout.image = UIImage(contentsOfFile: imageUrl)
|
|
80
|
+
} else {
|
|
81
|
+
messageLayout.image = UIImage(systemName: imageUrl)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Handle custom URL
|
|
86
|
+
if let urlString = layout["url"] as? String, let url = URL(string: urlString) {
|
|
87
|
+
message.url = url
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
message.layout = messageLayout
|
|
91
|
+
|
|
92
|
+
conversation.insert(message) { error in
|
|
93
|
+
if error != nil {
|
|
94
|
+
// Error handling
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Send update to existing message
|
|
101
|
+
Function("sendUpdate") { (layout: [String: Any], sessionId: String) -> Void in
|
|
102
|
+
DispatchQueue.main.async {
|
|
103
|
+
guard let msViewController = self.findMessagesViewController(),
|
|
104
|
+
let conversation = msViewController.activeConversation else {
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Reuse session from selected message if available, otherwise create new
|
|
109
|
+
let session = conversation.selectedMessage?.session ?? MSSession()
|
|
110
|
+
let message = MSMessage(session: session)
|
|
111
|
+
let messageLayout = MSMessageTemplateLayout()
|
|
112
|
+
|
|
113
|
+
// Same layout setup as sendMessage
|
|
114
|
+
if let caption = layout["caption"] as? String {
|
|
115
|
+
messageLayout.caption = caption
|
|
116
|
+
}
|
|
117
|
+
if let subcaption = layout["subcaption"] as? String {
|
|
118
|
+
messageLayout.subcaption = subcaption
|
|
119
|
+
}
|
|
120
|
+
if let trailing = layout["trailingCaption"] as? String {
|
|
121
|
+
messageLayout.trailingCaption = trailing
|
|
122
|
+
}
|
|
123
|
+
if let trailingSub = layout["trailingSubcaption"] as? String {
|
|
124
|
+
messageLayout.trailingSubcaption = trailingSub
|
|
125
|
+
}
|
|
126
|
+
if let imageUrl = layout["imageUrl"] as? String {
|
|
127
|
+
if imageUrl.starts(with: "file://") || imageUrl.starts(with: "/") {
|
|
128
|
+
messageLayout.image = UIImage(contentsOfFile: imageUrl)
|
|
129
|
+
} else {
|
|
130
|
+
messageLayout.image = UIImage(systemName: imageUrl)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if let urlString = layout["url"] as? String, let url = URL(string: urlString) {
|
|
134
|
+
message.url = url
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
message.layout = messageLayout
|
|
138
|
+
|
|
139
|
+
conversation.insert(message) { error in
|
|
140
|
+
if error != nil {
|
|
141
|
+
// Error handling
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Create new session ID
|
|
148
|
+
// Note: MSSession doesn't expose identifier, so we generate a UUID for tracking
|
|
149
|
+
Function("createSession") { () -> String in
|
|
150
|
+
return UUID().uuidString
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Get conversation info
|
|
154
|
+
Function("getConversationInfo") { () -> [String: Any]? in
|
|
155
|
+
guard let msViewController = self.findMessagesViewController(),
|
|
156
|
+
let conversation = msViewController.activeConversation else {
|
|
157
|
+
return nil
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return [
|
|
161
|
+
"conversationId": conversation.localParticipantIdentifier.uuidString,
|
|
162
|
+
"remoteParticipantIds": conversation.remoteParticipantIdentifiers.map { $0.uuidString },
|
|
163
|
+
"participantCount": conversation.remoteParticipantIdentifiers.count + 1,
|
|
164
|
+
"hasSelectedMessage": conversation.selectedMessage != nil
|
|
165
|
+
]
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Event for presentation style changes
|
|
169
|
+
Events("onPresentationStyleChange")
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private func findMessagesViewController() -> MSMessagesAppViewController? {
|
|
173
|
+
// First, try to get the shared instance from MessagesViewController
|
|
174
|
+
// Swift classes need module-qualified names for NSClassFromString
|
|
175
|
+
// Try common patterns: MessagesViewController, <ModuleName>.MessagesViewController
|
|
176
|
+
let classNames = [
|
|
177
|
+
"MessagesViewController",
|
|
178
|
+
"\(Bundle.main.infoDictionary?["CFBundleExecutable"] as? String ?? "").MessagesViewController"
|
|
179
|
+
]
|
|
180
|
+
|
|
181
|
+
for className in classNames {
|
|
182
|
+
if let viewControllerClass = NSClassFromString(className) as? NSObject.Type {
|
|
183
|
+
if let sharedInstance = viewControllerClass.value(forKey: "shared") as? MSMessagesAppViewController {
|
|
184
|
+
return sharedInstance
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Fallback: Get windows using modern API for iOS 15+ or legacy API for older versions
|
|
190
|
+
let windows: [UIWindow]
|
|
191
|
+
if #available(iOS 15.0, *) {
|
|
192
|
+
let scenes = UIApplication.shared.connectedScenes
|
|
193
|
+
let windowScenes = scenes.compactMap { $0 as? UIWindowScene }
|
|
194
|
+
windows = windowScenes.flatMap { $0.windows }
|
|
195
|
+
} else {
|
|
196
|
+
windows = UIApplication.shared.windows
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Try key window first
|
|
200
|
+
if let keyWindow = windows.first(where: { $0.isKeyWindow }),
|
|
201
|
+
let rootVC = keyWindow.rootViewController {
|
|
202
|
+
if let msViewController = findMessagesViewController(in: rootVC) {
|
|
203
|
+
return msViewController
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Fallback: search all windows
|
|
208
|
+
for window in windows {
|
|
209
|
+
if let rootVC = window.rootViewController {
|
|
210
|
+
if let msViewController = findMessagesViewController(in: rootVC) {
|
|
211
|
+
return msViewController
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return nil
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private func findMessagesViewController(in viewController: UIViewController) -> MSMessagesAppViewController? {
|
|
220
|
+
// Check if this view controller is MSMessagesAppViewController
|
|
221
|
+
if let msViewController = viewController as? MSMessagesAppViewController {
|
|
222
|
+
return msViewController
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Check parent first (React Native runs inside Messages extension as a child)
|
|
226
|
+
if let parent = viewController.parent {
|
|
227
|
+
if let msViewController = findMessagesViewController(in: parent) {
|
|
228
|
+
return msViewController
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Then check children
|
|
233
|
+
for childVC in viewController.children {
|
|
234
|
+
if let msViewController = findMessagesViewController(in: childVC) {
|
|
235
|
+
return msViewController
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Check presented view controllers
|
|
240
|
+
if let presented = viewController.presentedViewController {
|
|
241
|
+
if let msViewController = findMessagesViewController(in: presented) {
|
|
242
|
+
return msViewController
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Check navigation controller
|
|
247
|
+
if let navController = viewController as? UINavigationController {
|
|
248
|
+
if let topVC = navController.topViewController {
|
|
249
|
+
if let msViewController = findMessagesViewController(in: topVC) {
|
|
250
|
+
return msViewController
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Check tab controller
|
|
256
|
+
if let tabController = viewController as? UITabBarController {
|
|
257
|
+
if let selectedVC = tabController.selectedViewController {
|
|
258
|
+
if let msViewController = findMessagesViewController(in: selectedVC) {
|
|
259
|
+
return msViewController
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return nil
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, '../package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'ExpoTargetsStorage'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.description = 'Expo Targets Storage Module - App Group storage and widget refresh functionality'
|
|
10
|
+
s.license = package['license']
|
|
11
|
+
s.authors = package['author']
|
|
12
|
+
s.homepage = package['homepage']
|
|
13
|
+
s.platforms = { :ios => '13.0' }
|
|
14
|
+
s.swift_version = '5.4'
|
|
15
|
+
s.source = { :git => package['repository']['url'], :tag => "v#{package['version']}" }
|
|
16
|
+
s.static_framework = true
|
|
17
|
+
|
|
18
|
+
s.dependency 'ExpoModulesCore'
|
|
19
|
+
|
|
20
|
+
s.source_files = "**/*.{h,m,mm,swift,hpp,cpp}"
|
|
21
|
+
s.exclude_files = "Tests/**/*"
|
|
22
|
+
end
|
|
23
|
+
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
import WidgetKit
|
|
3
|
+
|
|
4
|
+
public class ExpoTargetsStorageModule: Module {
|
|
5
|
+
public func definition() -> ModuleDefinition {
|
|
6
|
+
Name("ExpoTargetsStorage")
|
|
7
|
+
|
|
8
|
+
Function("setInt") { (key: String, value: Int, suite: String?) -> Void in
|
|
9
|
+
let defaults = UserDefaults(suiteName: suite ?? "")
|
|
10
|
+
defaults?.set(value, forKey: key)
|
|
11
|
+
defaults?.synchronize()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
Function("setString") { (key: String, value: String, suite: String?) -> Void in
|
|
15
|
+
let defaults = UserDefaults(suiteName: suite ?? "")
|
|
16
|
+
defaults?.set(value, forKey: key)
|
|
17
|
+
defaults?.synchronize()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
Function("setObject") { (key: String, value: [String: Any], suite: String?) -> Bool in
|
|
21
|
+
let defaults = UserDefaults(suiteName: suite ?? "")
|
|
22
|
+
defaults?.set(value, forKey: key)
|
|
23
|
+
defaults?.synchronize()
|
|
24
|
+
return true
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
Function("get") { (key: String, suite: String?) -> String? in
|
|
28
|
+
let defaults = UserDefaults(suiteName: suite ?? "")
|
|
29
|
+
return defaults?.string(forKey: key)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Function("remove") { (key: String, suite: String?) -> Void in
|
|
33
|
+
let defaults = UserDefaults(suiteName: suite ?? "")
|
|
34
|
+
defaults?.removeObject(forKey: key)
|
|
35
|
+
defaults?.synchronize()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Function("getAllKeys") { (suite: String?) -> [String] in
|
|
39
|
+
let defaults = UserDefaults(suiteName: suite ?? "")
|
|
40
|
+
guard let dict = defaults?.dictionaryRepresentation() else {
|
|
41
|
+
return []
|
|
42
|
+
}
|
|
43
|
+
return Array(dict.keys)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
Function("getAllData") { (suite: String?) -> [String: Any] in
|
|
47
|
+
let defaults = UserDefaults(suiteName: suite ?? "")
|
|
48
|
+
return defaults?.dictionaryRepresentation() ?? [:]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
Function("clearAll") { (suite: String?) -> Void in
|
|
52
|
+
let defaults = UserDefaults(suiteName: suite ?? "")
|
|
53
|
+
guard let dict = defaults?.dictionaryRepresentation() else {
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
for key in dict.keys {
|
|
57
|
+
defaults?.removeObject(forKey: key)
|
|
58
|
+
}
|
|
59
|
+
defaults?.synchronize()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
Function("refreshTarget") { (name: String?) -> Void in
|
|
63
|
+
// Refresh widgets
|
|
64
|
+
if #available(iOS 14.0, *) {
|
|
65
|
+
if let targetName = name {
|
|
66
|
+
WidgetCenter.shared.reloadTimelines(ofKind: targetName)
|
|
67
|
+
} else {
|
|
68
|
+
WidgetCenter.shared.reloadAllTimelines()
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Refresh controls (iOS 18+)
|
|
73
|
+
if #available(iOS 18.0, *) {
|
|
74
|
+
if let targetName = name {
|
|
75
|
+
ControlCenter.shared.reloadControls(ofKind: targetName)
|
|
76
|
+
} else {
|
|
77
|
+
ControlCenter.shared.reloadAllControls()
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
Function("getTargetsConfig") { () -> [[String: Any]]? in
|
|
83
|
+
// Read targets config from bundle's Info.plist
|
|
84
|
+
guard let config = Bundle.main.object(forInfoDictionaryKey: "ExpoTargetsConfig") as? [[String: Any]] else {
|
|
85
|
+
return nil
|
|
86
|
+
}
|
|
87
|
+
return config
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# SwiftLint configuration for test code
|
|
2
|
+
|
|
3
|
+
disabled_rules:
|
|
4
|
+
- line_length # Tests can have longer descriptive names
|
|
5
|
+
- function_body_length # Tests can be longer for thorough verification
|
|
6
|
+
- file_length # Test files can be comprehensive
|
|
7
|
+
- type_body_length # Test classes can have many test methods
|
|
8
|
+
- force_cast # Sometimes needed in tests for clarity
|
|
9
|
+
- force_try # Acceptable in test setup/teardown
|
|
10
|
+
|
|
11
|
+
opt_in_rules:
|
|
12
|
+
- empty_count
|
|
13
|
+
- explicit_init
|
|
14
|
+
- first_where
|
|
15
|
+
- sorted_imports
|
|
16
|
+
- vertical_whitespace_closing_braces
|
|
17
|
+
- vertical_whitespace_opening_braces
|
|
18
|
+
|
|
19
|
+
excluded:
|
|
20
|
+
- Pods
|
|
21
|
+
- build
|
|
22
|
+
- .build
|
|
23
|
+
|
|
24
|
+
# Custom rule adjustments for tests
|
|
25
|
+
function_parameter_count:
|
|
26
|
+
warning: 8
|
|
27
|
+
error: 10
|
|
28
|
+
|
|
29
|
+
nesting:
|
|
30
|
+
type_level:
|
|
31
|
+
warning: 3
|
|
32
|
+
|
|
33
|
+
identifier_name:
|
|
34
|
+
min_length:
|
|
35
|
+
warning: 1
|
|
36
|
+
excluded:
|
|
37
|
+
- i
|
|
38
|
+
- j
|
|
39
|
+
- k
|
|
40
|
+
- id
|
|
41
|
+
- url
|
|
42
|
+
- URL
|
|
43
|
+
|
|
44
|
+
# Test-specific naming
|
|
45
|
+
test_case_accessibility:
|
|
46
|
+
allowed_prefixes:
|
|
47
|
+
- test
|
|
48
|
+
|
|
49
|
+
# Cyclomatic complexity - more lenient for tests
|
|
50
|
+
cyclomatic_complexity:
|
|
51
|
+
warning: 15
|
|
52
|
+
error: 20
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
#if canImport(UIKit)
|
|
3
|
+
import UIKit
|
|
4
|
+
#endif
|
|
5
|
+
|
|
6
|
+
/// Mock NSExtensionContext for testing extension functionality
|
|
7
|
+
public class MockExtensionContext: NSExtensionContext {
|
|
8
|
+
public var completeRequestCalled = false
|
|
9
|
+
public var cancelRequestCalled = false
|
|
10
|
+
public var completionItems: [Any]?
|
|
11
|
+
public var mockInputItems: [NSExtensionItem] = []
|
|
12
|
+
|
|
13
|
+
public override var inputItems: [Any] {
|
|
14
|
+
get { return mockInputItems }
|
|
15
|
+
set { mockInputItems = newValue as? [NSExtensionItem] ?? [] }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public override func completeRequest(returningItems items: [Any]?, completionHandler: ((Bool) -> Void)? = nil) {
|
|
19
|
+
completeRequestCalled = true
|
|
20
|
+
completionItems = items
|
|
21
|
+
completionHandler?(true)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public override func cancelRequest(withError error: Error) {
|
|
25
|
+
cancelRequestCalled = true
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Test helpers
|
|
29
|
+
public func reset() {
|
|
30
|
+
completeRequestCalled = false
|
|
31
|
+
cancelRequestCalled = false
|
|
32
|
+
completionItems = nil
|
|
33
|
+
mockInputItems = []
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public func addMockTextItem(_ text: String) {
|
|
37
|
+
let item = NSExtensionItem()
|
|
38
|
+
let itemProvider = NSItemProvider(item: text as NSString, typeIdentifier: "public.plain-text")
|
|
39
|
+
item.attachments = [itemProvider]
|
|
40
|
+
mockInputItems.append(item)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public func addMockURLItem(_ url: URL) {
|
|
44
|
+
let item = NSExtensionItem()
|
|
45
|
+
let itemProvider = NSItemProvider(item: url as NSURL, typeIdentifier: "public.url")
|
|
46
|
+
item.attachments = [itemProvider]
|
|
47
|
+
mockInputItems.append(item)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#if canImport(UIKit)
|
|
51
|
+
public func addMockImageItem(_ image: UIImage) {
|
|
52
|
+
let item = NSExtensionItem()
|
|
53
|
+
let itemProvider = NSItemProvider(item: image, typeIdentifier: "public.image")
|
|
54
|
+
item.attachments = [itemProvider]
|
|
55
|
+
mockInputItems.append(item)
|
|
56
|
+
}
|
|
57
|
+
#endif
|
|
58
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// Mock UserDefaults for testing without affecting real app storage
|
|
4
|
+
public class MockUserDefaults: UserDefaults {
|
|
5
|
+
private var storage: [String: Any] = [:]
|
|
6
|
+
private var synchronizeCalled = false
|
|
7
|
+
|
|
8
|
+
public override init?(suiteName suitename: String?) {
|
|
9
|
+
super.init(suiteName: suitename)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public override func set(_ value: Any?, forKey defaultName: String) {
|
|
13
|
+
if let value = value {
|
|
14
|
+
storage[defaultName] = value
|
|
15
|
+
} else {
|
|
16
|
+
storage.removeValue(forKey: defaultName)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public override func set(_ value: Int, forKey defaultName: String) {
|
|
21
|
+
storage[defaultName] = value
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public override func string(forKey defaultName: String) -> String? {
|
|
25
|
+
return storage[defaultName] as? String
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public override func integer(forKey defaultName: String) -> Int {
|
|
29
|
+
return storage[defaultName] as? Int ?? 0
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public override func bool(forKey defaultName: String) -> Bool {
|
|
33
|
+
return storage[defaultName] as? Bool ?? false
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public override func object(forKey defaultName: String) -> Any? {
|
|
37
|
+
return storage[defaultName]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public override func removeObject(forKey defaultName: String) {
|
|
41
|
+
storage.removeValue(forKey: defaultName)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public override func dictionaryRepresentation() -> [String : Any] {
|
|
45
|
+
return storage
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public override func synchronize() -> Bool {
|
|
49
|
+
synchronizeCalled = true
|
|
50
|
+
return true
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Test helpers
|
|
54
|
+
public func wasSynchronizeCalled() -> Bool {
|
|
55
|
+
return synchronizeCalled
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public func resetSynchronizeFlag() {
|
|
59
|
+
synchronizeCalled = false
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public func clearStorage() {
|
|
63
|
+
storage.removeAll()
|
|
64
|
+
synchronizeCalled = false
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public func getStorageSize() -> Int {
|
|
68
|
+
return storage.count
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import WidgetKit
|
|
3
|
+
|
|
4
|
+
/// Mock WidgetCenter for testing widget refresh operations
|
|
5
|
+
@available(iOS 14.0, *)
|
|
6
|
+
public class MockWidgetCenter {
|
|
7
|
+
public static var shared = MockWidgetCenter()
|
|
8
|
+
|
|
9
|
+
public var reloadTimelinesCalled = false
|
|
10
|
+
public var reloadAllTimelinesCalled = false
|
|
11
|
+
public var lastReloadedKind: String?
|
|
12
|
+
public var reloadCount = 0
|
|
13
|
+
|
|
14
|
+
public func reloadTimelines(ofKind kind: String) {
|
|
15
|
+
reloadTimelinesCalled = true
|
|
16
|
+
lastReloadedKind = kind
|
|
17
|
+
reloadCount += 1
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public func reloadAllTimelines() {
|
|
21
|
+
reloadAllTimelinesCalled = true
|
|
22
|
+
reloadCount += 1
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public func getCurrentConfigurations(completion: @escaping (Result<[Any], Error>) -> Void) {
|
|
26
|
+
// Mock implementation
|
|
27
|
+
completion(.success([]))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Test helpers
|
|
31
|
+
public func reset() {
|
|
32
|
+
reloadTimelinesCalled = false
|
|
33
|
+
reloadAllTimelinesCalled = false
|
|
34
|
+
lastReloadedKind = nil
|
|
35
|
+
reloadCount = 0
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public func wasReloadCalled(forKind kind: String) -> Bool {
|
|
39
|
+
return reloadTimelinesCalled && lastReloadedKind == kind
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// Mock ControlCenter for testing iOS 18+ control refresh
|
|
44
|
+
@available(iOS 18.0, *)
|
|
45
|
+
public class MockControlCenter {
|
|
46
|
+
public static var shared = MockControlCenter()
|
|
47
|
+
|
|
48
|
+
public var reloadControlsCalled = false
|
|
49
|
+
public var reloadAllControlsCalled = false
|
|
50
|
+
public var lastReloadedKind: String?
|
|
51
|
+
public var reloadCount = 0
|
|
52
|
+
|
|
53
|
+
public func reloadControls(ofKind kind: String) {
|
|
54
|
+
reloadControlsCalled = true
|
|
55
|
+
lastReloadedKind = kind
|
|
56
|
+
reloadCount += 1
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public func reloadAllControls() {
|
|
60
|
+
reloadAllControlsCalled = true
|
|
61
|
+
reloadCount += 1
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Test helpers
|
|
65
|
+
public func reset() {
|
|
66
|
+
reloadControlsCalled = false
|
|
67
|
+
reloadAllControlsCalled = false
|
|
68
|
+
lastReloadedKind = nil
|
|
69
|
+
reloadCount = 0
|
|
70
|
+
}
|
|
71
|
+
}
|