FloatingPanel icon indicating copy to clipboard operation
FloatingPanel copied to clipboard

lock the panel and prevent going to tip state?

Open alouanemed opened this issue 5 years ago • 9 comments

Is there any to lock the panel and prevent going to tip state and support only half and full?

I am using the Maps example.

How do you display panel(s)?

  • Add as child view controllers

How many panels do you displays?

  • 1

Environment

Library version latest

Installation method

  • CocoaPods

iOS version(s) 14

Xcode version latest

alouanemed avatar Oct 22 '20 08:10 alouanemed

Is there any to lock the panel and prevent going to tip state and support only half and full?

Does lock the panel mean that a panel doesn't become the tip state, doesn’t it? If so, yes, you can define a layout object adopting FloatingPanelLayout to change supported states of a panel and then assign the instance to FloatingPanelLayout.layout.

Here is a short way to define a layout object inherited from FloatingPanelBottomLayout.

class MyPanelLayout: FloatingPanelBottomLayout {
    override var anchors: [FloatingPanelState : FloatingPanelLayoutAnchoring] {
        return [
            .full: FloatingPanelLayoutAnchor(absoluteInset: 88.0, edge: .bottom, referenceGuide: .safeArea),
            .half: FloatingPanelLayoutAnchor(absoluteInset: 216.0, edge: .top, referenceGuide: .safeArea),
        ]
    }
}

scenee avatar Oct 23 '20 10:10 scenee

I removed. .tip from anchor here: https://github.com/SCENEE/FloatingPanel/blob/master/Examples/Maps/Maps/ViewController.swift#L295 but still can scroll to the tup state.

alouanemed avatar Oct 25 '20 10:10 alouanemed

Aha, I might be able to understand your expectation. How about this code?(please use this with the above layout) You can control a panel move in floatingPanelDidMove delegate method. This code prevents moving a pane under a position of half state.

    func floatingPanelDidMove(_ vc: FloatingPanelController) {
        let loc = vc.surfaceLocation
        if vc.isAttracting == false {
            let maxY = vc.surfaceLocation(for: .half).y
            vc.surfaceLocation = CGPoint(x: loc.x, y: min(loc.y, maxY))
        }
    }

scenee avatar Oct 29 '20 23:10 scenee

tried several methods but not working. The panel keeps going to the tip when scrolled, while i want it to stay fixed and locked in half and can be dragged to full state.

alouanemed avatar Nov 09 '20 12:11 alouanemed

You look use a top positioned panel. The above example code is for a bottom positioned panel. So in addition to the change of your comment, please try this in Maps example app.

class SearchPanelPadDelegate: NSObject, FloatingPanelControllerDelegate, UIGestureRecognizerDelegate {
    ...
    func floatingPanelDidMove(_ vc: FloatingPanelController) {
        let loc = vc.surfaceLocation
        if vc.isAttracting == false {
            let minY = vc.surfaceLocation(for: .half).y
            vc.surfaceLocation = CGPoint(x: loc.x, y: max(loc.y, minY))
        }
    }
}

scenee avatar Nov 10 '20 10:11 scenee

The behavior is weird now. Were you able to test in the Map example? Thanks.

alouanemed avatar Nov 19 '20 12:11 alouanemed

Hmm... yes, I was of course. I'm having trouble understanding your situation. You said as below.

I removed. .tip from anchor here: https://github.com/SCENEE/FloatingPanel/blob/master/Examples/Maps/Maps/ViewController.swift#L295

But the layout removed .tip is not valid because the initial state is tip. Which of panel did you want to modify a layout in Map example?

scenee avatar Nov 19 '20 13:11 scenee

The search one declared here: https://github.com/SCENEE/FloatingPanel/blob/master/Examples/Maps/Maps/ViewController.swift#L11

alouanemed avatar Nov 22 '20 09:11 alouanemed

Hi @alouanemed, I just added the below lines and it is working for me. You can also give it a try.

extension FloatingPanelBottomLayout { open var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] { return [ .full: FloatingPanelLayoutAnchor(absoluteInset: 18.0, edge: .top, referenceGuide: .safeArea), .half: FloatingPanelLayoutAnchor(fractionalInset: 0.5, edge: .bottom, referenceGuide: .safeArea) ] } }

mallikarjuna0308 avatar Jun 23 '21 13:06 mallikarjuna0308