scenee / FloatingPanel

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

Full screen panel with intrinsic layout #300

Closed mcg95 closed 3 years ago

mcg95 commented 4 years ago

Short description

I have 2 floating panels in my VC. One only covers half the screen, while the other needs to take the complete screen. I will refer to the panels as such in the rest of the issue Half Screen Panel - Panel 1 Full Screen Panel - Panel 2 I am using an intrinsic layout, so that Panel 1 cannot be expanded completely. However, using the intrinsic layout, I am not able to cover the full screen using Panel 2.

Expected behavior

Open Panel 1 and it should not be able to be expanded more than the height set in the insetFor(position: FloatingPanelPosition). Open Panel 2 and it should be expanded to the height of the complete screen.

Actual behavior

Panel 1 works as required. Panel 2 does not show up at all, and if I set a height in insetFor(position: FloatingPanelPosition) function. It crashes. However, if I do not set it, it will be nil and the Panel does not slide up at all.

Steps to reproduce

Code example that reproduces the issue `
private func setupFloatingPanel(viewController: UIViewController, floatingPanelPosition: FloatingPanelPosition) {

    slidingViewIsDisplayed = true
    fpc = FloatingPanelController()
    fpc.delegate = self
    fpc.view.backgroundColor = StyleSheet.Color.panelBackgroundColor
    fpc.surfaceView.backgroundColor = StyleSheet.Color.panelBackgroundColor
    self.view.addSubview(fpc.view)
    fpc.view.frame = self.view.bounds
    fpc.view.translatesAutoresizingMaskIntoConstraints = false
    NSLayoutConstraint.activate([
      fpc.view.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 0.0),
      fpc.view.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: 0.0),
      fpc.view.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: 0.0),
      fpc.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: 0.0)
    ])
    fpc.set(contentViewController: viewController)
    fpc.addPanel(toParent: self, belowView: stackView, animated: true)
    self.addChild(fpc)
    fpc.show(animated: true, completion: {
        self.fpc.didMove(toParent: self)
    })
    fpc.move(to: floatingPanelPosition, animated: true)
}

class MyFloatingPanelLayout: FloatingPanelIntrinsicLayout {
public var initialPosition: FloatingPanelPosition {
    return .tip
}

public func insetFor(position: FloatingPanelPosition) -> CGFloat? {
    switch position {
    case .half: return 310.0 // A bottom inset from the safe area
    case .tip: return 0.0 // A bottom inset from the safe area
    default: return nil // Or `case .hidden: return nil`
    }
}
var supportedPositions: Set<FloatingPanelPosition> {
    return [.tip, .half, .full]
}

} `

Environment

Library version 1.7.1 Installation method

iOS version(s) iOS 13 - iPhone 11 Simulator Xcode version 11.2.1

scenee commented 4 years ago

I will investigate this issue.

scenee commented 4 years ago

You don't need to call the following codes after calling fpc.addPanel(toParent: self, belowView: stackView, animated: true) because addPanel(toParent:) does the same ones.

    self.addChild(fpc)
    fpc.show(animated: true, completion: {
        self.fpc.didMove(toParent: self)
    })
    fpc.move(to: floatingPanelPosition, animated: true)