How to force focus engine to focus first item in HStack when this HStack is about to get focused?

In tvOS Application using SwiftUI

Assume there are list of HStacks, where each HStack has 10 elements (say thumbnails).

Initially focus will be on the 1st HStack 1st element, now if I scroll to tenth element in the same HStack and Swipe downward in siri remote then How to force focus to go to 1st element in next HStack in tvOS?

Any updates on this?

Found a way to achieve it. defaultFocus modifier allows you to say which element should have the default focus. Plus, we track which was the last focused (aka remembersLastFocusedIndexPath from UIKit)

@main
struct FocusApp: App {
    var body: some Scene {
        WindowGroup {
            VStack(spacing: 50) {
                CustomRow()
                CustomRow()
            }
        }
    }
}

struct CustomRow: View {
    let items = [1, 2, 3, 4]

    @FocusState private var currentFocusItem: Int?
    @State private var lastFocusItem: Int?

    var body: some View {
        ScrollView(.horizontal) {
            LazyHStack(spacing: 50) {
                ForEach(items, id: \.self) { item in
                    Button { } label: {
                        Text("Item \(item)")
                            .frame(width: 300, height: 300, alignment: .center)
                            .background(Color.red)
                    }
                    .focused($currentFocusItem, equals: item)
                }
            }
        }
        .defaultFocus($currentFocusItem, lastFocusItem ?? items.first, priority: .userInitiated)
        .onChange(of: currentFocusItem) {
            if currentFocusItem != nil {
                lastFocusItem = currentFocusItem
            }
        }
    }
}
How to force focus engine to focus first item in HStack when this HStack is about to get focused?
 
 
Q