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
| struct KeyboardAvoidance: View { | |
| @State var text = "" | |
| var body: some View { | |
| VStack { | |
| // Only work if something is added below the list | |
| TextField("Enter", text: $text) | |
| List { | |
| ForEach(1...50, id: \.self) { | |
| Text("More \($0)") |
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 RedactedReasonReplaceIsPlaceholder: View { | |
| @Environment(\.redactionReasons) private var redactionReason | |
| let junk: RedactionReasons = .placeholder | |
| var body: some View { | |
| VStack { | |
| Text("Want this to be shown even when redacted!") | |
| .redacted(reason: .init()) |
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 AnimateForever: View { | |
| @State private var flag = false | |
| var body: some View { | |
| VStack { | |
| Rectangle() | |
| // on rectangle, foregroundColor() animate |
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
| // | |
| // !!! SwiftUI 3: use .foregroundStyle()! Much simplified | |
| // | |
| import SwiftUI | |
| import os | |
| let logger = Logger(subsystem: "net.hddigitalworks.TextColorAnimate", category: "color") |
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
| struct User: Equatable { | |
| var firstName: String | |
| var lastName: String | |
| } | |
| @main | |
| struct MyApp: App { | |
| @State var value = User(firstName: "", lastName: "") | |
| @State var showEdit = false | |
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
| // | |
| // TextLabelViewForSeanHeber.swift | |
| // NewWorld12 | |
| // | |
| // Created by Matthew on 8/1/20. | |
| // | |
| // https://twitter.com/BigZaphod/status/1289674767684046848 | |
| import SwiftUI |
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 | |
| // this demonstrate preference/onPreferenceChange propagate size value | |
| // to set View size do not work. The value is propagated out as can be | |
| // verified by seeing the print() output from closure of .onPreferenceChange() | |
| // but size value is not reflected inside makeBody() | |
| struct CircleProgressViewStyle: ProgressViewStyle, PreferenceKey { | |
| static var defaultValue: CGFloat = 0 | |
| static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { | |
| value = nextValue() |
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 ContentView: View { | |
| let orientationNotification = NotificationCenter.default | |
| .publisher(for: UIDevice.orientationDidChangeNotification) | |
| .map { _ in | |
| UIDevice.current.orientation | |
| } | |
| // .onReceive() mutate this @State var to trigger re-render on orientation change |
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 ContentView: View { | |
| @State var value = -122.90 | |
| let range = -300.0...300 | |
| var body: some View { | |
| VStack { | |
| #warning("`alignment: .firstTextBaseline`, cause the Text inside Label is elided sometime") | |
| HStack(alignment: .firstTextBaseline) { |