HomeiOS Developmentios - WatchOS Complication Flashing

ios – WatchOS Complication Flashing


I’m making a quite simple WidgetKit complication and sadly it flashes each time the watch face awakens. My Apple Watch is updated with WatchOS 9.4. I skilled this earlier than however appeared to repair the difficulty by uninstalling and reinstalling the watch app. Sadly, that’s not proving profitable anymore. Does anybody have any concepts? Right here is my code. You’ll be able to assume getCount() returns 0 instantly – changing it with this doesn’t cease the flashing.

//
//  DrinkCountComplications.swift
//  DrinkCountComplications
//
//  Created by Bryce Sandlund on 11/6/22.
//

import WidgetKit
import SwiftUI

struct Supplier: TimelineProvider {
    func placeholder(in context: Context) -> SimpleEntry {
        SimpleEntry(date: Date(), depend: getCount())
    }
    
    func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
        let entry = SimpleEntry(date: Date(), depend: getCount())
        completion(entry)
    }
    
    func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
        completion(Timeline(entries: [SimpleEntry(date: Date(), count: getCount())], coverage: TimelineReloadPolicy.by no means))
    }
}

struct SimpleEntry: TimelineEntry {
    let date: Date
    let depend: Int
}

struct DrinkCountComplicationsEntryView : View {
    var entry: SimpleEntry

    var physique: some View {
        let hyperlink = URL(string: "myApp://widgetClick")?
            .appending(queryItems: [URLQueryItem(name: "count", value: String(entry.count))])
        ZStack {
            Textual content("DRINK")
                .offset(x: 0, y: -15)
                .foregroundColor(Colour.orange)
                .font(.system(measurement: 10, weight: .semibold))
            Textual content(String(entry.depend))
                .font(.title)
                .offset(x: 0, y: 0)
            Textual content("COUNT")
                .offset(x: 0, y: 15)
                .foregroundColor(Colour.orange)
                .font(.system(measurement: 10, weight: .semibold))
        }
        .unredacted()
        .widgetURL(hyperlink)
        .body(maxWidth: .infinity, maxHeight: .infinity)
        .background()
    }
}

@important
struct DrinkCountComplications: Widget {
    let type: String = "DrinkCountComplications"

    var physique: some WidgetConfiguration {
        StaticConfiguration(type: type, supplier: Supplier()) { entry in
            DrinkCountComplicationsEntryView(entry: entry)
        }
        .configurationDisplayName("Drink Depend Widget")
        .description("Show drink depend & add a drink")
    }
}

struct DrinkCountComplications_Previews: PreviewProvider {
    static var previews: some View {
        DrinkCountComplicationsEntryView(entry: SimpleEntry(date: Date(), depend: getCount()))
            .previewContext(WidgetPreviewContext(household: .accessoryRectangular))
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments