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
// | |
import SwiftUI | |
import ScreenSaver | |
struct Defaults { | |
/// Use bundleID for the Module name. It is found in the project properties, of target, General Tab. | |
let storage = ScreenSaverDefaults(forModuleWithName: "com.ajc.SSaver")! | |
let refreshRateKey = "refreshRate" | |
var refreshRate: Double { storage.double(forKey: refreshRateKey) } |
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
// Created by Andrew Cowley on 01/12/2021. | |
// | |
import SwiftUI | |
enum Priority: String, Pickable { | |
case none, low, medium, high // any raw type can be used | |
} | |
struct ContentView: View { | |
@State var priority: Priority = .none |
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
// | |
// Easy Focus Example | |
// | |
// The package allows the code below to focus (🙂) on the data | |
// that is changing, and not on underlying id records as is required | |
// when using @FocusState. | |
// Code differences when using this package are highlighted | |
// below with /*👉*/ | |
// | |
// Created by Andrew Cowley on 21/11/2021. |
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
// | |
// ReminderList.swift | |
// | |
// Demonstrates:- | |
// list settings (style, colouring etc ) | |
// autoscrolling | |
// control of focus in List, | |
// adding new values with enter, or double click, | |
// auto deleting nil values, | |
// using Combine for managed delay/UI updates |
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
import SwiftUI | |
struct TaskList: View { | |
@StateObject var vm = TaskListVM() | |
@FocusState private var focusedField: RowID? | |
var body: some View { | |
List() { | |
ForEach($vm.tasks) { $task in | |
TaskRow(task: $task) | |
.focused($focusedField, equals: .row(id: task.id)) |
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
struct Task: Identifiable, Codable { | |
var id = UUID().uuidString | |
var text: String = "" | |
static var examples = [ Task(text: "one"), Task(text: "two")] | |
} | |
struct Tasks: View { | |
enum Field : Hashable { case text } | |
@State private var tasks = Task.examples | |
@FocusState private var focusedField: Field? |
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
class LoginViewModel: ObservableObject { | |
@Published var username = "" | |
@Published var password = "" | |
@Published var focusedField: Field? | |
enum Field: Hashable { | |
case username | |
case password | |
} | |
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
extension View { | |
/// Mirror changes between an @Published variable (typically in your View Model) and an @FocusedState variable in a view | |
func sync<T: Equatable>(_ field1: Binding<T>, _ field2: FocusState<T>.Binding ) -> some View { | |
self | |
.onChange(of: field1.wrappedValue) { field2.wrappedValue = $0 } | |
.onChange(of: field2.wrappedValue) { field1.wrappedValue = $0 } | |
} | |
} |
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
struct Login: View { | |
@State private var username = "" | |
@State private var password = "" | |
enum Field: Hashable { | |
case username | |
case password | |
} | |
@FocusState private var focusedField: Field? | |
var body: some View { |