TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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 String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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.