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

New features #1151

Merged
merged 5 commits into from
Sep 13, 2018
Merged

New features #1151

merged 5 commits into from
Sep 13, 2018

Conversation

OrkhanAlikhanov
Copy link
Contributor

@OrkhanAlikhanov OrkhanAlikhanov commented Sep 12, 2018

Added left/right/above/below directions to DepthPreset.

We can now use, depthPreset = .below(.right(.depth5))) and get shadow cast below and right of the view.
Using the same modifier twice just increases the offset:

depthPreset = .right(.right(.below(.below(.depth5)))))

Default is direction is below.

depthPreset = .below(.depth5)
depthPreset = .depth5 // same as above

Note: Had to remove @objc to add this feature.

Added .custom(x) case for HeightPreset.

heightPreset = .custom(32.3)

Note: Had to remove @objc to add this feature.

Added support for heightPreset in BottomNavigationController.

Manipulating tabBar.frame was only working in layoutSubviews(). Using this way had drawbacks:

  1. tabBar height was returned back to default on rotation.
  2. selectedViewController?.view.frame was not changing even though it was calculated and set. (It should shrink as the tabBar grows occupying the space)

Fortunately, tabBar height is taken via sizeThatFits method, so I use UITabBar subclass returning custom height based on heightPreset value.

private class MaterialTabBar: UITabBar {
  override func sizeThatFits(_ size: CGSize) -> CGSize {
    var v = super.sizeThatFits(size)
    let offset = v.height - HeightPreset.normal.rawValue
    v.height = heightPreset.rawValue + offset
    return v
  }
}

v.height - HeightPreset.normal.rawValue calculates the offset of the system from our reference. It allows us to match system's behavior.

Suppose tabBar.heightPreset = .normal //rawValue is 49 and super.sizeThatFits(size).height returns 49. In this case resulting height becomes 49, if the system would return 83 or 58 (values are for iPhoneX's portrait and landscape orientation respectively), the resulting height would be the same. If we set tabBar.heightPreset = .xxlarge then for iPhoneX's portrait and landscape orientation the tabBar height would be 138 and 113 respectively. In portrait it has larger tabBar height than landscape, so behavior of the system is matched.

Related:
#1144, #1150

@daniel-jonathan daniel-jonathan merged commit 5876288 into CosmicMind:development Sep 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants