2019-09-30 15:04:19 -07:00
|
|
|
/*
|
2022-10-04 13:59:32 -07:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2017-02-13 09:05:22 -08:00
|
|
|
*
|
2019-10-15 10:30:08 -07:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-02-13 09:05:22 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import YogaKit
|
|
|
|
|
|
|
|
final class LayoutInclusionViewController: UIViewController {
|
|
|
|
private let button: UIButton = UIButton(type: .system)
|
|
|
|
private let disappearingView: UIView = UIView(frame: .zero)
|
|
|
|
private let contentView: UIView = UIView(frame: .zero)
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
2023-06-05 22:18:39 -07:00
|
|
|
super.viewDidLoad()
|
2017-02-13 09:05:22 -08:00
|
|
|
let root = self.view!
|
|
|
|
root.backgroundColor = .white
|
2017-03-13 12:07:19 -07:00
|
|
|
root.configureLayout { (layout) in
|
|
|
|
layout.isEnabled = true
|
|
|
|
layout.flexDirection = .column
|
|
|
|
layout.justifyContent = .spaceAround
|
|
|
|
}
|
2017-02-13 09:05:22 -08:00
|
|
|
|
|
|
|
contentView.backgroundColor = .clear
|
|
|
|
contentView.layer.borderColor = UIColor.lightGray.cgColor
|
|
|
|
contentView.layer.borderWidth = 1.0
|
2017-03-13 12:07:19 -07:00
|
|
|
contentView.configureLayout { (layout) in
|
|
|
|
layout.isEnabled = true
|
|
|
|
layout.height = 300
|
2017-04-28 10:32:02 -07:00
|
|
|
layout.width = YGValue(self.view.bounds.size.width)
|
2017-03-13 12:07:19 -07:00
|
|
|
layout.flexDirection = .row
|
|
|
|
layout.justifyContent = .center
|
|
|
|
layout.paddingHorizontal = 25
|
|
|
|
}
|
2017-02-13 09:05:22 -08:00
|
|
|
self.view.addSubview(contentView)
|
|
|
|
|
|
|
|
let redView = UIView(frame: .zero)
|
|
|
|
redView.backgroundColor = .red
|
2017-03-13 12:07:19 -07:00
|
|
|
redView.configureLayout { (layout) in
|
|
|
|
layout.isEnabled = true
|
|
|
|
layout.flexGrow = 1
|
|
|
|
layout.flexShrink = 1
|
|
|
|
}
|
2017-02-13 09:05:22 -08:00
|
|
|
contentView.addSubview(redView)
|
|
|
|
|
|
|
|
disappearingView.backgroundColor = .blue
|
2017-03-13 12:07:19 -07:00
|
|
|
disappearingView.configureLayout { (layout) in
|
|
|
|
layout.isEnabled = true
|
|
|
|
layout.flexGrow = 1
|
|
|
|
}
|
2017-02-13 09:05:22 -08:00
|
|
|
contentView.addSubview(disappearingView)
|
|
|
|
|
2023-06-05 22:18:39 -07:00
|
|
|
button.setTitle("Add Blue View", for: .selected)
|
|
|
|
button.setTitle("Remove Blue View", for: .normal)
|
|
|
|
button.addTarget(self, action: #selector(buttonWasTapped), for: .touchUpInside)
|
2017-03-13 12:07:19 -07:00
|
|
|
button.configureLayout { (layout) in
|
|
|
|
layout.isEnabled = true
|
|
|
|
layout.height = 300
|
|
|
|
layout.width = 300
|
|
|
|
layout.alignSelf = .center
|
|
|
|
}
|
2017-02-13 09:05:22 -08:00
|
|
|
root.addSubview(button)
|
|
|
|
|
|
|
|
root.yoga.applyLayout(preservingOrigin: false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK - UIButton Action
|
2023-06-05 22:18:39 -07:00
|
|
|
@objc func buttonWasTapped() {
|
2017-02-13 09:05:22 -08:00
|
|
|
button.isSelected = !button.isSelected
|
|
|
|
|
|
|
|
button.isUserInteractionEnabled = false
|
|
|
|
disappearingView.yoga.isIncludedInLayout = !disappearingView.yoga.isIncludedInLayout
|
|
|
|
disappearingView.isHidden = !disappearingView.isHidden
|
|
|
|
|
|
|
|
contentView.yoga.applyLayout(preservingOrigin: true)
|
|
|
|
button.isUserInteractionEnabled = true
|
|
|
|
}
|
|
|
|
}
|