Swipe for options swiftUI scrollview

1k views Asked by At

forgive me if this question has been asked before I did a quick search a couldn't find the answer. I'm creating an app in which a user can receive a friend request and I want the user to be able to swipe to the left to show different options to accept or decline the request

for more clarification this is what I want it to look like enter image description here enter image description here

if it helps this is my scroll view

 ScrollView(.vertical){
                        VStack(spacing: 40){
                            
                            // TODO Add Chat Rooms
                            ForEach(ChatRooms, content: {room in
                                //Create an in app link that navigates to messaging screen
                                NavigationLink(
                                    destination: MessageDetail(messageShowing: $detailShowing),
                                    isActive: $detailShowing,
                                    label: {
                                        //Create a chat room card
                                        Button(action: {
                                            detailShowing = true
                                        }, label: {
                                            ChatRoomView(room: room)
                                        }).buttonStyle(PlainButtonStyle())
                                        
                                    }
                                    
                                ).buttonStyle(PlainButtonStyle())
                            
                        })
                        
                    }.padding(.top, 30)
                }

edit: I tried nesting a horizontal scroll view inside my vertical scrollview like the following ScrollView (.horizontal) { VStack(spacing: 40){

                                // TODO Add Chat Rooms
                                ForEach(ChatRooms, content: {room in
                                    //Create an in app link that navigates to messaging screen
                                    ScrollView (.horizontal) {
                                        NavigationLink(
                                            destination: MessageDetail(messageShowing: $detailShowing),
                                            isActive: $detailShowing,
                                            label: {
                                                //Create a chat room card
                                                Button(action: {
                                                    detailShowing = true
                                                }, label: {
                                                    ChatRoomView(room: room)
                                                }).buttonStyle(PlainButtonStyle())

                                            }

                                        ).buttonStyle(PlainButtonStyle())
                                    }



                                })

                           }.padding(.top, 30)
                        }

but this is what I end with

enter image description here

1

There are 1 answers

1
Shivam Parmar On

try this class :-

https://github.com/EnesKaraosman/SwipeCell

how to use:-

Simply add onSwipe(leading, trailing) method to your list item
    List {
        HStack {
            Text("Enes Karaosman")
            Spacer()
        }
        .listRowInsets(EdgeInsets())
        .onSwipe(leading: [
          .. // here add slots
        ])
        
    }