0

I have a view named MainNavigation that has a floating button over my main content views. The MainNavigation view switches to different views depending on what is selected. When displaying

I have a view that contains multiple scrollviews. I want the final scrollview to navigate to the selected view, obviously without wrapping the view in a NavigationView nothing happens. However when I try and wrap everything into a NavigationView everything shifts into a type of sidebar with a back button.

I have removed a lot of the formatting and irrelevant code to make this shorter, however if the longer code is needed to understand what is happening I can upload:

struct ProductList3: View {
    
    @ObservedObject var selected = SelectedState()
    
    var products: [ProductModel] = productData
    var categories =  Array(Set(productData.flatMap(\.categories)))
            .sortedWithAll()
    var activeApplications : Set<String> {
        Set(products.flatMap { product -> [String] in
            if product.categories.contains(selected.selectedCategory) {
                return product.application
            } else {
                return []
            }
        })
    }

    private var gridItemLayout = [
        GridItem(.flexible()),
        GridItem(.flexible())
    ]
    
    var body: some View {
        NavigationView {
            GeometryReader{ geo in
                HStack {
                    VStack(alignment: .leading){
                        Text("Categories")
                        ScrollView(showsIndicators: false){
                            ForEach(categories, id: \.self) { item in
                                // LISTS CATEGORIES
                            }
                        }
                        .frame(height: geo.size.height * 0.3)
                        
                        Text("Application")
                        ScrollView(showsIndicators: false){
                            ForEach(Array(activeApplications).sortedWithAll(), id: \.self) { item in
                                // LIST APPLICATIONS
                            }
                        }
                    }
                    .frame(width: geo.size.width * 0.3)
                    
                    
                    VStack(alignment: .leading){
                        Text("Products")
                        let matchedItems = products.filter { product in
                            let category = product.categories
                            for item in category {
                                if item == selected.selectedCategory {
                                    let application = product.application
                                    for item in application {
                                        if item == selected.selectedApplication {
                                            return true
                                        }
                                    }
                                }
                            }
                            return false
                        }
                        ScrollView {
                            LazyVGrid(columns: gridItemLayout) {
                                ForEach(matchedItems) { item in
                                    NavigationLink(destination: ProductTabView(product: item, selected: selected)){
                                        applicationListRow(product: item)
                                    }
                                }
                            }
                        }
                    }

                    .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)
                }
            }
        }
    }
} 
spoax
  • 471
  • 9
  • 29

0 Answers0