0

RoomView.swift

ScrollViewReader { proxy in
    
    ScrollView {
        VStack  {
            LazyVGrid(columns: twoColumnGrid, alignment: .leading) {
                ForEach(roomData.newItems, id: \.id) { item in
                    
                    VStack{
                        ItemView(lastDeleted: $recentDeletedItems, item: item, roomData: roomData)
                    }
                    
                }
            }
        }
    }
    .onChange(of: roomData.lastItemID) { id in
        print("ID Changed: \(String(describing: id))")
        withAnimation { proxy.scrollTo(id, anchor: .bottom) }
    }
    .onAppear(perform: {
        proxy.scrollTo(roomData.lastItemID, anchor: .bottom)
    })
    
}      

On adding new items, the print statement inside .onChange prints the correct lastItemID but still it won't scroll to bottom. What am I missing?

0 Answers0