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 characters
import SwiftUI | |
struct AnimatingMeshView: View { | |
let referenceDate: Date | |
var body: some View { | |
TimelineView(.animation) { context in | |
let t = context.date.timeIntervalSince(referenceDate) | |
MeshGradient(width: 5, height: 4, points: [ |
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 characters
import SwiftUI | |
struct KeyframeValues { | |
var scale = 1.0 | |
var horizontalStretch = 1.0 | |
var verticalStretch = 1.0 | |
var translation = 0.0 | |
var rotation = Angle.zero | |
} |
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 characters
import SwiftUI | |
@Observable class ViewModel { | |
var isOn: Bool | |
var text: String | |
init(isOn: Bool = false, text: String = "default") { | |
self.isOn = isOn | |
self.text = text | |
} |
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 characters
import SwiftUI | |
/* | |
Put these in a file that is compiled for iOS only. | |
Note that these are just a few examples of things that worked well in my project. | |
They may or may not be useful to you, but they give an idea of how typealias + extensions | |
could be used to keep your code tidy. | |
*/ |
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 characters
import SwiftUI | |
/// Provides a text label appropriate for the current platform. | |
/// | |
/// Specifically, this provides a `Label` with the specified system image on iOS and `Text` without an image on macOS. | |
struct MultiplatformLabel: View { | |
// MARK:- Properties | |
/// A title generated from a localized string. |
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 characters
import SwiftUI | |
import WidgetKit | |
@available(iOS 16.0, macOS 13.0, *) | |
public enum MultiplatformWidgetFamily: CaseIterable { | |
/// A small widget. | |
/// | |
/// The small system widget can appear on the Home Screen or in the Today View in iOS and iPadOS, or in the Notification Center on macOS. | |
case systemSmall |
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 characters
import SwiftUI | |
import WidgetKit | |
@available(iOS 14.0, macOS 11.0, *) | |
public extension WidgetFamily { | |
/// Returns the value for the current widget family. | |
/// | |
/// If no value is provided for the current widget family, the method will return the `defaultValue`. | |
/// |
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 characters
import Foundation | |
/* | |
Put these global functions in a file that is compiled for all platforms. | |
*/ | |
/// Returns the value for the current device from the values that are provided. | |
/// | |
/// - Parameters: | |
/// - phoneValue: The value to use for iPhone. |
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 characters
import Foundation | |
/// Returns the value for the current platform from the values that are provided. | |
/// | |
/// - Parameters: | |
/// - iOSValue: The value to use for the iOS platform. | |
/// - macOSValue: The value to use for the macOS platform. | |
func valueForPlatform<Value>(iOS iOSValue: @autoclosure () -> Value, macOS macOSValue: @autoclosure () -> Value) -> Value { | |
#if os(iOS) | |
iOSValue() |
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 characters
import SwiftUI | |
enum ColorAttribute: CodableAttributedStringKey, MarkdownDecodableAttributedStringKey { | |
enum Value: String, Codable, Hashable { | |
case red | |
case orange | |
case yellow | |
case green | |
case mint | |
case teal |
NewerOlder