๐Ÿ‘”AdaptiveHStack

SwiftUI โŸฉ Layout โŸฉ Adaptive Layout โŸฉ Size Classes โŸฉ

โฌ†๏ธ ้œ€่ฆ๏ผš ๐Ÿ‘” AdaptiveHStack

struct ContentView: View {
    
    @State private var isCompact = true
    
    let text = """
        For simplicity's sake, we will focus on conditions based on the horizontal space available: the same concepts can also be applied for vertical space.
        """
    
    var body: some View {
        
        Toggle("is compact", isOn: $isCompact)
            .padding()
        
        Spacer()
        
        // ๐Ÿ‘” AdaptiveHStack
        AdaptiveHStack(threshold: isCompact, alignment: .top) {
            // RoundedRectangle
            RoundedRectangle(cornerRadius: 16)
                .fill(Color.pink)
                .frame(maxHeight: 300)
            // VStack
            VStack {
                Text("Title")
                    .bold()
                    .font(.title)
                Text(text)
                    .fixedSize(horizontal: false, vertical: true)
            }
        }
    }
}

Last updated