scenee / FloatingPanel

A clean and easy-to-use floating panel UI component for iOS
MIT License
5.61k stars 509 forks source link

Stuttering, laggy movement of panels on newer versions #578

Closed tarrouye closed 1 year ago

tarrouye commented 1 year ago

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.

https://user-images.githubusercontent.com/5017270/211762411-5a9134d7-8975-4df4-968b-794355bcdc4e.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)?

How many panels do you displays?

Environment

Library version

2.5.5

Installation method

iOS version(s)

16.2

Xcode version

14.2

scenee commented 1 year ago

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.

  1. 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.
  2. 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.
tarrouye commented 1 year ago

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