Forked from ABashkirova/BackdeployedWidgetAccentedRenderingMode.swift
Created
October 15, 2024 08:03
-
-
Save cute/25aec0ee3f0a7a5b0dba2cb4d1e811b3 to your computer and use it in GitHub Desktop.
Revisions
-
ABashkirova revised this gist
Sep 22, 2024 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ Circle() .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) // Accent only the current day -
ABashkirova revised this gist
Sep 22, 2024 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal 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) -
ABashkirova revised this gist
Sep 22, 2024 . 1 changed file with 19 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal 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 } -
ABashkirova revised this gist
Sep 21, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,3 @@ Image("userAvatar") .resizable() .widgetAccentedRenderingMode(.fullColor) -
ABashkirova created this gist
Sep 21, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal 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 } } } This file contains hidden or 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 charactersOriginal 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() ) This file contains hidden or 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 charactersOriginal 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. This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ Image("userAvatar") .resizable() .widgetAccentedRenderingMode(.fullColor) This file contains hidden or 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 charactersOriginal 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 ) } } This file contains hidden or 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 charactersOriginal 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 } } }