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 | |
/// Animated volume widget like the one on the iPhone Control Center, used like this: | |
/// | |
/// SpeakerVolumeView(volumeSetting: self.volumeSetting) | |
/// .frame(height: 123) | |
/// | |
/// Only need to constrain the height dimension, this widget set its width accordingly | |
/// | |
/// volumeSetting: indicates the volume value 0...1 |
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
/* | |
Note: | |
- To disable all shadows, comment out all .modifier(Emboss()) and .modifier(Deboss()) | |
- Search for .drawingGroup(), uncomment it to see it kills all shadows | |
*/ | |
import SwiftUI |
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
protocol Record: Equatable { | |
func save() | |
} | |
extension Record { | |
func save() { | |
// save to disk | |
print("Record: Disk") | |
} | |
} |
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
// https://twitter.com/jsngr/status/1282116429152751617 | |
import SwiftUI | |
struct AppleRemote: View { | |
var body: some View { | |
VStack(spacing: 24) { | |
Text("Apple TV") | |
.font(.headline) |
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 SimpleAnimation: View { | |
// In Xcode preview? animation doesn't work | |
// animate only if these are set to true | |
// why when set to false, no animation? | |
@State var flag = false | |
@State var anotherFlag = true | |
var body: some View { |
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 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 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 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 |