Post

Replies

Boosts

Views

Activity

Reply to SWIFTUI 2, SWIFTUI 3 - MACOS: Why TextField's onCommit closure is always trigger every time I switch to another tab
I have found the solution by following the deprecated message. Deprecated Use init(_:text:prompt:) instead. Add the onSubmit(of:_:) view modifier for the onCommit behavior, and onFocus(_:) for the onEditingChanged behavior. import SwiftUI struct ContentView: View { @State private var text = "" var body: some View { TabView { TextField("", text: $text) .onSubmit { // new api print("onCommit") } .tabItem { Text("Tab 1") } Text("Tab 2") .tabItem { Text("Tab 2") } Text("Tab 3") .tabItem { Text("Tab 3") } } } } onSubmit doesn't trigger every time I switch to another tab.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’21
Reply to SWIFTUI 2, SWIFTUI 3 - MACOS: Why TextField's onCommit closure is always trigger every time I switch to another tab
I have found the solution by following the deprecated message. Deprecated Use init(_:text:prompt:) instead. Add the onSubmit(of:_:) view modifier for the onCommit behavior, and onFocus(_:) for the onEditingChanged behavior. import SwiftUI struct ContentView: View { @State private var text = "" var body: some View { TabView { TextField("", text: $text) .onSubmit { // new api print("onCommit") } .tabItem { Text("Tab 1") } Text("Tab 2") .tabItem { Text("Tab 2") } Text("Tab 3") .tabItem { Text("Tab 3") } } } } onSubmit doesn't trigger every time I switch to another tab.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to What's the purpose of Vstack when we actually don't need it ??
Can you show preview images of ContentView with and without VStack?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Feb ’24
Reply to Debugging to find out why View is bring re-drawn
struct ContentView: View { @State var text = "[This is some long text that will be cut off at the end of the text editor]" var body: some View { Text(text).opacity(0.0).padding() .overlay { TextEditor(text: $text) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’24
Reply to TextEditor with a fixedSize and scroll disabled is completely broken
struct ContentView: View { @State var text = "[This is some long text that will be cut off at the end of the text editor]" var body: some View { Text(text).opacity(0.0).padding() .overlay { TextEditor(text: $text) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’24