Comments (6)
UICollectionView works a bit differently from UITableView - you need to register a class for a reuse idenfier:
collectionView.registerClass(ComponentCollectionViewCell<MyComponent>.self, forCellWithReuseIdentifier: CellPrototype.defaultIdentifier(MyComponent.self))
Also check out Buffer - it has built-in table and collection view adapters that work great with Render.
from render.
Thanks! it works. I tried with Buffer and wanted to know. Can i create a sub state and send it into Buffer in my app?
from render.
from render.
ok. I will try to use it again. Do you know how you can create collection view cell on full screen? currently i am trying to do it but it is only fixed size?
from render.
You can set the width and the height of the cell to the size parameter passed in the closure.
from render.
Hi Ran or Alex,
I'm trying to setup a collection view component and I was looking at the code snippets above trying to piece one together, but I'm still having trouble. I'm not sure what the issue is. The collection view draws to screen, but neither of my data source methods are called and no cells are rendered. I'm trying to do this purely in code so not using storyboards for either the collection view or cell prototype. Here is the code I have so far:
import Foundation
import UIKit
import Render
struct CollectionState: StateType {
var id: String = "collectionContainer"
var elements: [NodeType] = [layoutBuilder("")]
var layoutAs: String = "flow"
var direction: String = "vertical"
}
class CollectionContainer: ComponentView<CollectionState>, UICollectionViewDataSource, UICollectionViewDelegate {
var collectionView: UICollectionView?
required init() {
super.init()
//self.defaultOptions = [.preventViewHierarchyDiff]
}
required init?(coder aDecoder: NSCoder) {
fatalError("Not supported")
}
override func render() -> NodeType {
// A container view that wraps it's contents
func layoutContainer() -> NodeType {
return Node<UICollectionView>(
create: {[weak self] in
let layout = UICollectionViewFlowLayout()
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.register(ComponentCollectionViewCell.self, forCellWithReuseIdentifier: CellComponent.reuseIdentifier)
collectionView.dataSource = self
collectionView.delegate = self
collectionView.backgroundColor = UIColor.blue
collectionView.isPagingEnabled = true
collectionView.showsHorizontalScrollIndicator = false
collectionView.showsVerticalScrollIndicator = false
collectionView.alwaysBounceHorizontal = true
self?.collectionView = collectionView
return collectionView
},
configure: {(collection,layout,size) in
layout.alignSelf = .stretch
layout.width = size.width
layout.height = size.height
configs[self.state.layoutAs]!(layout)
configs[self.state.direction]!(layout)
}
)}
return layoutContainer()
}
// tell the collection view how many cells to make
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print("Count")
return state.elements.count
}
// make a cell for each cell index path
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let id = CellComponent.reuseIdentifier
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: id, for: indexPath)
if let cell = cell as? ComponentCollectionViewCell {
cell.mountComponentIfNecessary(CellComponent())
cell.set(state: CellState(node: self.state.elements[indexPath.row]))
print("Add Cells")
cell.update(options: [])
}
return cell
}
}
from render.
Related Issues (20)
- What happened to ComponentCollectionViewCell? HOT 1
- Classic Version does not compile on clean CocoaPods install HOT 2
- No control over a ComponentView's contentView HOT 1
- UICollectionView support? HOT 2
- Updating a panning view fails to HOT 4
- RenderNeutrino issue with cacaopod headers(device) HOT 1
- Question: why is .flexibleHeight a default for non-scrolling UIComponentViewControllers? HOT 2
- Question: optimisation of the render cycle for stateless components HOT 3
- Carthage support broken since version 5.2
- AppKit Support? HOT 3
- Struct vs Class for UIProps/UIState HOT 1
- Use of _kvcKeyPathString for the identifier in AnyKeyPath extension HOT 2
- REQUEST: Simple Example of how to use CollectionViews with Render Neutrino?
- Write documentation.
- Is Render cross-platform?
- Build List component.
- Ensure RenderInspector works with Neutrino.
- Build more examples in the catalog.
- Port Documentation. HOT 5
- Neutrino: table component layout performance HOT 5
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 render.