Last active
October 3, 2020 07:38
-
-
Save stleamist/2e8a3399c039b18c0a11821aeb3a6d85 to your computer and use it in GitHub Desktop.
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 | |
extension View { | |
@ViewBuilder | |
func modify<Modified: View>(@ModifiedViewBuilder modificationBlock: (Self) -> Modified) -> some View { | |
let modified = modificationBlock(self) | |
if modified is EmptyView { | |
self | |
} else { | |
modified | |
} | |
} | |
} | |
@_functionBuilder | |
struct ModifiedViewBuilder { | |
static func buildBlock() -> EmptyView { | |
EmptyView() | |
} | |
static func buildBlock<Content: View>(_ content: Content) -> Content { | |
content | |
} | |
} |
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 ContentView: View { | |
@State private var text = "" | |
var body: some View { | |
TextField("", text: $text) | |
.modify { | |
#if os(iOS) | |
$0 | |
.autocapitalization(.none) | |
#endif | |
} | |
.foregroundColor(.blue) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment