Unlike in UIKit, where a LongPressGesture is actually delayed, in SwiftUI it began as soon as you hover/pan/touch the view. So if you have a LongPressGesture/Action in a View within a List or a NavigationLink, it'll prevent scrolling the List, or triggering the NavigationLink action.
Anyone have any idea if it's possible to delay it with current API?
Related
I was looking to replicate the functionality contained in the native iOS Clock and Contacts apps for list items. After pressing "Edit" at the top right, red "minus" circles appear on the left side of each list item. If you press the minus sign, it "swipes" the list item to the right and shows the "Delete" swipeAction:
Contacts Groups List View
Contacts Groups List Edit View
Contacts Groups List Edit View - Swipe Action Active
I can set the swipeActions for a list item easily, and can replicate the edit button. As well as adding the minus buttons when editing the list (I used an HStack with a Button and Text view inside). What I cannot find anywhere is how to have the button action show the swipe action. All related posts comment on having the button action closure run the code that a gesture would typically activate. From what I understand, the gesture handling is done inside of SwiftUI itself for swipeActions, and I cannot find a way that you could imitate the result. Would this be something that would have to be done in UIKit? Or would I have to build a custom version of swipeActions to implement the same feature?
I have tried researching imitating gestures on Views, but everything seems to say it is not possible to do so
I have a SwiftUI puzzle game. I store played puzzles and show in the history view. History view is displayed as a sheet when a button is tapped. In the history view, I want to have a button ("Replay puzzle") which should 1) dismiss the history view, and 2) run a function in the main view so that a game from history view can be replayed.
Seems simple but I could not figure out how to call a function in the main view to update the current game. Any pointers would be appreciated.
Use onDismiss parameter of .sheet, like in https://stackoverflow.com/a/63673342/12299030
I have a case where one of my SwiftUI Views is automatically going back to previous screen on a published variable change, which is not related to isActive. I want to stop navigating the swiftUI view onViewWillDisappear(). How can I stop SwiftUI from navigating just before it is navigating.
I have a List view. ForEach element there is a card which is a child class. Data has been passed to the child class using #Binding. There is a button in the child class which updates the #Binding element. I am using a plugin named Pages(https://github.com/nachonavarro/Pages) to show a slideShow of images in the listView's card.
Problem: Every time I update a state/binding element onButtonPress, the plugin Pages re-renders due to which I see flickering when updation. Is there a way to prevent or solve this problem???
Questions that come to my mind:
Is there any way to prevent the plugin from re-rendering?
Why does the all the elements update in a View even though there is just 1 element dependent on the updated state variable?
I'm building a SwiftUI app for macOS, then I came with the following challenge.
Given a view hierarchy like:
Which basically shows a collection of elements in ElementListView. Then the FiltersView is used to search new elements to possibly add to the element list, the results of that search are shown in rows like FilterRow.
When a user clicks on FilterRow, that means I want to add a new element to the ElementListView, but I am not sure of How to propagate events between the two branches of the view hierarchy in SwiftUI?
If I were to implement this in pure AppKit, I would probably use the responder chain, but I guess it's not the SwiftUI way of doing it.
You can have a shared ObservableObject for filters and list views. As soon as ObservableObject changes SwiftUI updates views connected to it.