Created
July 12, 2022 20:57
-
-
Save heckj/72f713faf28014e560449f82b7ab357d to your computer and use it in GitHub Desktop.
SwiftUI contextual rendering example
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
// Content expanded from Form reference documentation at | |
// https://developer.apple.com/documentation/swiftui/form | |
import SwiftUI | |
enum ProfileImageSize { | |
case large | |
case medium | |
case small | |
} | |
enum NotifyMeAboutType { | |
case anything | |
case mentions | |
case directMessages | |
} | |
struct FormExample: View { | |
@State private var notifyMeAbout: NotifyMeAboutType = .directMessages | |
@State private var playNotificationSounds: Bool = false | |
@State private var sendReadReceipts: Bool = false | |
@State private var profileImageSize: ProfileImageSize = .medium | |
var body: some View { | |
NavigationView { | |
Form { | |
Picker("Notify Me About", selection: $notifyMeAbout) { | |
Text("Direct Messages").tag(NotifyMeAboutType.directMessages) | |
Text("Mentions").tag(NotifyMeAboutType.mentions) | |
Text("Anything").tag(NotifyMeAboutType.anything) | |
} | |
Toggle("Play notification sounds", isOn: $playNotificationSounds) | |
Toggle("Send read receipts", isOn: $sendReadReceipts) | |
Picker("Profile Image Size", selection: $profileImageSize) { | |
Text("Large").tag(ProfileImageSize.large) | |
Text("Medium").tag(ProfileImageSize.medium) | |
Text("Small").tag(ProfileImageSize.small) | |
} | |
Button("Clear Image Cache") {} | |
} | |
} | |
} | |
} | |
struct VStackExample: View { | |
@State private var notifyMeAbout: NotifyMeAboutType = .directMessages | |
@State private var playNotificationSounds: Bool = false | |
@State private var sendReadReceipts: Bool = false | |
@State private var profileImageSize: ProfileImageSize = .medium | |
var body: some View { | |
NavigationView { | |
VStack { | |
Picker("Notify Me About", selection: $notifyMeAbout) { | |
Text("Direct Messages").tag(NotifyMeAboutType.directMessages) | |
Text("Mentions").tag(NotifyMeAboutType.mentions) | |
Text("Anything").tag(NotifyMeAboutType.anything) | |
} | |
Toggle("Play notification sounds", isOn: $playNotificationSounds) | |
Toggle("Send read receipts", isOn: $sendReadReceipts) | |
Picker("Profile Image Size", selection: $profileImageSize) { | |
Text("Large").tag(ProfileImageSize.large) | |
Text("Medium").tag(ProfileImageSize.medium) | |
Text("Small").tag(ProfileImageSize.small) | |
} | |
Button("Clear Image Cache") {} | |
} | |
} | |
} | |
} | |
struct FormExample_Previews: PreviewProvider { | |
static var previews: some View { | |
FormExample() | |
VStackExample() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment