home_widget icon indicating copy to clipboard operation
home_widget copied to clipboard

LockScreen widget for IOS 16?

Open desmeit opened this issue 2 years ago • 1 comments

Is there a possibility to create the new lockscreen widgets for IOS 16 with this plugin or is it planned?

Thanks

desmeit avatar Oct 21 '22 10:10 desmeit

its possible, use families

private var supportedFamilies: [WidgetFamily] { if #available(iOSApplicationExtension 16.0, *) { return [ .systemSmall, .systemMedium, .systemLarge, .accessoryCircular, .accessoryRectangular, .accessoryInline ] } else { return [ .systemSmall, .systemMedium, .systemLarge ] } }

var body: some WidgetConfiguration {
    StaticConfiguration(kind: kind, provider: Provider()) { entry in
        HomeWidgetExampleEntryView(entry: entry)
    }
    .configurationDisplayName("title")
    .description("description")
    .supportedFamilies(supportedFamilies)
}

then:

struct HomeWidgetExampleEntryView : View { var entry: Provider.Entry let data = UserDefaults.init(suiteName:widgetGroupId) @Environment(.widgetFamily) private var family

var body: some View {
    switch family {
    case .systemSmall:
        SmallWidgetView(entry: entry)
    case .systemMedium:
        MediumWidgetView(entry: entry)
    case .systemLarge, .systemExtraLarge:
        LargeWidgetView(entry: entry)
    case .accessoryCircular:
        yourWidget()
    case .accessoryInline:
        yourWidget()
    case .accessoryRectangular:
        yourWidget()
    default:
        EmptyView()
    }  
}

}

accesoryCircular and AccesoryRectangular is LockScreen widgets!

EDnny12 avatar Oct 21 '22 13:10 EDnny12

thank you very much. I tried the code but its only working without accesoryCircular and accesoryRectangular. I get an white widget. This behavior affects the normal widgets and the new screenlock widgets.

desmeit avatar Nov 11 '22 14:11 desmeit

I think I found the issue. It seems that the new LockScreen widgets has a limitation that is lower than the normal widgets. I have set too many entries.

desmeit avatar Nov 14 '22 15:11 desmeit