2024-08-11 00:53:57 +02:00
|
|
|
// Made by Lumaa
|
2024-08-10 18:26:58 +02:00
|
|
|
|
|
|
|
import SwiftUI
|
2024-08-11 00:53:57 +02:00
|
|
|
import WidgetKit
|
2024-08-10 18:26:58 +02:00
|
|
|
|
2024-08-11 00:53:57 +02:00
|
|
|
struct CreatePostWidget: Widget {
|
|
|
|
let kind: String = "CreatePostWidget"
|
|
|
|
|
|
|
|
var body: some WidgetConfiguration {
|
|
|
|
StaticConfiguration(
|
|
|
|
kind: kind,
|
|
|
|
provider: Provider()
|
|
|
|
) { entry in
|
|
|
|
CreatePostWidget.WidgetView()
|
|
|
|
}
|
|
|
|
.configurationDisplayName("widget.open.composer")
|
|
|
|
.description("widget.open.composer")
|
|
|
|
.supportedFamilies([.systemSmall])
|
2024-08-15 04:30:05 +02:00
|
|
|
.disfavoredLocations(
|
|
|
|
[.standBy, .iPhoneWidgetsOnMac],
|
|
|
|
for: [.systemSmall]
|
|
|
|
)
|
2024-08-11 00:53:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct WidgetView: View {
|
|
|
|
@Environment(\.widgetFamily) private var family: WidgetFamily
|
|
|
|
@Environment(\.colorScheme) private var colorScheme: ColorScheme
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
ZStack {
|
|
|
|
if family == .systemSmall {
|
2024-11-11 15:28:47 +01:00
|
|
|
Button(intent: OpenComposerIntent()) {
|
|
|
|
Text("status.posting.placeholder")
|
|
|
|
.foregroundStyle(Color.gray)
|
|
|
|
.font(.callout)
|
|
|
|
.frame(width: 110, height: 110, alignment: .topLeading)
|
|
|
|
.padding(9.0)
|
|
|
|
.background(Color.gray.opacity(0.3))
|
|
|
|
.clipShape(RoundedRectangle(cornerRadius: 20))
|
2024-08-11 00:53:57 +02:00
|
|
|
}
|
2024-11-11 15:28:47 +01:00
|
|
|
.buttonStyle(.plain)
|
2024-08-11 00:53:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.containerBackground(Color.appBackground, for: .widget)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Provider: TimelineProvider {
|
|
|
|
func getSnapshot(
|
|
|
|
in context: Context,
|
|
|
|
completion: @escaping @Sendable (CreatePostWidget.Entry) -> Void
|
|
|
|
) {
|
|
|
|
completion(.init(date: .now))
|
|
|
|
}
|
|
|
|
|
|
|
|
func getTimeline(
|
|
|
|
in context: Context,
|
|
|
|
completion: @escaping (Timeline<CreatePostWidget.Entry>) -> Void
|
|
|
|
) {
|
|
|
|
var entries: [CreatePostWidget.Entry] = []
|
|
|
|
|
|
|
|
// Generate a timeline consisting of two entries an hour apart, starting from the current date.
|
|
|
|
let currentDate = Date()
|
|
|
|
for hourOffset in 0 ..< 2 {
|
|
|
|
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
|
|
|
|
let entry = CreatePostWidget.Entry(date: entryDate)
|
|
|
|
entries.append(entry)
|
|
|
|
}
|
|
|
|
|
|
|
|
completion(Timeline(entries: entries, policy: .atEnd))
|
|
|
|
}
|
|
|
|
|
|
|
|
func placeholder(in context: Context) -> CreatePostWidget.Entry {
|
|
|
|
return .init(date: .now)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Entry: TimelineEntry {
|
|
|
|
let date: Date
|
2024-08-10 18:26:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-11 00:53:57 +02:00
|
|
|
#Preview(as: .systemSmall) {
|
2024-08-10 18:26:58 +02:00
|
|
|
CreatePostWidget()
|
2024-08-11 00:53:57 +02:00
|
|
|
} timeline: {
|
|
|
|
CreatePostWidget.Entry(date: .now)
|
2024-08-10 18:26:58 +02:00
|
|
|
}
|