Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WidgetKit development experiment in LINE

WidgetKit development experiment in LINE

All About WidgetKit
WidgetKit development experiment in LINE by Lin, Kuan-Wei
Event: https://cocoaheads-taipei.kktix.cc/events/20211209

LINE Developers Taiwan

December 10, 2021
Tweet

More Decks by LINE Developers Taiwan

Other Decks in Programming

Transcript

  1. LINE Developer Driven Culture • News Widget • Developer’s proposal

    along with other features • Cross team communication • Documentation • Agility
  2. Documentation Feature document for development Feature proposal from developers Study

    / Learning / experience for developers Low High Complexity
  3. Apple Sample Code import WidgetKit struct SimpleEntry: TimelineEntry { let

    date: Date } struct Provider: TimelineProvider { func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date()) } func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) { let entry = SimpleEntry(date: Date()) completion(entry) } func getTimeline(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) entries.append(entry) } let timeline = Timeline(entries: entries, policy: .atEnd) completion(timeline) } }
  4. Apple Sample Code import WidgetKit struct SimpleEntry: TimelineEntry { let

    date: Date } struct Provider: TimelineProvider { func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date()) } func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) { let entry = SimpleEntry(date: Date()) completion(entry) } func getTimeline(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) entries.append(entry) } let timeline = Timeline(entries: entries, policy: .atEnd) completion(timeline) } }
  5. Apple Sample Code import WidgetKit struct SimpleEntry: TimelineEntry { let

    date: Date } struct Provider: TimelineProvider { func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date()) } func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) { let entry = SimpleEntry(date: Date()) completion(entry) } func getTimeline(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) entries.append(entry) } let timeline = Timeline(entries: entries, policy: .atEnd) completion(timeline) } }
  6. Apple Sample Code import WidgetKit struct SimpleEntry: TimelineEntry { let

    date: Date } struct Provider: TimelineProvider { func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date()) } func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) { let entry = SimpleEntry(date: Date()) completion(entry) } func getTimeline(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) entries.append(entry) } let timeline = Timeline(entries: entries, policy: .atEnd) completion(timeline) } }
  7. @main struct MyWidget: Widget { let widgetKind: String = "MyWidget"

    var body: some WidgetConfiguration { StaticConfiguration(kind: widgetKind, provider: Provider()) { entry in WidgetEntryView(entry: entry) } .configurationDisplayName("My Widget") .description("This is an example widget.") } } Apple Sample Code
  8. @main struct MyWidget: Widget { let widgetKind: String = "MyWidget"

    var body: some WidgetConfiguration { StaticConfiguration(kind: widgetKind, provider: Provider()) { entry in WidgetEntryView(entry: entry) } .configurationDisplayName("My Widget") .description("This is an example widget.") } } Apple Sample Code
  9. Debugging • Open Developer Mode for WidgetKit, Shortcuts, and Display

    Donations • It still take times for developer to verify the donation result for Widget Suggestion