UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Scroll and Drag Unwanted Interaction

Forums > SwiftUI

I have a scrollable list that responds to a long press on the left (score and sailNum) and allows moving items to reorder them. Editmode is on so there are bars on the right to instantly allow dragging to move. The blank center part of the item allows dragging to scroll the list. The issue is that if you try to scroll but hold too long the list jumps to move mode and you end up reordering instead of scrolling.

Is there a way to stop the UI switching to move mode and restrict it to the move bars at the right?

VStack {
                    Text("Scored Skippers").font(.title3).padding(5)
                    ScrollViewReader { proxy in
                        List {
                            ForEach(thisRace.heatScoredSkippers[thisHeat], id: \.id) { skip in
                                HStack {
                                    if skip.raceLetterScore == .👍 {
                                        Image(systemName: "\(Int(skip.raceRawScore)).circle.fill").font(.title3).foregroundColor(skip.promoteColor)
                                    } else {
                                        VStack {
                                            Image(systemName: "\(Int(skip.raceRawScore)).circle.fill")
                                            Text("\(skip.raceLetterScore.rawValue)").font(.caption2)
                                        }
                                    }

                                    Text(String(format: "%02d", skip.sailNum))

                                }.id(skip)
                                    .onLongPressGesture {
                                        isShowingRaceScore = skip
                                    }
                                    .disabled(skip.raceRawScore == 0 && !skip.scoreEditOK)
                                    .listRowBackground(skip.scoreBG)

                            }
                            .onMove(perform: move)
                        }
                        .id(UUID())
                        .scrollContentBackground(.hidden)
                        .scrollIndicators(.visible)
                        .background(.green.opacity(0.05))
                        .sheet(item: $isShowingRaceScore) { skip in
                            UpdateScoreView(thisRscore: skip)
                        }
                        .environment(\.editMode, .constant(.active))
                        .onChange(of: thisRace.areScored) { _ in
                            withAnimation {
                                proxy.scrollTo(thisRace.scoredSkippers.last)
                            }
                        }
                    } //ScrollViewReader

                }
                .frame(width: geometry.size.width * 0.6)
                .background(.green.opacity(0.3))

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.