scenee / FloatingPanel

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

Update panel height programmatically when panel is already presented #506

Open AndrexOfficial opened 3 years ago

AndrexOfficial commented 3 years ago

Hello, I'm trying to change panel's height in order to adapt it to content, the content arrives later because of API but panel is already presented and shown. I tried to make a func in order to update it but without success, it updates only after changing scroll position with my finger.

Here's my code:

func updatePanelViewHeight() {
        guard isViewLoaded else { return }
        floatingPanelController?.invalidateLayout()
        let productTitleLines = productTitleLabel.numberOfVisibleLines
        let productPriceLines = productPriceLabel.numberOfVisibleLines
        appFloatingPanelLayout?.heightToAdd = CGFloat(productTitleLines + productPriceLines) + 20
        floatingPanelController?.layout = tezenisFloatingPanelLayout!
        floatingPanelController?.updateViewConstraints()
        floatingPanelController?.viewDidLayoutSubviews()
        floatingPanelController?.notifyDidMove()
    }

What am I doing wrong? Thanks

scenee commented 3 years ago

FloatingPanelController expects invalidateLayout() is called after a new layout is assigned into it. Please see also README - Update your panel layout. If you call invalidateLayout() in an animation block. The layout changes with the animation.