-
Notifications
You must be signed in to change notification settings - Fork 98
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
Usage for UI components library #79
Comments
Absolutely yes - Render is designed to be stack-agnostic. It can be used within other view that utilize autolayout and it can wrap views that uses autolayout. |
Yes, I encountered an issue with size. I have autolayout setup the size of the component view to 200x300, but when I use |
If you can provide a workable example I can try to fix it :) |
Here it is, sir :) import Foundation
import Render
public class TestComponentView: StatelessComponentView {
override public func render() -> NodeType {
let container = Node<UIView> { view, layout, size in
layout.width = size.width
layout.height = size.height
layout.padding = 10
view.backgroundColor = .red
}
container.add(child: Node<UIView>{ view, layout, size in
layout.percent.width = 100%
layout.percent.height = 100%
view.backgroundColor = .blue
})
return container
}
} import UIKit
class DetailViewController: UIViewController {
func configureView() {
title = detailItem
}
override func loadView() {
super.loadView()
let test = TestComponentView()
test.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(test)
let cts = [
test.centerXAnchor.constraint(equalTo: view.centerXAnchor),
test.centerYAnchor.constraint(equalTo: view.centerYAnchor),
test.widthAnchor.constraint(equalToConstant: 200),
test.heightAnchor.constraint(equalToConstant: 250)
]
view.addConstraints(cts)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
configureView()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
var detailItem: String? {
didSet {
// Update the view.
configureView()
}
}
|
I think it will be hard to achieve with AutoLayout :/ |
I have added an example on how to use Render with autolayout managed view hierarchies. ` override func loadView() {
}` |
This is a solution but I'm working on something prettier! |
I see. However this will not work when you don't have specific constraints for height and width. You can have something like I am afraid that ComponentView is not usable for AutoLayout for now :( Maybe there should be an option to render withing current bounds? And call this whenever layoutSubviews is called? Somehow this must be possible to achieve. |
Ok - I've introduced
|
I was thinking of the same solution. What I don't like about this is that it wraps it yet in another UIView, the hierarchy becomes more complex and memory inefficient. |
I know, on the other hand an opaque, non-visible parent view is not a big overhead. |
I can optimize |
Maybe that would be worth the effort. However, still, I don't feel entirely cool about this. EDIT: actually the same issue would occur when you would use |
Hey,
I have a question regarding the usage of Render in UI framework for multiple apps. Is it possible to use stateless
ComponentViews
as usualUIViews
without a need to callupdate
?For example: if you setup autolayout constraints and the layout is calculated and new frames set, can the ComponentView actually automatically update it-self?
I want to have a collection of UI components/views/bits available in a separate framework and work with them as usual UIViews without the developer knowing it is actually Render based component. Even if he is going to use them with Render himself.
The text was updated successfully, but these errors were encountered: