Choosing to display one or other ScrollView blocks the second one

I have a particular issue where, when using two ScrollViews and trying to display one or the other conditionnally, the second one never works.

To make it simple : I need to display a list, but if a certain action is made, I need to display a second different list instead (not filtering, a whole other data type and cells). When the condition to display the second ScrollView is active, I see the second ScrollView. But :

I can’t scroll at all unless I go back to the first ScrollView
In the same manner, buttons inside the second ScrollView doesn’t work
It seems like the user interaction is disabled on the second scroll view. I tried to inverse the condition, to see if there was a problem with the second layout, but the issue remains: it’s always the scrollview that comes second that doesn’t work.

Here’s the current code for the view:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>struct SearchView: View {
@StateObject var viewModel: SearchViewModel
var body: some View {
ZStack(alignment: .top) {
ScrollView {
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 2), spacing: 16) {
ForEach(viewModel.categories, id: .id) { category in
Button {
viewModel.categoryTapped(category: category)
} label: {
CategoryCellView(category: category)
}
}
}
.padding(.horizontal, 16)
}
.opacity(viewModel.items.isEmpty ? 1 : 0)
ScrollView {
LazyVStack {
ForEach(viewModel.items) { item in
Button {
viewModel.openItem(item: item)
} label: {
cell(for: item)
}
}
}
.padding(.horizontal, 16)
}
.opacity(viewModel.items.isEmpty ? 0 : 1)
}
.onAppear {
viewModel.load()
}
}
}
</code>
<code>struct SearchView: View { @StateObject var viewModel: SearchViewModel var body: some View { ZStack(alignment: .top) { ScrollView { LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 2), spacing: 16) { ForEach(viewModel.categories, id: .id) { category in Button { viewModel.categoryTapped(category: category) } label: { CategoryCellView(category: category) } } } .padding(.horizontal, 16) } .opacity(viewModel.items.isEmpty ? 1 : 0) ScrollView { LazyVStack { ForEach(viewModel.items) { item in Button { viewModel.openItem(item: item) } label: { cell(for: item) } } } .padding(.horizontal, 16) } .opacity(viewModel.items.isEmpty ? 0 : 1) } .onAppear { viewModel.load() } } } </code>
struct SearchView: View {

    @StateObject var viewModel: SearchViewModel

    var body: some View {
        ZStack(alignment: .top) {
            ScrollView {
                LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 2), spacing: 16) {
                    ForEach(viewModel.categories, id: .id) { category in
                        Button {
                            viewModel.categoryTapped(category: category)
                        } label: {
                            CategoryCellView(category: category)
                        }
                    }
                }
                .padding(.horizontal, 16)
            }
            .opacity(viewModel.items.isEmpty ? 1 : 0)

            ScrollView {
                LazyVStack {
                    ForEach(viewModel.items) { item in
                        Button {
                            viewModel.openItem(item: item)
                        } label: {
                            cell(for: item)
                        }
                    }
                }
                .padding(.horizontal, 16)
            }
            .opacity(viewModel.items.isEmpty ? 0 : 1)
        }
        .onAppear {
            viewModel.load()
        }
    }
}

In this version, I’m trying to display both ScrollView but hide one with opacity, but it’s because I tried so many things already. Same result with an if/else condition determining which scroll views is displayed, same result by setting the if/else condition inside an unique ScrollView, same result by setting the if/else inside the LazyVGrid.

If someone has an idea, it will be glady appreciated! thanks

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật