Skip to content

Conversation

@anomaddev
Copy link

Had a use case where I needed a collapsed case, a partiallyOpen case, and then a pushedUp case that was basically a partially open state that opens a little more to handle a view that animates in. Added a new snapPosition pushedUp and a variable on the drawer called pushUp that will take the partiallyOpenHeight and open it the set amount more to add to the height without fully opening the drawer.

See example:

@objc public enum DrawerPosition: Int {
    case closed = 0
    case collapsed = 1
    case partiallyOpen = 2
    case pushedUp = 3
    case open = 4
}
@IBDesignable open class DrawerView: UIView {
// . . .
/// The height of the drawer when partially open.
    public var partiallyOpenHeight: CGFloat = 264.0 {
        didSet {
            self.updateSnapPosition(animated: false)
        }
    }
    
    /// The amount the drawer is pushed up from partially open when selected.
    public var pushUp: CGFloat = 50 {
        didSet {
            self.updateSnapPosition(animated: false)
        }
    }
// . . . 
fileprivate func snapPosition(for position: DrawerPosition, inSuperView superview: UIView) -> CGFloat {
        switch position {
        case .open:
            if let height = self.openHeight {
                return max(self.topMargin, superview.bounds.height - bottomInset - height)
            } else {
                return self.topMargin
            }
            
        case .pushedUp:
            return superview.bounds.height - bottomInset - (self.pushUp + self.partiallyOpenHeight)
        case .partiallyOpen:
            return superview.bounds.height - bottomInset - self.partiallyOpenHeight
        case .collapsed:
            return superview.bounds.height - bottomInset - self.collapsedHeight
        case .closed:
            // When closed, the safe area is ignored since the
            // drawer should not be visible.
            return superview.bounds.height
        }
    }
// . . .

@mkko mkko force-pushed the master branch 2 times, most recently from 5816e8c to 9dedb12 Compare February 3, 2024 10:02
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

Successfully merging this pull request may close these issues.

1 participant