Comments (3)
This is expected. In this framework, there are two phases when rendering. One is the layout, second is rendering the views that are on screen.
The component view will first layout the entire component tree, then only create the views that are on screen. This makes it fast just like a UICollectionView where even if you have 100000 cell, it will still only display the ones that user scrolls to.
SimpleViewComponent
by default, doesn't initialize a view for it to get its size. If you imagine having 100,000 of these in your feed, if each SimpleViewComponent
initialize a view to retrieve its size, it is going to take a lot of memory and be very slow to initialize. So normally you will have to supply a size via the .size()
modifier, or do your own size calculation by writing your own component.
SimpleViewComponent<UIButton>().update {
$0.setTitle("button", for: .normal)
$0.setTitleColor(.systemBlue, for: .normal)
}.backgroundColor(.brown).size(CGSize(width:100, height:44))
However, if you don't update your feed frequently, or if you only have a few of these views. You can directly create a view and pass it into the SimpleViewComponent like so:
let button = UIButton()
button.setTitle("button", for: .normal)
button.setTitleColor(.systemBlue, for: .normal)
SimpleViewComponent(view: button)
This way, the SimpleViewComponent
has a view to retrieve the size from, and you will get the correct layout.
And did you know? all UIView
are compatible to be used as a ViewComponent
.
So what I do normally if I have a few views that I would like to display in a componentView is the following:
class ViewController: UIViewController {
let button = UIButton()
// ...
func viewDidLoad() {
super.viewDidLoad()
button.setTitle("button", for: .normal)
button.setTitleColor(.systemBlue, for: .normal)
componentView.component = VStack {
// ...
button // <- notice that I can directly put the button inside any layout component, this will turn it into a SimpleViewComponent automatically
}
}
from uicomponent.
If you are going to build a scrolling feed of these cells, you should create your own component for your cells. You can check out the Card examples or the Text
or Image
component to see how the size is calculated during a layout cycle if you plan to implement your own Component.
from uicomponent.
This is awesome and very helpful to me
from uicomponent.
Related Issues (16)
- Deleted
- ViewComponent enhancement HOT 2
- HStack has bug HOT 1
- Use background modifier Issue HOT 3
- Podspec missing Dependency `BaseToolbox` HOT 3
- Cooperate with `IQKeyboardManager` `ComponentScrollView` to display unusual HOT 1
- Support `SwipeActions` HOT 1
- Is this component compatible with IOS 11? HOT 12
- State Binding
- Support sticky view? HOT 1
- Can you make the internally used Then framework private or prefixed so that it is not exposed externally HOT 1
- How to hide an existing view element?
- Is it possible to have a drag and drop example?
- Consider compatibility with macOS
- Support RTL?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uicomponent.