hello OOPer
here is what I tried so far to try to understand how it work
_______________________________________________________
Documentation
Code Block init<S>(S, content: () -> Content) |
Creates a disclosure group, using a provided string to create a text view for the label.
Available when Label is Text and Content conforms to View._______________________________________________________
and in the Definition :
Code Block public struct DisclosureGroup<Label, Content> : View where Label : View, Content : View { |
|
/// Creates a disclosure group with the given label and content views.
/// - Parameters:
/// - content: The content shown when the disclosure group expands.
/// - label: A view that describes the content of the disclosure group.
Code Block public init(@ViewBuilder content: @escaping () -> Content, @ViewBuilder label: () -> Label) |
/// Creates a disclosure group with the given label and content views, and
/// a binding to the expansion state (expanded or collapsed).
/// - Parameters:
/// - isExpanded: A binding to a Boolean value that determines the group's
/// expansion state (expanded or collapsed).
/// - content: The content shown when the disclosure group expands.
/// - label: A view that describes the content of the disclosure group.
Code Block public init(isExpanded: Binding<Bool>, @ViewBuilder content: @escaping () -> Content, @ViewBuilder label: () -> Label) |
/// The content and behavior of the view.
Code Block public var body: some View { get } |
/// The type of view representing the body of this view.
/// When you create a custom view, Swift infers this type from your
/// implementation of the required
body property.
Code Block public typealias Body = some View |
} |
_______________________________________________________
from this
struct DisclosureGroup<Label, Content> : View where Label : View, Content : View
I expect to call disclosure with 2 view. but it does not seems to work.
I decide to do some test with the first parameter as a string, because I knew it work and try to give the content for the 2 parameter
Test 2 - I tried this and it work
Code Block struct ContentView2: View { |
var body: some View { |
DisclosureGroup("Lightning") { |
Text("Fast") |
} |
} |
} |
Test 3: I tried to enter the Text view into the disclosure calling , did not work
but the content should be () -> Content and Text is taking an argument ...
Code Block struct ContentView3: View { |
var body: some View { |
DisclosureGroup("Lightning", content: Text("Fast") ) |
} |
} |
Test 4 with the last argument inside - calling a var of type some View - did not work
Code Block struct ContentView4: View { |
var body: some View { |
DisclosureGroup ("Lightning", content: ContentViewSmall1) |
} |
} |
|
struct ContentViewSmall1: View { |
var body: some View { |
Text("ContentViewSmall 1") |
} |
} |
Test 5 with the last argument inside - calling a func that return some View - Worked
Code Block struct ContentView5: View { |
var body: some View { |
DisclosureGroup ("Lightning", content: ContentViewSmall2) |
} |
} |
|
func ContentViewSmall2() -> some View { |
return Text("ContentViewSmall 2 ") |
} |
I know I am doing something wrong, and mostly I have an error in my thinking.
if you can help me, it would be great , thank you