Closed minuitagency closed 1 year ago
Did you make sure that your widget folder (the folder with the Swift files that you point to in the plugin's config) contains a file "Module.swift" that defines the ReactNativeWidgetExtensionModule module?
Hi Benedikt,
Thanks for your help, the widget and app are building now, i don't understand how to pass data to the widget as Module.swift seems to be designed to pass data to live activities;
Here's the widget code, not asking for you to do the work but if you could point me in the right direction:
`import WidgetKit import SwiftUI
extension Color { init(hex: UInt32) { let red = Double((hex & 0xFF0000) >> 16) / 255.0 let green = Double((hex & 0x00FF00) >> 8) / 255.0 let blue = Double(hex & 0x0000FF) / 255.0 self.init(red: red, green: green, blue: blue) } }
struct Provider: TimelineProvider { func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(ongoingTasks: 0, averageTaskTime: "00:00", estimatedDeliveryDate: Date()) }
func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
// Remplacez cette ligne avec un nombre de tâches par défaut ou zéro
let entry = SimpleEntry(ongoingTasks: 0, averageTaskTime: "00:00", estimatedDeliveryDate: Date())
completion(entry)
}
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
let currentDate = Date()
// Remplacez cette ligne avec un nombre de tâches par défaut ou zéro
let entry = SimpleEntry(estimatedDeliveryDate: currentDate, ongoingTasks: 0)
let timeline = Timeline(entries: [entry], policy: .never)
completion(timeline)
}
}
struct SimpleEntry: TimelineEntry { let ongoingTasks: Int let averageTaskTime: String let estimatedDeliveryDate: Date }
struct CustomTaskWidgetsEntryView : View { var entry: Provider.Entry
var dateFormatter: DateFormatter {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "fr_FR")
formatter.dateStyle = .medium
return formatter
}
func convertToDays(time: String) -> String {
let timeComponents = time.split(separator: ":").compactMap { Double($0) }
guard timeComponents.count == 2 else { return "N/A" }
let hours = timeComponents[0]
let minutes = timeComponents[1]
let days = (hours + minutes / 60.0) / 24.0
return String(format: "%.1f jours", days)
}
var dataSections: [(title: String, value: String)] {
return [
("Tâches en cours", "\(entry.ongoingTasks) tâches"),
("Temps par tâche", convertToDays(time: entry.averageTaskTime)),
("Date de fin", dateFormatter.string(from: entry.estimatedDeliveryDate))
]
}
var body: some View {
ZStack {
Color(hex: 0x0F0C14).edgesIgnoringSafeArea(.all)
VStack(alignment: .leading, spacing: 10) {
ForEach(dataSections, id: \.title) { section in
VStack(alignment: .leading, spacing: 0) {
Text(section.title)
.font(.system(size: 10))
.foregroundColor(.white)
.opacity(0.5)
Text(section.value)
.font(.custom("NewYorkLarge-Semibold", size: 15))
.foregroundColor(.white)
}
.frame(maxWidth: .infinity, alignment: .leading)
}
}
.padding()
}
}
}
struct CustomTaskWidgets: Widget { let kind: String = "CustomTaskWidgets"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
CustomTaskWidgetsEntryView(entry: entry)
}
.configurationDisplayName("My Widget")
.description("This is an example widget.")
}
}
struct CustomTaskWidgets_Previews: PreviewProvider { static var previews: some View { CustomTaskWidgetsEntryView(entry: SimpleEntry(ongoingTasks: 5, averageTaskTime: "02:30", estimatedDeliveryDate: Date())) .previewContext(WidgetPreviewContext(family: .systemSmall)) } } `
Thanks!
This error appears if the package is installed but the plug-in is not included in app.json or app.config.js and is due to the nature of this module/plugin. @minuitagency if you still run into problems please open a new issue and provide a minimal reproducible example.
I'm getting this issue on expo build
on the fastlane stage. Strangley it's all fine locally with expo start
and expo run:ios.
No idea what to check for, any ideas?
Also seeing this issue, but in my case I'm using an app.config.ts
(and running bare). I also noticed that running npx expo prebuild
with your plugin is throwing errors too.
Suggestions anyone?
I noticed your great blog post had this
{
"plugins": [
[
"../app.plugin.js",
{ "frequentUpdates": true, "widgetsFolder": "SampleWidgetExtension" }
]
]
}
But your readme has this
"plugins": [
[
"react-native-widget-extension",
{ "frequentUpdates": true, "widgetsFolder": "_widgets/PizzaDelivery" },
],
]
I'm getting this issue on
expo build
on the fastlane stage. Strangley it's all fine locally withexpo start
andexpo run:ios.
No idea what to check for, any ideas?
Hi @gitn00b1337, were you able to fix this issue? I'm also getting this error when running eas build.
Hi,
Thanks for the great work, when trying to build, i get this issue:
expo app on macOS, i configured as the doc says and the widget is working in xcode,
Thanks,
Théo