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

Modified for custom DropDown Height #306

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dev-Siddhesh
Copy link

@dev-Siddhesh dev-Siddhesh commented Jun 20, 2022

In pod file DropDown.swift do following changes for custom height

Step 1 : Add this below width property

public var height: CGFloat? {
       didSet { setNeedsUpdateConstraints() }
 }

Step 2 : In public override func updateConstraints() do this

replace 
`heightConstraint.constant = layout.visibleHeight `
with following

if let height = self.height {
    if layout.visibleHeight >= height {
         heightConstraint.constant = self.height ?? layout.visibleHeight
     } else {
         heightConstraint.constant = layout.visibleHeight
     }
} else {
     heightConstraint.constant = layout.visibleHeight
}

Step 3 : In fileprivate func computeLayoutForTopDisplay(window: UIWindow) -> ComputeLayoutTuple do this

replace

if y < windowY {
    offscreenHeight = abs(y - windowY)
    y = windowY
}

with following

if y < windowY {
 offscreenHeight = abs(y - windowY)
  if let height = self.height {
         y = anchorViewMaxY + topOffset.y - height
    } else {
          y = windowY
    }
 }

Uses

let dropDown = DropDown()
dropDown.height = 50

If height is not set, the dropdown height will be its content size and if content size is greater than screen/superview size then it will stop at view bounds and dropdown's scroll is activated.
If you don't want that set height as suggested above.
After setting height:-

  1. if your content size is less than your assigned height it will wrap to its content means dropdown will have height of its content size, you will see all dropdown option in list.
  2. If content size exceeds assigned height then dropdown will have its assigned height and scroll will be activated.

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.

2 participants