Questions tagged [viewbuilder]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
9votes
3answers
2kviews

Is there any way to create/extract an array of Views using @ViewBuilder in SwiftUI

I'm trying to create a simple struct that accepts an array of Views and returns an ordinary VStack containing those Views except they all are stacked diagonally. Code: struct LeaningTower<Content: ...
user avatar
9votes
2answers
1kviews

How to loop over viewbuilder content subviews in SwiftUI

So I’m trying to create a view that takes viewBuilder content, loops over the views of the content and add dividers between each view and the other struct BoxWithDividerView<Content: View>: View ...
user avatar
  • 194
3votes
1answer
4kviews

SwiftUI custom View's ViewBuilder doesn't re-render/update on subclassed ObservedObject update

This one I've been researching for a few days, scouring the Swift & SwiftUI docs, SO, forums, etc. and can't seem to find an answer. Here is the problem; I have a SwiftUI custom View that does ...
user avatar
  • 695
3votes
3answers
373views

Individually modifying child views passed to a container using @ViewBuilder in SwiftUI

In SwiftUI you are able to pass multiple views as one parameter to another view, thanks to @ViewBuilder. Each child view is treated individually, and so after being passed, can be contained in a ...
user avatar
2votes
1answer
234views

SwiftUI & iOS 13.3 TupleView initializer stop working. what happens to it?

I have such inits with ViewBuilders with TupleView // MARK: TupleView support public init<A: View, B: View>(@ViewBuilder content: () -> TupleView<(A, B)>) { let views = ...
user avatar
1vote
2answers
57views

How to pass in content for TabView through a function

I am trying to build a reusable onboarding pager overlay. So I want to pass in different "slides" into the pager TabView based on a variable IntroType. But since TabView takes content ...
user avatar
  • 1,226
1vote
1answer
33views

Using Variables in Viewbuilder (Swift)

I'm new to swift and Viewbuilder and I am trying to use variables in the Viewbuilder correctly. The objective of this code is to reveal the answer to a question using an animation. The question is ...
user avatar
  • 59
1vote
1answer
1kviews

Closure containing control flow statement cannot be used with result builder 'CommandsBuilder'

I've made a button style to create circular neumorphic buttons in my app as follows: struct NeumorphicCircleButtonStyle: ButtonStyle { var startPoint: UnitPoint var endPoint: UnitPoint var ...
user avatar
1vote
2answers
490views

How can I apply an overlay to an entire SwiftUI container view's children?

I am trying to understand how to use container views in SwiftUI. I am expecting this - But when I run my app I get - How can I wrap all the child views? I am currently creating the views using the ...
user avatar
  • 730
1vote
1answer
386views

Swiftui How to pass a view that takes a parameter to another view that will set the parameter when calling the view

Here is a simple example, but I cannot figure out how to pass the value of test into the passed in destination view. All the examples on the web have the view "Fully" formed when it gets ...
user avatar
1vote
4answers
1kviews

How to execute non-view code inside a SwiftUI view

I have been struggling with this over and over again, so I think I'm missing something. I need to do math, make a setting, assign a value or any of a host of simple operations in reaction to some ...
user avatar
  • 195
1vote
2answers
941views

What is the correct method for passing data into a ViewBuilder closure in SwiftUI?

I'm playing around with generics in SwiftUI, and ran into a data persistence issue when attempting to leverage a ViewBuilder closure to pass data into a generic View. My goal is to have a shell view ...
user avatar
1vote
3answers
67views

SwiftUI View: two different initializers: cannot convert value of type 'Text' to closure result type 'Content'

The code: import SwiftUI public struct Snackbar<Content>: View where Content: View { private var content: Content // Works OK public init(@ViewBuilder content: () -> Content) { ...
user avatar
1vote
1answer
42views

Passing a String value to a viewbuilder from another view

This is the Base View struct BaseView<Content: View>: View { @State private var ShowSFView : Bool = false let content: Content init(@ViewBuilder content: () -> Content ) {...
user avatar
  • 87
1vote
1answer
2kviews

SwiftUI, Passing a View as params in @Viewbuilder

My curiosity takes me to pass a View type as parameter to @ViewBuilder. Passing a Model/Primitive type as param in @ViewBuilder is perfectly valid. As shown below code. struct TestView<Content: ...
user avatar
  • 1,336

15 30 50 per page