Stuttering, laggy movement of panels on newer versions
tarrouye opened this issue · comments
Description
We recently updated this library from version 1.7.6
to 2.5.5
in our project, and after updating all of our layouts etc to meet the new APIs, I've noticed that the animations and movement when dragging or programmatically moving the panels feels super laggy and uncomfortable on the newer version.
Expected behavior
The panel movement should be smooth.
Actual behavior
The panel movement feels slow, stuttery, and makes the app feel laggy.
It's a bit hard to see in video, but here is one anyways comparing an empty panel from this library to the one from Apple Maps. On device, moving it yourself, it's very apparent.
RPReplay_Final1673427406.mov
Steps to reproduce
I see this on every panel in our application after updating, simply by dragging them around or by triggering actions that call the move(to: ..)
function. It feels especially apparent when triggering a move from .full
to .tip
, where it seems to get especially funky around the .half
position on the way down.
Code example that reproduces the issue
the layout:
class ExampleBadFeelingLayout: FloatingPanelLayout {
let position: FloatingPanelPosition = .bottom
let initialState: FloatingPanelState = .tip
let anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] = [
.full: FloatingPanelLayoutAnchor(absoluteInset: 100, edge: .top, referenceGuide: .safeArea),
.half: FloatingPanelLayoutAnchor(fractionalInset: 0.5, edge: .bottom, referenceGuide: .safeArea),
.tip: FloatingPanelLayoutAnchor(absoluteInset: 100, edge: .bottom, referenceGuide: .superview)
]
func backdropAlpha(for state: FloatingPanelState) -> CGFloat {
0
}
}
simply applied to a floating panel as done in the docs
How do you display panel(s)?
- Present modally, one at a time (dismiss previous if will show another)
How many panels do you displays?
- 1 at a time, but many
Environment
Library version
2.5.5
Installation method
- Swift Package Manager
iOS version(s)
16.2
Xcode version
14.2
I believe this issue doesn't happen on the Samples app. So it should depend on your application.
I guess there are 2 possible causes.
- The main thread is busy: v2 hans't used UIViewPropertyAnimator anymore to move a panel into a position. Instead, it uses CADIsplayLink with the custom animation logic. Thus, a panel animation can be laggy if the main thread of an app is busy.
floatingPanelDidMove
delegate is blocking the animation: v2 calls the delegate while a user drags the surface or the surface animates to a state anchor. On the other hand, v1 called only when a user drags. Therefore the delegate method can block the panel animation if its implementation is heavy.
@scenee Thank you so much for the insight, that's very helpful. Both of those sound like changes that could have caused a performance hit for us. Appreciate the response, and will take a look on our end.