-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fixes #232] Implement iOS 16 lock screen widget
- Loading branch information
Showing
8 changed files
with
179 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// LockScreenWidget.swift | ||
// ClendarWidgetExtension | ||
// | ||
// Created by Vinh Nguyen on 01/09/2022. | ||
// Copyright © 2022 Vinh Nguyen. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import WidgetKit | ||
|
||
struct LockScreenWidgetCounter: Widget { | ||
var body: some WidgetConfiguration { | ||
StaticConfiguration( | ||
kind: Constants.WidgetKind.lockScreenWidgetCounter.rawValue, | ||
provider: DateInfoWidgetTimelineProvider() | ||
) { entry in buildContentView(entry) } | ||
.supportedFamilies(widgetFamilies) | ||
} | ||
|
||
private func buildContentView(_ entry: WidgetEntry) -> some View { | ||
if #available(iOSApplicationExtension 16.0, *) { | ||
return LockScreenWidgetView(entry: entry, style: .counter) | ||
.widgetAccentable() | ||
} else { | ||
return EmptyView() | ||
} | ||
} | ||
} | ||
|
||
struct LockScreenWidgetNextEvent: Widget { | ||
var body: some WidgetConfiguration { | ||
StaticConfiguration( | ||
kind: Constants.WidgetKind.lockScreenWidgetNextEvent.rawValue, | ||
provider: DateInfoWidgetTimelineProvider() | ||
) { entry in buildContentView(entry) } | ||
.supportedFamilies(widgetFamilies) | ||
} | ||
|
||
private func buildContentView(_ entry: WidgetEntry) -> some View { | ||
if #available(iOSApplicationExtension 16.0, *) { | ||
return LockScreenWidgetView(entry: entry, style: .nextEvent) | ||
.widgetAccentable() | ||
} else { | ||
return EmptyView() | ||
} | ||
} | ||
} | ||
|
||
private var widgetFamilies: [WidgetFamily] { | ||
if #available(iOSApplicationExtension 16.0, *) { | ||
return [ | ||
.accessoryInline, | ||
.accessoryCircular, | ||
.accessoryRectangular | ||
] | ||
} else { | ||
return [ | ||
.systemSmall, | ||
.systemMedium, | ||
.systemLarge, | ||
.systemExtraLarge | ||
] | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
ClendarWidget/Widget/Lock Screen/SmallCircularWidgetView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// File.swift | ||
// ClendarWidgetExtension | ||
// | ||
// Created by Vinh Nguyen on 01/09/2022. | ||
// Copyright © 2022 Vinh Nguyen. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import WidgetKit | ||
|
||
enum LockScreenWidgetViewStyle { | ||
case nextEvent | ||
case counter | ||
} | ||
|
||
struct LockScreenWidgetView: View { | ||
@Environment(\.widgetFamily) private var widgetFamily | ||
|
||
let entry: WidgetEntry | ||
let style: LockScreenWidgetViewStyle | ||
|
||
var body: some View { | ||
if #available(iOSApplicationExtension 16.0, *) { | ||
ViewThatFits { | ||
switch widgetFamily { | ||
case .accessoryCircular: | ||
ViewThatFits(in: .vertical) { | ||
VStack(alignment: .center) { | ||
Text(DateFormatter.asString(entry.date, format: "MMM").localizedUppercase) | ||
.font(.boldFontWithSize(15)) | ||
Text(entry.date.toFullDayString()) | ||
.font(.regularFontWithSize(13)) | ||
} | ||
} | ||
.widgetAccentable() | ||
|
||
case .accessoryRectangular: | ||
ViewThatFits(in: .vertical) { | ||
VStack(alignment: .leading, spacing: 5) { | ||
Text(entry.date.toFullDateString().localizedUppercase) | ||
.font(.boldFontWithSize(12)) | ||
|
||
Text(entry.events.isEmpty ? "🎉" : message) | ||
.lineLimit(2) | ||
.font(.mediumFontWithSize(12)) | ||
} | ||
} | ||
default: | ||
Text(entry.date.toMonthString().localizedUppercase) | ||
.font(.boldFontWithSize(15)) | ||
Text(entry.date.toFullDayString()) | ||
.font(.regularFontWithSize(13)) | ||
|
||
} | ||
|
||
} | ||
.widgetAccentable() | ||
} else { | ||
Text(entry.date.toFullDayString()) | ||
.font(.boldFontWithSize(15)) | ||
} | ||
} | ||
|
||
private var message: String { | ||
switch style { | ||
case .nextEvent: return entry.events.first?.event?.title ?? "" | ||
case .counter: return "\(entry.events.count) \(NSLocalizedString("Events", comment: ""))" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
Pods/Pods.xcodeproj/xcuserdata/Vinh.xcuserdatad/xcschemes/xcschememanagement.plist
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.