I have a piece of code that looks like this in my ContentView
and I'd like to not repeat the ScrollView
's modifiers unnecessarily.
if variable == false {
ScrollView {
// Code here
}
.navigationBarTitleDisplayMode(.inline)
.toolbar() {
// Code here
}
} else {
ScrollView(.horizontal, showsIndicators: false) {
// Code here
}
.navigationBarTitleDisplayMode(.inline)
.toolbar() {
// Code here
}
So I tried to do this instead:
ScrollView(variable ? .horizontal, showsIndicators: false : nil) {
// Code here
}
.navigationBarTitleDisplayMode(.inline)
.toolbar() {
// Code here
}
But it doesn't work. How do you guys do this kind of thing?
Maybe, I should create my own custom scrollview, but how ?
struct ScrollViewCustom /* What to write here? */ View {
@AppStorage("variable") private var variable = false
@ViewBuilder /* What to write here? */
var body: some View {
if variable == false {
ScrollView()
} else {
ScrollView(.horizontal, showsIndicators: false)
}
}
}
Thanks in advance!