swiftui

How to disable user interaction on SwiftUI view?

瘦欲@ 提交于 2020-12-01 08:30:38
问题 Let's say I have a SwiftUI view hierarchy that looks like this: ZStack() { ScrollView { ... } Text("Hello.") } The Text view blocks touch events from reaching the underlying ScrollView . With UIKit, I'd use something like .isUserInteractionEnabled to control this, but I can't find any way to do this with SwiftUI. I've tried adding a Gesture with a GestureMask of .none on the text view, but that doesn't seem to work. I hope I'm missing something obvious here, because I need to put some status

How can I trigger an action when a swiftUI toggle() is toggled?

落爺英雄遲暮 提交于 2020-12-01 08:17:27
问题 In my SwiftUI view I have to trigger an action when a Toggle() changes its state. The toggle itself only takes a Binding. I therefore tried to trigger the action in the didSet of the @State variable. But the didSet never gets called. Is there any (other) way to trigger an action? Or any way to observe the value change of a @State variable? My code looks like this: struct PWSDetailView : View { @ObjectBinding var station: PWS @State var isDisplayed: Bool = false { didSet { if isDisplayed !=

Best-practices to download data from server in SwiftUI

こ雲淡風輕ζ 提交于 2020-12-01 07:50:18
问题 My question is a conceptual question. I have the following code: struct CategoriesList : View { @State private var categories: [CategoryMetadata] = [] var body: some View { NavigationView { List(self.categories) { category in NavigationButton(destination: PostsList(category: category)) { CategoryRow(category: category) } } }.navigationBarTitle(Text("Categorie")) } } That simply compose my UI using a list of elements (categories) and I have a state associated with my view that auto-update the

Best-practices to download data from server in SwiftUI

送分小仙女□ 提交于 2020-12-01 07:46:48
问题 My question is a conceptual question. I have the following code: struct CategoriesList : View { @State private var categories: [CategoryMetadata] = [] var body: some View { NavigationView { List(self.categories) { category in NavigationButton(destination: PostsList(category: category)) { CategoryRow(category: category) } } }.navigationBarTitle(Text("Categorie")) } } That simply compose my UI using a list of elements (categories) and I have a state associated with my view that auto-update the

Best-practices to download data from server in SwiftUI

那年仲夏 提交于 2020-12-01 07:46:20
问题 My question is a conceptual question. I have the following code: struct CategoriesList : View { @State private var categories: [CategoryMetadata] = [] var body: some View { NavigationView { List(self.categories) { category in NavigationButton(destination: PostsList(category: category)) { CategoryRow(category: category) } } }.navigationBarTitle(Text("Categorie")) } } That simply compose my UI using a list of elements (categories) and I have a state associated with my view that auto-update the

How do I add a toolbar to a macOS app using SwiftUI?

牧云@^-^@ 提交于 2020-12-01 03:47:15
问题 I am trying to add a toolbar inside the title bar to a macOS app using SwiftUI, something similar to what is shown below. I am unable to figure out a way to achieve this using SwiftUI. Currently, I have my toolbar (which just has a text field) inside my view, but I want to move it into the title bar. My current code: struct TestView: View { var body: some View { VStack { TextField("Placeholder", text: .constant("")).padding() Spacer() } } } So, in my case, I need to have the textfield inside

How do I add a toolbar to a macOS app using SwiftUI?

不羁岁月 提交于 2020-12-01 03:46:45
问题 I am trying to add a toolbar inside the title bar to a macOS app using SwiftUI, something similar to what is shown below. I am unable to figure out a way to achieve this using SwiftUI. Currently, I have my toolbar (which just has a text field) inside my view, but I want to move it into the title bar. My current code: struct TestView: View { var body: some View { VStack { TextField("Placeholder", text: .constant("")).padding() Spacer() } } } So, in my case, I need to have the textfield inside

How do I add a toolbar to a macOS app using SwiftUI?

ε祈祈猫儿з 提交于 2020-12-01 03:43:28
问题 I am trying to add a toolbar inside the title bar to a macOS app using SwiftUI, something similar to what is shown below. I am unable to figure out a way to achieve this using SwiftUI. Currently, I have my toolbar (which just has a text field) inside my view, but I want to move it into the title bar. My current code: struct TestView: View { var body: some View { VStack { TextField("Placeholder", text: .constant("")).padding() Spacer() } } } So, in my case, I need to have the textfield inside

How do I add a toolbar to a macOS app using SwiftUI?

只愿长相守 提交于 2020-12-01 03:42:38
问题 I am trying to add a toolbar inside the title bar to a macOS app using SwiftUI, something similar to what is shown below. I am unable to figure out a way to achieve this using SwiftUI. Currently, I have my toolbar (which just has a text field) inside my view, but I want to move it into the title bar. My current code: struct TestView: View { var body: some View { VStack { TextField("Placeholder", text: .constant("")).padding() Spacer() } } } So, in my case, I need to have the textfield inside

SwiftUI: ListItem gestures

Deadly 提交于 2020-11-30 12:40:28
问题 Target is a modification with the following behavior: (but only with 2 buttons - 1 on the left side, 1 on the right) Behavior: short swipe shows the buttons and gives the user the ability to click it. strong long swipe presses button. ability to use 2 finger gesture Minimal reproducible example: import SwiftUI public extension View { func SwiperizeItem(closureL: @escaping () -> (), closureR: @escaping () -> ()) -> some View { self.modifier( SwiperizeItemModifier(closureL: closureL, closureR: