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      

Hacking with Swift is sponsored by Superwall

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn 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.