Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
i-arun-samui opened this issue Jan 15, 2021 · 7 comments
Closed

Comments

@i-arun-samui
Copy link

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
Copy link
Owner

scenee commented Jan 15, 2021

Specify the panel move's boundary will help you.

@i-arun-samui
Copy link
Author

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
Copy link
Owner

scenee commented Jan 24, 2021

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
Copy link
Author

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
Copy link
Author

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

@scenee
Copy link
Owner

scenee commented Feb 6, 2021

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants