Skip to content

Translations (.lproj folders) in widgets breaks prebuild #41

@madsbrydegaard

Description

@madsbrydegaard

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-widget-extension@0.2.0 for the project I'm working on.

If the widget contains translations in .lproj folders then prebuild breaks due to missing support for lproj folders in the file copy phase of the extension. I have created a patch to make it work

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-widget-extension/ios/Attributes.swift b/node_modules/react-native-widget-extension/ios/Attributes.swift
new file mode 100644
index 0000000..68c8dd1
--- /dev/null
+++ b/node_modules/react-native-widget-extension/ios/Attributes.swift
@@ -0,0 +1,3 @@
+import ActivityKit
+import WidgetKit
+import SwiftUI
\ No newline at end of file
diff --git a/node_modules/react-native-widget-extension/ios/Module.swift b/node_modules/react-native-widget-extension/ios/Module.swift
new file mode 100644
index 0000000..ccc687a
--- /dev/null
+++ b/node_modules/react-native-widget-extension/ios/Module.swift
@@ -0,0 +1,81 @@
+import ExpoModulesCore
+import ActivityKit
+
+internal class MissingCurrentWindowSceneException: Exception {
+    override var reason: String {
+        "Cannot determine the current window scene in which to present the modal for requesting a review."
+    }
+}
+
+public class ReactNativeWidgetExtensionModule: Module {
+    public func definition() -> ModuleDefinition {
+        Name("ReactNativeWidgetExtension")
+        
+        // Function("areActivitiesEnabled") { () -> Bool in
+        //     let logger = Logger(logHandlers: [])
+        //     logger.info("areActivitiesEnabled()")
+            
+        //     if #available(iOS 16.2, *) {
+        //         return ActivityAuthorizationInfo().areActivitiesEnabled
+        //     } else {
+        //         return false
+        //     }
+        // }
+        
+        // Function("startActivity") { (quarter: Int, scoreLeft: Int, scoreRight: Int, bottomText: String) -> Void in
+        //     let logger = Logger(logHandlers: [])
+        //     logger.info("startActivity()")
+            
+        //     if #available(iOS 16.2, *) {
+        //         let future = Calendar.current.date(byAdding: .minute, value: (Int(15) ), to: Date())!
+        //         let attributes = SportsLiveActivityAttributes(timer: Date.now...future, imageLeft: "Knights", teamNameLeft: "Knights", imageRight: "Pirates", teamNameRight: "Pirates", gameName: "Western Conference Round 1")
+        //         let contentState = SportsLiveActivityAttributes.ContentState(quarter: quarter, scoreLeft: scoreLeft, scoreRight: scoreRight, bottomText: bottomText)
+                
+        //         let activityContent = ActivityContent(state: contentState, staleDate: Calendar.current.date(byAdding: .minute, value: 30, to: Date())!)
+                
+        //         do {
+        //             let activity = try Activity.request(attributes: attributes, content: activityContent)
+        //             logger.info("Requested a Live Activity \(String(describing: activity.id)).")
+        //         } catch (let error) {
+        //             logger.info("Error requesting Live Activity \(error.localizedDescription).")
+        //         }
+        //     }
+        // }
+
+        // Function("updateActivity") { (quarter: Int, scoreLeft: Int, scoreRight: Int, bottomText: String) -> Void in
+        //     let logger = Logger(logHandlers: [])
+        //     logger.info("updateActivity()")
+            
+        //     if #available(iOS 16.2, *) {
+        //         let future = Calendar.current.date(byAdding: .minute, value: (Int(15) ), to: Date())!
+        //         let contentState = SportsLiveActivityAttributes.ContentState(quarter: quarter, scoreLeft: scoreLeft, scoreRight: scoreRight, bottomText: bottomText)
+        //         let alertConfiguration = AlertConfiguration(title: "Score update", body: "This is the alert text", sound: .default)
+        //         let updatedContent = ActivityContent(state: contentState, staleDate: nil)
+                
+        //         Task {
+        //             for activity in Activity<SportsLiveActivityAttributes>.activities {
+        //                 await activity.update(updatedContent, alertConfiguration: alertConfiguration)
+        //                 logger.info("Updated the Live Activity: \(activity.id)")
+        //             }
+        //         }
+        //     }
+        // }
+        
+        // Function("endActivity") { (quarter: Int, scoreLeft: Int, scoreRight: Int, bottomText: String) -> Void in
+        //     let logger = Logger(logHandlers: [])
+        //     logger.info("endActivity()")
+            
+        //     if #available(iOS 16.2, *) {
+        //         let contentState = SportsLiveActivityAttributes.ContentState(quarter: quarter, scoreLeft: scoreLeft, scoreRight: scoreRight, bottomText: bottomText)
+        //         let finalContent = ActivityContent(state: contentState, staleDate: nil)
+                
+        //         Task {
+        //             for activity in Activity<SportsLiveActivityAttributes>.activities {
+        //                 await activity.end(finalContent, dismissalPolicy: .default)
+        //                 logger.info("Ending the Live Activity: \(activity.id)")
+        //             }
+        //         }
+        //     }
+        // }
+    }
+}
\ No newline at end of file
diff --git a/node_modules/react-native-widget-extension/plugin/build/lib/getWidgetFiles.js b/node_modules/react-native-widget-extension/plugin/build/lib/getWidgetFiles.js
index dc0719e..a9df56c 100644
--- a/node_modules/react-native-widget-extension/plugin/build/lib/getWidgetFiles.js
+++ b/node_modules/react-native-widget-extension/plugin/build/lib/getWidgetFiles.js
@@ -44,6 +44,7 @@ function getWidgetFiles(widgetsPath, targetPath, moduleFileName, attributesFileN
         plistFiles: [],
         assetDirectories: [],
         intentFiles: [],
+        lprojFolders: [],
         otherFiles: [],
     };
     if (!fs.existsSync(targetPath)) {
@@ -70,6 +71,9 @@ function getWidgetFiles(widgetsPath, targetPath, moduleFileName, attributesFileN
             else if (fileExtension === "intentdefinition") {
                 widgetFiles.intentFiles.push(file);
             }
+            else if (fileExtension === "lproj") {
+                widgetFiles.lprojFolders.push(file);
+            }
             else {
                 widgetFiles.otherFiles.push(file);
             }
@@ -95,6 +99,10 @@ function getWidgetFiles(widgetsPath, targetPath, moduleFileName, attributesFileN
         const imagesXcassetsSource = path.join(widgetsPath, directory);
         copyFolderRecursiveSync(imagesXcassetsSource, targetPath);
     });
+    widgetFiles.lprojFolders.forEach((directory) => {
+        const lprojSource = path.join(widgetsPath, directory);
+        copyFolderRecursiveSync(lprojSource, targetPath);
+    });
     return widgetFiles;
 }
 function copyFileSync(source, target) {

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions