Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save cute/25aec0ee3f0a7a5b0dba2cb4d1e811b3 to your computer and use it in GitHub Desktop.

Select an option

Save cute/25aec0ee3f0a7a5b0dba2cb4d1e811b3 to your computer and use it in GitHub Desktop.

Revisions

  1. @ABashkirova ABashkirova revised this gist Sep 22, 2024. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions DayView+widgetAccentable.swift
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    Circle()
    .fill(model.isCurrent ? .white : .clear)
    // This is not accentable by default, widgetAccentable() in not necessary
    .fill(model.isCurrent ? .white : .clear)
    // No need for widgetAccentable(false) as it's not accentable by default

    Text("21")
    .font(.system(size: 15))
    .foregroundColor(model.isCurrent ? .black : .white)
    .widgetAccentable(model.isCurrent) // We want to accent only on the current day.
    .widgetAccentable(model.isCurrent) // Accent only the current day
  2. @ABashkirova ABashkirova revised this gist Sep 22, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions CutContentFromView.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    // If you want to get black text on a white background,
    // there is only one way out - to cut it out of the background
    Circle()
    .fill(.white)
    .frame(width: 20, height: 20, alignment: .center)
  3. @ABashkirova ABashkirova revised this gist Sep 22, 2024. 1 changed file with 19 additions and 0 deletions.
    19 changes: 19 additions & 0 deletions EnvironmentValues+isFullColorWidget.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    import SwiftUI

    extension EnvironmentValues {
    @available(iOS, deprecated: 16.0, message: "use `widgetRenderingMode` instead")
    var isFullColorWidget: Bool {
    get {
    if #available(iOS 16.0, *) {
    widgetRenderingMode == .fullColor
    }
    else {
    self[FullColorWidgetKey.self]
    }
    }
    }
    }

    private enum FullColorWidgetKey: EnvironmentKey {
    static let defaultValue = true
    }
  4. @ABashkirova ABashkirova revised this gist Sep 21, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Image+widgetAccentedRenderingMode.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    Image("userAvatar")
    .resizable()
    .resizable()
    .widgetAccentedRenderingMode(.fullColor)
  5. @ABashkirova ABashkirova created this gist Sep 21, 2024.
    35 changes: 35 additions & 0 deletions BackdeployedWidgetAccentedRenderingMode.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    import SwiftUI
    import WidgetKit

    @available(iOS, deprecated: 18.0, message: "use WidgetAccentedRenderingMode instead")
    enum BackdeployedWidgetAccentedRenderingMode {
    case accented
    case accentedDesaturated
    case desaturated
    case fullColor

    @available(iOS 18.0, *)
    func toRenderingMode() -> WidgetAccentedRenderingMode {
    switch self {
    case .accented: .accented
    case .accentedDesaturated: .accentedDesaturated
    case .desaturated: .desaturated
    case .fullColor: .fullColor
    }
    }
    }

    extension Image {
    @available(iOS, deprecated: 18.0, message: "use widgetAccentedRenderingMode instead")
    @ViewBuilder
    func backdeployedWidgetAccentedRenderingMode(
    _ mode: BackdeployedWidgetAccentedRenderingMode
    ) -> some View {
    if #available(iOS 18.0, *) {
    self.widgetAccentedRenderingMode(mode.toRenderingMode())
    }
    else {
    self
    }
    }
    }
    16 changes: 16 additions & 0 deletions CutContentFromView.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    Circle()
    .fill(.white)
    .frame(width: 20, height: 20, alignment: .center)
    .mask(
    ZStack {
    Circle()
    .fill(Color.white)

    Text(model.formattedDayNumber)
    .font(.system(size: 9, weight: .bold))
    .foregroundColor(.black)

    }
    .compositingGroup()
    .luminanceToAlpha()
    )
    8 changes: 8 additions & 0 deletions DayView+widgetAccentable.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    Circle()
    .fill(model.isCurrent ? .white : .clear)
    // This is not accentable by default, widgetAccentable() in not necessary

    Text("21")
    .font(.system(size: 15))
    .foregroundColor(model.isCurrent ? .black : .white)
    .widgetAccentable(model.isCurrent) // We want to accent only on the current day.
    3 changes: 3 additions & 0 deletions Image+widgetAccentedRenderingMode.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    Image("userAvatar")
    .resizable()
    .widgetAccentedRenderingMode(.fullColor)
    11 changes: 11 additions & 0 deletions PeridoDayView+widgetRenderingMode.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    struct PeridoDayView: View {
    @Environment(\.widgetRenderingMode)
    private var widgetRenderingMode

    var body: some View {
    DayRangeView()
    .foregroundStyle(
    widgetRenderingMode == .fullColor ? .periodColor : .white60Color
    )
    }
    }
    17 changes: 17 additions & 0 deletions View+backdeployedWidgetAccentable.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    import SwiftUI

    extension View {
    @available(iOS, deprecated: 16.0, message: "use widgetAccentable(_:)` instead")
    @ViewBuilder
    func backdeployedWidgetAccentable(
    _ accentable: Bool = true
    ) -> some View {
    if #available(iOS 16.0, *) {
    self
    .widgetAccentable(accentable)
    }
    else {
    self
    }
    }
    }