Post

Replies

Boosts

Views

Activity

Reply to Keep ScrollView position when adding items on the top
But what about adding multiple items at the top of the list? I did that and the result was strange, when I start scrolling it couldn't scroll properly. We are developing something really important and we need that ability but Swiftui has a problem with it! struct SwiftUIView: View { @State var data: [String] = (0 ..< 25).map { String($0) } @State var dataID: String? var body: some View { ScrollView { VStack { Text("Header") LazyVStack { ForEach(data, id: \.self) { item in Color.red .frame(width: 100, height: 100) .overlay { Text("\(item)") .padding() .background() } } } .scrollTargetLayout() } } .scrollPosition(id: $dataID) .safeAreaInset(edge: .bottom) { HStack { Text("\(Text("Scrolled").bold()) \(dataIDText)") Spacer() Button { dataID = data.first } label: { Label("Top", systemImage: "arrow.up") } Button { dataID = data.last } label: { Label("Bottom", systemImage: "arrow.down") } Menu { Button("Batch Prepend") { let newDatas = (data.count ..< data.count + 6).map{"New Data \($0)"} newDatas.forEach { data in self.data.insert(data, at: 0) } // data.insert(contentsOf: newDatas, at: 0) // Does not have any difference. } Button("Prepend") { let next = "New Data 1" data.insert(next, at: 0) } Button("Append") { let next = String(data.count) data.append(next) } Button("Remove First") { data.removeFirst() } Button("Remove Last") { data.removeLast() } } label: { Label("More", systemImage: "ellipsis.circle") } } } } var dataIDText: String { dataID.map(String.init(describing:)) ?? "None" } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’23
Reply to SwiftUI list overlap navigationBar
I fixed the problem just by removing all unnecessary views around the List and just putting the pure view at the root of the view. Also, you need to be cautious about ZStack and so on. My piece of advice is that, commenting all the views and modifiers and then step by step uncomment the views until you can find the root of the problem.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’23
Reply to Keep ScrollView position when adding items on the top
But what about adding multiple items at the top of the list? I did that and the result was strange, when I start scrolling it couldn't scroll properly. We are developing something really important and we need that ability but Swiftui has a problem with it! struct SwiftUIView: View { @State var data: [String] = (0 ..< 25).map { String($0) } @State var dataID: String? var body: some View { ScrollView { VStack { Text("Header") LazyVStack { ForEach(data, id: \.self) { item in Color.red .frame(width: 100, height: 100) .overlay { Text("\(item)") .padding() .background() } } } .scrollTargetLayout() } } .scrollPosition(id: $dataID) .safeAreaInset(edge: .bottom) { HStack { Text("\(Text("Scrolled").bold()) \(dataIDText)") Spacer() Button { dataID = data.first } label: { Label("Top", systemImage: "arrow.up") } Button { dataID = data.last } label: { Label("Bottom", systemImage: "arrow.down") } Menu { Button("Batch Prepend") { let newDatas = (data.count ..< data.count + 6).map{"New Data \($0)"} newDatas.forEach { data in self.data.insert(data, at: 0) } // data.insert(contentsOf: newDatas, at: 0) // Does not have any difference. } Button("Prepend") { let next = "New Data 1" data.insert(next, at: 0) } Button("Append") { let next = String(data.count) data.append(next) } Button("Remove First") { data.removeFirst() } Button("Remove Last") { data.removeLast() } } label: { Label("More", systemImage: "ellipsis.circle") } } } } var dataIDText: String { dataID.map(String.init(describing:)) ?? "None" } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jul ’23
Reply to SwiftUI list overlap navigationBar
I fixed the problem just by removing all unnecessary views around the List and just putting the pure view at the root of the view. Also, you need to be cautious about ZStack and so on. My piece of advice is that, commenting all the views and modifiers and then step by step uncomment the views until you can find the root of the problem.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’23