gitn00b1337 / expo-widgets

Bringing widget functionality to expo!
110 stars 9 forks source link

Intents are not recognizable #5

Open st4l1nR opened 8 months ago

st4l1nR commented 8 months ago

Hello , I'm making my widget and it's running fine in xcode but when i tried to build the ios build whit expo it show the next errors `❌ (ios/flowwyWidgetExtension/RecordThought.swift:17:41)

15 | } 16 |

17 | func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) { | ^ cannot find type 'ConfigurationIntent' in scope 18 | let entry = SimpleEntry(date: Date(), configuration: configuration) 19 | completion(entry) 20 | }

❌ (ios/flowwyWidgetExtension/RecordThought.swift:22:41)

20 | } 21 |

22 | func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline) -> ()) { | ^ cannot find type 'ConfigurationIntent' in scope 23 | var entries: [SimpleEntry] = [] 24 | 25 | // Generate a timeline consisting of five entries an hour apart, starting from the current date.

❌ (ios/flowwyWidgetExtension/RecordThought.swift:12:8)

10 | import Intents 11 |

12 | struct Provider: IntentTimelineProvider { | ^ type 'Provider' does not conform to protocol 'IntentTimelineProvider' 13 | func placeholder(in context: Context) -> SimpleEntry { 14 | SimpleEntry(date: Date(), configuration: ConfigurationIntent()) 15 | }

❌ (ios/flowwyWidgetExtension/RecordThought.swift:40:24)

38 | struct SimpleEntry: TimelineEntry { 39 | let date: Date

40 | let configuration: ConfigurationIntent | ^ cannot find type 'ConfigurationIntent' in scope 41 | } 42 | 43 | struct RecordThoughtEntryView : View {

❌ (ios/flowwyWidgetExtension/RecordThought.swift:14:50)

12 | struct Provider: IntentTimelineProvider { 13 | func placeholder(in context: Context) -> SimpleEntry {

14 | SimpleEntry(date: Date(), configuration: ConfigurationIntent()) | ^ cannot find 'ConfigurationIntent' in scope 15 | } 16 | 17 | func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) {

❌ (ios/flowwyWidgetExtension/RecordThought.swift:70:49)

68 | 69 | var body: some WidgetConfiguration {

70 | IntentConfiguration(kind: kind, intent: ConfigurationIntent.self, provider: Provider()) { entry in | ^ cannot find 'ConfigurationIntent' in scope 71 | RecordThoughtEntryView(entry: entry) 72 | } 73 | .configurationDisplayName("Record thought")

❌ (ios/flowwyWidgetExtension/RecordThought.swift:81:80)

79 | struct RecordThought_Previews: PreviewProvider { 80 | static var previews: some View {

81 | RecordThoughtEntryView(entry: SimpleEntry(date: Date(), configuration: ConfigurationIntent())) | ^ cannot find 'ConfigurationIntent' in scope 82 | .previewContext(WidgetPreviewContext(family: .accessoryCircular)).previewDisplayName("Circular") 83 | } 84 | } `

I attach my folder structure below and the code of my widget, it appears that the "import Intents" statement it's not importing anything cause the "RecordThought.intentdefinition" it's not being recognizable Screenshot at Jan 10 12-09-45

` import WidgetKit import SwiftUI import Intents

struct Provider: IntentTimelineProvider { func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date(), configuration: ConfigurationIntent()) }

func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) {
    let entry = SimpleEntry(date: Date(), configuration: configuration)
    completion(entry)
}

func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
    var entries: [SimpleEntry] = []

    // Generate a timeline consisting of five entries an hour apart, starting from the current date.
    let currentDate = Date()
    for hourOffset in 0 ..< 5 {
        let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
        let entry = SimpleEntry(date: entryDate, configuration: configuration)
        entries.append(entry)
    }

    let timeline = Timeline(entries: entries, policy: .atEnd)
    completion(timeline)
}

}

struct SimpleEntry: TimelineEntry { let date: Date let configuration: ConfigurationIntent }

struct RecordThoughtEntryView : View { var entry: Provider.Entry

var url: URL {
     guard let url = URL(string:"https://home/open_microphone") else {
         fatalError("Failed to construct url")
     }
     return url
 }
 var body: some View {
        Gauge(value: 0.7) {
            VStack {
                Image(systemName: "mic.fill")
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .frame(width: 30, height: 30)
                    .padding(.top, -20)
                Spacer()
            }.widgetURL(url)
        }
        .gaugeStyle(.accessoryCircular)
    }}

struct RecordThought: Widget { let kind: String = "RecordThought"

var body: some WidgetConfiguration {
    IntentConfiguration(kind: kind, intent: ConfigurationIntent.self, provider: Provider()) { entry in
        RecordThoughtEntryView(entry: entry)
    }
    .configurationDisplayName("Record thought")
    .description("This widget it's a shortcut for recording thought")
    .supportedFamilies([.accessoryCircular])
}

}

struct RecordThought_Previews: PreviewProvider { static var previews: some View { RecordThoughtEntryView(entry: SimpleEntry(date: Date(), configuration: ConfigurationIntent())) .previewContext(WidgetPreviewContext(family: .accessoryCircular)).previewDisplayName("Circular") } }`

gitn00b1337 commented 8 months ago

Hi,

Have you configured

moduleDependencies: [],

in the settings (see readme). If so, please can you provide a minimal reproduction project and I'll reopen the issue. Thanks

st4l1nR commented 8 months ago

Yes , i tried specifying in the moduleDependencies the file, but it didn't work so the solution was when i created my widget on xcode i uncheck the "Include Configuration FIle" box

sercanov commented 1 month ago

I guess it's because the plugin only add .swift files to xcode, to make editable widgets we need .intentdefinition files to be added to Xcode too. Adding to module dependencies only copy the file to folder. Maybe a config option describe non-swift extensions to be added would solve a part of this @gitn00b1337

 addFile(file: string) {
    const extension = path.extname(file).substring(1)

    if (file === "Module.swift") {
      return;
    }
    else if (this._files.hasOwnProperty(extension)) {
      Logging.logger.debug(`Adding file ${file}...`)
      Logging.logger.debug(`Extension: ${extension}`)

      this._files[extension].push(file)
    }
  }

I'm also trying make it work and having the same ConfigurationIntent problems as you @st4l1nR did you solve it by any chance?

gitn00b1337 commented 1 month ago

I'll take a look when I can. It would be great if someone can create an example project I can pull + fix.