ios – Need assistance setting accessibility focus to newly loaded merchandise in SwiftUI ForEach array

0
71


I am new to swift, swiftUI, and to apple accessibility.

I’ve a location record with a prefix on it that masses 10 gadgets at a time. When a person selects the load extra button accessibilityFocused is about to the following task particularly the ability quantity on the high of every task. Once I run voice over focus begins on the final task as a substitute of the brand new task that was loaded after the person chosen the load extra button.

@StateObject personal var viewModel = AssignmentViewModel()

Record{
ForEach(
                            Array(viewModel.locationList.prefix(viewModel.visibleItems))
                        ) { (location) in
                            letindexPath = viewModel.locationList.firstIndex{$0.self== location.self} ?? -1
                          
                            
                            HStack{
                                Textual content("Location Quantity: ")
                                    .font(
                                        .title2
                                            .weight(.daring)
                                    )
                                    .foregroundColor(Shade.body_Text)
                                    .fontWeight(.daring)
                                
                                Textual content("(location.facilityNumber?? "")")
                                    .fontWeight(.daring)
                                    .padding(.trailing)
                                    .padding(.main)
                                    .background( Shade.storeNum)
                                    .foregroundColor(Shade.body_Text)
                                /*MARK: Pin graphic**/
                                ZStack{
                                    Picture(systemName: "pin.fill")
                                        .foregroundColor(Shade.HHS_Purple)
                                        .rotationEffect(.levels(45))
                                }
                                .accessibilityHidden(true)
                                    //MARK: use geometry reader to detect panorama and portrait modes for ipad
                                .offset(x: bounds.dimension.width< bounds.dimension.peak? 30: 725)
                                /*Pin graphic**/
                                
                            }
                            .listRowSeparator(.hidden)
                            .accessibility(sortPriority: 5)
                            .body(maxWidth: .infinity, alignment: .middle)
                            .accessibilityElement(kids: .ignore)
                            .accessibilityLabel("Location Quantity: (location.facilityNumber ?? "") ")
                            .accessibilityHeading(AccessibilityHeadingLevel.h2)
                            /*Leaving the main target as is for now. When person masses subsequent task, the main target is on the final task.
                It must be on the following task displaying. There may be not alot of documentation obtainable on methods to set
                concentrate on a foreach loop array. */
                            .accessibilityFocused($focus, equals: .nextAssignment)
                            
                       }// finish foreach 
                        // I additionally tried accessibilityFocused right here. It went to the clean 
                        //areas in between assignments. Virtually the conduct I would like however not 
                        //quiet.
            if viewModel.isFilteredEmpty {
                                EmptyView()
                            }
                            else
                            {
                                buttonLoadMore
                            }
} // finish record

Load extra button:

    var buttonLoadMore: some View {
        HStack{
            if (viewModel.isLastAssignment())
            {
                Textual content("Finish of Assignments")
            }
            else
            {
                Button("Load Extra") {
                    withAnimation {
                        
                        focusIndicator = .loadMore
                        focus = .nextAssignment
                        print("Load Extra button tapped. (String(describing: focus))")
                        viewModel.showMore()
                        if isSearchEnabled() {
                            print("Search assignments enabled. (String(describing: focus))")
                            viewModel.filter(byLocation: searchAssignments)
                        }
                          
                    }
                    
                }
                .buttonStyle(LinkStyle())
                .font(
                    .physique
                        .weight(.daring)
                )
                .body(width: 300, alignment: .middle)
                .contentShape(Capsule())
                .padding()
                .background(
                    Capsule()
                        .strokeBorder(focusIndicator == .loadMore  ? Shade.HHS_Purple : Shade.clear, lineWidth:  focusIndicator == .loadMore  ? 3 : 1)
                        .background( Shade.HHS_Purple.opacity(0.1))
                        .clipped()
                )
                .clipShape(Capsule())
                .foregroundColor(Shade.HHS_Purple)
                .multilineTextAlignment(.main)
                .fixedSize(horizontal: false, vertical: true)
                
            }
        }
        .accessibility(sortPriority: 0)
        .body(maxWidth: .infinity, alignment: .middle)
        .listRowSeparator(.hidden)
        .padding()
        
    }

Desired conduct:

I need assistance setting the main target to the following merchandise loaded from an array. Particularly the facilityNumber.

What I attempted:

I attempted the answer from this put up. and it didn’t work for me. Any ideas are drastically appreciated! Thanks!