Skip to content

Commit

Permalink
feat: init(widgets)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandram-Dutta committed Jun 18, 2024
1 parent 8952b53 commit c3f25ae
Show file tree
Hide file tree
Showing 8 changed files with 320 additions and 5 deletions.
177 changes: 172 additions & 5 deletions VITTY/VITTY.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions VITTY/vittyios-widgets/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
11 changes: 11 additions & 0 deletions VITTY/vittyios-widgets/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widgetkit-extension</string>
</dict>
</dict>
</plist>
80 changes: 80 additions & 0 deletions VITTY/vittyios-widgets/vittyios_widgets.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// vittyios_widgets.swift
// vittyios-widgets
//
// Created by Chandram Dutta on 18/06/24.
//

import WidgetKit
import SwiftUI

struct Provider: TimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(date: Date(), emoji: "😀")
}

func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
let entry = SimpleEntry(date: Date(), emoji: "😀")
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, emoji: "😀")
entries.append(entry)
}

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

struct SimpleEntry: TimelineEntry {
let date: Date
let emoji: String
}

struct vittyios_widgetsEntryView : View {
var entry: Provider.Entry

var body: some View {
VStack {
Text("Time:")
Text(entry.date, style: .time)

Text("Emoji:")
Text(entry.emoji)
}
}
}

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

var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
if #available(iOS 17.0, *) {
vittyios_widgetsEntryView(entry: entry)
.containerBackground(.fill.tertiary, for: .widget)
} else {
vittyios_widgetsEntryView(entry: entry)
.padding()
.background()
}
}
.configurationDisplayName("My Widget")
.description("This is an example widget.")
}
}

#Preview(as: .systemSmall) {
vittyios_widgets()
} timeline: {
SimpleEntry(date: .now, emoji: "😀")
SimpleEntry(date: .now, emoji: "🤩")
}
16 changes: 16 additions & 0 deletions VITTY/vittyios-widgets/vittyios_widgetsBundle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// vittyios_widgetsBundle.swift
// vittyios-widgets
//
// Created by Chandram Dutta on 18/06/24.
//

import WidgetKit
import SwiftUI

@main
struct vittyios_widgetsBundle: WidgetBundle {
var body: some Widget {
vittyios_widgets()
}
}

0 comments on commit c3f25ae

Please sign in to comment.