Skip to content

Commit

Permalink
Merge pull request #1151 from OrkhanAlikhanov/new-features
Browse files Browse the repository at this point in the history
New features
  • Loading branch information
DanielDahan authored Sep 13, 2018
2 parents d82a9cd + 9707a8f commit 5876288
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 18 deletions.
22 changes: 22 additions & 0 deletions Sources/iOS/BottomNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ extension UIViewController {
}
}

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
}
}

open class BottomNavigationController: UITabBarController {
/// A Boolean that indicates if the swipe feature is enabled..
open var isSwipeEnabled = false {
Expand All @@ -60,6 +69,7 @@ open class BottomNavigationController: UITabBarController {
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setTabBarClass()
}

/**
Expand All @@ -69,6 +79,7 @@ open class BottomNavigationController: UITabBarController {
*/
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
setTabBarClass()
}

/// An initializer that accepts no parameters.
Expand Down Expand Up @@ -143,6 +154,17 @@ open class BottomNavigationController: UITabBarController {
}
}

private extension BottomNavigationController {
/// Sets tabBar class to MaterialTabBar.
func setTabBarClass() {
guard object_getClass(tabBar) === UITabBar.self else {
return
}

object_setClass(tabBar, MaterialTabBar.self)
}
}

private extension BottomNavigationController {
/**
Selects a view controller at a given index.
Expand Down
79 changes: 77 additions & 2 deletions Sources/iOS/Depth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,33 @@

import UIKit

@objc(DepthPreset)
public enum DepthPreset: Int {
public enum DepthPreset {
case none
case depth1
case depth2
case depth3
case depth4
case depth5
indirect case above(DepthPreset)
indirect case below(DepthPreset)
indirect case left(DepthPreset)
indirect case right(DepthPreset)

/// Returns raw depth value without considering direction.
public var rawValue: DepthPreset {
switch self {
case .above(let v):
return v.rawValue
case .below(let v):
return v.rawValue
case .left(let v):
return v.rawValue
case .right(let v):
return v.rawValue
default:
return self
}
}
}

public struct Depth {
Expand Down Expand Up @@ -110,5 +129,61 @@ public func DepthPresetToValue(preset: DepthPreset) -> Depth {
return Depth(offset: Offset(horizontal: 0, vertical: 4), opacity: 0.3, radius: 4)
case .depth5:
return Depth(offset: Offset(horizontal: 0, vertical: 8), opacity: 0.3, radius: 8)
case .above(let preset):
var v = DepthPresetToValue(preset: preset)
if preset.isRoot {
v.offset.vertical *= -1
} else {
let value = DepthPresetToValue(preset: preset.rawValue)
v.offset.vertical -= value.offset.vertical
}
return v
case .below(let preset):
var v = DepthPresetToValue(preset: preset)
if preset.isRoot {
return v
} else {
let value = DepthPresetToValue(preset: preset.rawValue)
v.offset.vertical += value.offset.vertical
}
return v
case .left(let preset):
var v = DepthPresetToValue(preset: preset)
if preset.isRoot {
v.offset.horizontal = -v.offset.vertical
v.offset.vertical = 0
} else {
let value = DepthPresetToValue(preset: preset.rawValue)
v.offset.horizontal -= value.offset.vertical
}
return v
case .right(let preset):
var v = DepthPresetToValue(preset: preset)
if preset.isRoot {
v.offset.horizontal = v.offset.vertical
v.offset.vertical = 0
} else {
let value = DepthPresetToValue(preset: preset.rawValue)
v.offset.horizontal += value.offset.vertical
}
return v
}
}

fileprivate extension DepthPreset {
/// Checks if the preset is the root value (has no direction).
var isRoot: Bool {
switch self {
case .above(_):
return false
case .below(_):
return false
case .left(_):
return false
case .right(_):
return false
default:
return true
}
}
}
51 changes: 39 additions & 12 deletions Sources/iOS/HeightPreset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,43 @@

import UIKit

@objc(HeightPreset)
public enum HeightPreset: Int {
case none = 0
case tiny = 20
case xsmall = 28
case small = 36
case `default` = 44
case normal = 49
case medium = 52
case large = 60
case xlarge = 68
case xxlarge = 104
public enum HeightPreset {
case none
case tiny
case xsmall
case small
case `default`
case normal
case medium
case large
case xlarge
case xxlarge
case custom(CGFloat)

public var rawValue: CGFloat {
switch self {
case .none:
return 0
case .tiny:
return 20
case .xsmall:
return 28
case .small:
return 36
case .`default`:
return 44
case .normal:
return 49
case .medium:
return 52
case .large:
return 60
case .xlarge:
return 68
case .xxlarge:
return 104
case .custom(let v):
return v
}
}
}
4 changes: 2 additions & 2 deletions Sources/iOS/Material+CALayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fileprivate class MaterialLayer {
/// A property that sets the height of the layer's frame.
fileprivate var heightPreset = HeightPreset.default {
didSet {
layer?.height = CGFloat(heightPreset.rawValue)
layer?.height = heightPreset.rawValue
}
}

Expand Down Expand Up @@ -281,7 +281,7 @@ extension CALayer {
return
}

if .none == depthPreset {
if case .none = depthPreset.rawValue {
shadowPath = nil
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
Expand Down
2 changes: 0 additions & 2 deletions Sources/iOS/Material+UIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ extension UIView {
}

/// HeightPreset value.
@objc
open var heightPreset: HeightPreset {
get {
return layer.heightPreset
Expand All @@ -87,7 +86,6 @@ extension UIView {
}

/// A preset value for Depth.
@objc
open var depthPreset: DepthPreset {
get {
return layer.depthPreset
Expand Down

0 comments on commit 5876288

Please sign in to comment.