Swiftgram/Display/TabBarContollerNode.swift
2017-11-14 20:39:42 +03:00

54 lines
1.6 KiB
Swift

import Foundation
import AsyncDisplayKit
final class TabBarControllerNode: ASDisplayNode {
let tabBarNode: TabBarNode
var currentControllerView: UIView? {
didSet {
oldValue?.removeFromSuperview()
if let currentControllerView = self.currentControllerView {
self.view.insertSubview(currentControllerView, at: 0)
}
}
}
init(theme: TabBarControllerTheme, itemSelected: @escaping (Int) -> Void) {
self.tabBarNode = TabBarNode(theme: theme, itemSelected: itemSelected)
super.init()
self.setViewBlock({
return UITracingLayerView()
})
self.backgroundColor = theme.backgroundColor
self.addSubnode(self.tabBarNode)
}
func updateTheme(_ theme: TabBarControllerTheme) {
self.backgroundColor = theme.backgroundColor
self.tabBarNode.updateTheme(theme)
}
func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
let update = {
let tabBarHeight = 49.0 + layout.insets(options: []).bottom
self.tabBarNode.frame = CGRect(origin: CGPoint(x: 0.0, y: layout.size.height - tabBarHeight), size: CGSize(width: layout.size.width, height: tabBarHeight))
if self.tabBarNode.isNodeLoaded {
self.tabBarNode.layout()
}
}
switch transition {
case .immediate:
update()
case .animated:
update()
}
}
}