bndkt / react-native-widget-extension

Add widgets and live activities to a React Native app
https://bndkt.com/blog/2023/ios-live-activities
437 stars 33 forks source link

No such module 'ReactNativeWidgetExtension' #5

Closed minuitagency closed 1 year ago

minuitagency commented 1 year ago

Hi,

Thanks for the great work, when trying to build, i get this issue:

12 | import ExpoLinearGradient
  13 | import ExpoSystemUI
> 14 | import ReactNativeWidgetExtension
     |        ^ no such module 'ReactNativeWidgetExtension'
  15 | 
  16 | @objc(ExpoModulesProvider)
  17 | public class ExpoModulesProvider: ModulesProvider {

expo app on macOS, i configured as the doc says and the widget is working in xcode,

Thanks,

Théo

bndkt commented 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?

Example: https://github.com/bndkt/react-native-widget-extension/blob/d7280ad4884d2c8365374166ec988ab0df09ded0/example/PizzaDeliveryWidgets/Module.swift#L10

minuitagency commented 1 year ago

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!

bndkt commented 1 year ago

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.

gitn00b1337 commented 1 year ago

I'm getting this issue on expo buildon the fastlane stage. Strangley it's all fine locally with expo startand expo run:ios. No idea what to check for, any ideas?

abelfiore commented 11 months ago

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" },
        ],
    ]
afloresmorales commented 7 months ago

I'm getting this issue on expo buildon the fastlane stage. Strangley it's all fine locally with expo startand expo 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.