scenee / FloatingPanel

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

How to desactivate attraction for positions between full and tip #434

Closed i-arun-samui closed 3 years ago

i-arun-samui commented 3 years ago

Description

Expected behavior

I would like to be able to have to floatingpanel to stop where the user stop dragging, with limits on top and bottom

Actual behavior

the floatingpanel goes to top, half, tip

Steps to reproduce

Code example that reproduces the issue

How do you display panel(s)? floatingPanel = FloatingPanelController() floatingPanel.delegate = self floatingPanel.delegate?.floatingPanelDidEndDragging?(floatingPanel, willAttract: false) floatingPanel.layout = MyFloatingPanelLayout() let storyBoard = UIStoryboard(name: "Main", bundle: nil) let contentVC = storyBoard.instantiateViewController(withIdentifier: "pagingPage") as? Paging floatingPanel.set(contentViewController: contentVC) floatingPanel.addPanel(toParent: self)

class MyFloatingPanelLayout: FloatingPanelLayout { let position: FloatingPanelPosition = .bottom let initialState: FloatingPanelState = .tip var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] { return [ .full: FloatingPanelLayoutAnchor(absoluteInset: 0.0, edge: .top, referenceGuide: .safeArea), .half: FloatingPanelLayoutAnchor(fractionalInset: 0.5, edge: .bottom, referenceGuide: .safeArea), .tip: FloatingPanelLayoutAnchor(absoluteInset: 20.0, edge: .bottom, referenceGuide: .safeArea), ] } }

How many panels do you displays? 1

Environment

iphone ipad MacOS catalyst Library version 2.1.0 Installation method CocoaPods

iOS version(s) ios 14

Xcode version 12.2

scenee commented 3 years ago

Specify the panel move's boundary will help you.

i-arun-samui commented 3 years ago

Hi,

Thanks for your answer,

To suit my need I finally change FloatingPanelStates, this way (adding 2 intermediate states) :

@objc(Full) public static let full: FloatingPanelState = FloatingPanelState(rawValue: "full", order: 1000) /// A panel state indicates the 3/4 of a panel is shown. @objc(LastQuart) public static let lastQuart: FloatingPanelState = FloatingPanelState(rawValue: "lastQuart", order: 750) /// A panel state indicates the half of a panel is shown. @objc(Half) public static let half: FloatingPanelState = FloatingPanelState(rawValue: "half", order: 500) /// A panel state indicates the 1/4 of a panel is shown. @objc(FirstQuart) public static let firstQuart: FloatingPanelState = FloatingPanelState(rawValue: "firstQuart", order: 250) /// A panel state indicates the tip of a panel is shown. @objc(Tip) public static let tip: FloatingPanelState = FloatingPanelState(rawValue: "tip", order: 100)

all good for me

you could open FloatingPanelState to be able to easily add states

scenee commented 3 years ago

Hi, @i-arun-samui. Could you tell me how you use lastQuart and firstQuart? Because I think just adding them is not enough to deactivate attractions 🤔

i-arun-samui commented 3 years ago

hi, it doesn't deactivate attractions but it add intermediate states which suit my needs. I couldn't achieve the deactivation of attraction without messing up layout. I need initial state to be bottom (tip) with min Y (absoluteInset: 20.0 from bottom edge) and Max Y (top view area)

On iPad I'm thinking to add more intermediates states

class VerticalFloatingPanelLayout: FloatingPanelLayout { let position: FloatingPanelPosition = .bottom let initialState: FloatingPanelState = .tip var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] { return [ .full: FloatingPanelLayoutAnchor(absoluteInset: 0.0, edge: .top, referenceGuide: .safeArea), .lastQuart: FloatingPanelLayoutAnchor(fractionalInset: 0.75, edge: .bottom, referenceGuide: .safeArea), .half: FloatingPanelLayoutAnchor(fractionalInset: 0.5, edge: .bottom, referenceGuide: .safeArea), .firstQuart: FloatingPanelLayoutAnchor(fractionalInset: 0.25, edge: .bottom, referenceGuide: .safeArea), .tip: FloatingPanelLayoutAnchor(absoluteInset: 20.0, edge: .bottom, referenceGuide: .safeArea), ] } }

i-arun-samui commented 3 years ago

this line doesn't stop attraction floatingPanel.delegate?.floatingPanelDidEndDragging?(floatingPanel, willAttract: false)

scenee commented 3 years ago

Him @i-arun-samui. I've created PR #438 to create a custom state like . lastQuart/. firstQuart as you mentioned.

this line doesn't stop attraction floatingPanel.delegate?.floatingPanelDidEndDragging?(floatingPanel, willAttract: false)

Yes, it does because it's a delegate method. You are able to prevent a panel bounce by using a critical damped spring behavior which can be defined in FloatingPanelBehavior.springDecelerationRate.

i-arun-samui commented 3 years ago

Hi, Thank you very much for adding states customization, and clarifying the use of floatingPanel, willAttract: false Regards