scenee / FloatingPanel

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

Transition to layout with a single anchor breaks panel behavior #611

Closed nikita-bor closed 1 year ago

nikita-bor commented 1 year ago

Description

I'm working on a scenario that requires a transition between two layouts:

class FirstLayout: FloatingPanelLayout {
    let position: FloatingPanelPosition = .bottom
    let initialState: FloatingPanelState = .half
    let anchors: [FloatingPanelState : FloatingPanelLayoutAnchoring] = [
        .full: FloatingPanelLayoutAnchor(absoluteInset: 16.0, edge: .top, referenceGuide: .safeArea),
        .half: FloatingPanelLayoutAnchor(absoluteInset: 262, edge: .top, referenceGuide: .safeArea),
        .tip: FloatingPanelLayoutAnchor(absoluteInset: 44.0, edge: .bottom, referenceGuide: .safeArea)
    ]
}

class SecondLayout: FloatingPanelLayout {
    let position: FloatingPanelPosition = .bottom
    let initialState: FloatingPanelState = .half
    let anchors: [FloatingPanelState : FloatingPanelLayoutAnchoring] = [
        .half: FloatingPanelLayoutAnchor(absoluteInset: 262, edge: .top, referenceGuide: .safeArea)
    ]
 }

Expected behavior

1) FirstLayout is active and current state is .tip 2) Set SecondLayout and call fpc.invalidateLayout() 3) State is .half and despite any attempts to drag the panel, the panel remains in a half state, since it's the only state that's allowed by the currently active SecondLayout

Actual behavior

1) FirstLayout is active and current state is .tip 2) Set SecondLayout and call fpc.invalidateLayout() 3) State is .half. Dragging the panel to the top or to the bottom makes it disappear, almost like it's transitioning to the .tip state from FirstLayout

Steps to reproduce

Code example that reproduces the issue

https://github.com/swasta/FloatingPanelLayoutTransitioning

https://github.com/scenee/FloatingPanel/assets/5530878/181f3eaf-cd41-4748-b657-811016774e4e

How do you display panel(s)?

Present modally

How many panels do you displays?

1

Environment

2.8.0

Installation method

CocoaPods

iOS version(s)

iOS 17.0.1

Xcode version

15.0.1

scenee commented 1 year ago

Thanks for your report. It looks a bug. I will dive deep this issue later.

scenee commented 1 year ago

Thanks to your example code, I found the cause of the problem easily. I have fixed it in dbef6a6 commit and then it will be released in v2.8.1 shortly.

Thank you.