Post

Replies

Boosts

Views

Activity

Reply to State change doesn't affect TextField lineLimit UI in Xcode 14 Beta
I have not tested this but give it a try SB import SwiftUI struct TextFieldDynamicHeight: ViewModifier {     var fullSize: Binding<Bool> = .constant(false)     var upperRange: ClosedRange<Int>     var lowerRange: ClosedRange<Int>     var upperBound: Int     var lowerBound: Int     func body(content: Content) -> some View {         if #available(iOS 16.0, *) {             content                 .lineLimit(fullSize.wrappedValue ? upperRange : lowerRange)         } else {             content                 .lineLimit(fullSize.wrappedValue ? upperBound : lowerBound)         }     } } extension View {     @available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *)     func lineLimit(_ fullSize: Binding<Bool>, upperRange: ClosedRange<Int>, lowerRange: ClosedRange<Int>) -> some View {         modifier(TextFieldDynamicHeight(fullSize: fullSize, upperRange: upperRange, lowerRange: lowerRange,                                         upperBound: 0, lowerBound: 0))     }     @available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)     func lineLimit(_ fullSize: Binding<Bool>, upperBound: Int, lowerBound: Int) -> some View {         modifier(TextFieldDynamicHeight(fullSize: fullSize, upperRange: 0...0, lowerRange: 0...0,                                         upperBound: upperBound, lowerBound: lowerBound))     } } struct ContentView: View {     @State private var description: String = ""     @State private var fullSize: Bool = false     @State private var fullHeight: Bool = false     var body: some View {         VStack {             VStack {                 Image(systemName: "globe")                     .imageScale(.large)                     .foregroundColor(.accentColor)                 Text("Hello world!")             }             if #available(iOS 16.0, *) {                 TextField("Type a textmail", text: $description, axis: .vertical)                     .lineLimit($fullSize, upperRange: 2...6, lowerRange: 2...3)                     .foregroundColor(.white)                     .background(Color.blue)                     .frame(height: fullHeight ? 300 : 100)                     .padding(0)             } else {                 TextField("Type a textmail", text: $description)                     .lineLimit($fullSize, upperBound:6, lowerBound: 3)                     .foregroundColor(.white)                     .background(Color.blue)                     .frame(height: fullHeight ? 300 : 100)                     .padding(0)             }             Button("Full size") {                 fullSize.toggle()                 print("fullSize: \(fullSize)")             }             .padding(5)             Button("Full height") {                 fullHeight.toggle()                 print("fullHeight: \(fullHeight)")             }             .padding(5)         }     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’22
Reply to Dynamic list sections with observed data with SwiftUI
I ran your code with Xcode 13.4.1 & iOS 15.5 and it works as expected and not as described: one thing I will do is sort the data at source         self.objectList = [             Testclass(name: "A1"),             Testclass(name: "B1"),             Testclass(name: "Z2"),             Testclass(name: "C1"),             Testclass(name: "D1"),             Testclass(name: "D2"),             Testclass(name: "A2"),             Testclass(name: "Z1")         ].sorted(by: {$0.name < $1.name})
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’22