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
How to show hide Section with UICollectionView? #2
Comments
Hi @arimunandar , Can you take me a sample code? // call on main thread
renderer.render(
Section(
id: "id value"
header: ViewNode(Sample()),
cells: [
CellNode(Sample()),
CellNode(Sample())
]
footer: ViewNode(Sample()),
)
)
// ↓↓↓ Call again to hide Section ↓↓↓
renderer.render() // renderer.data = [], renderer.render([]) Moreover, you can handle show or hide section using Bool flag as state. var hidesSection: Bool = false {
didSet { render() }
}
func render() {
renderer.render(
hidesSection ? nil : Section(
id: "id value"
header: ViewNode(Sample()),
cells: [
CellNode(Sample()),
CellNode(Sample())
]
footer: ViewNode(Sample()),
)
)
} And, Example app may be helps you! |
Hi @ra1028 , thanks for your answer, I have done it according to the example above, but when the components in hide always scroll back to the top. this is my code example: var isHide: Bool = true {
didSet { render() }
}
override func viewDidLoad() {
super.viewDidLoad()
title = "Kyoto"
collectionView?.collectionViewLayout = layout
collectionView.contentInset.bottom = 24
renderer.updater.alwaysRenderVisibleComponents = false
renderer.updater.skipReloadComponents = false
render()
}
func render() {
renderer.render(
Section(
id: ID.top,
header: ViewNode(KyotoTop())
),
Section(
id: ID.gallery,
header: ViewNode(Header(title: "PHOTOS")),
cells: photo.enumerated().map({ _, data in
CellNode(KyotoImage(title: data.name, image: data.image, onSelected: {
self.isHide = false
}) {
self.isHide = true
})
}),
footer: !isHide ? nil : ViewNode(KyotoLicense {
let url = URL(string: "https://unsplash.com/")!
UIApplication.shared.open(url)
})
)
)
} there is something wrong with my code? thnks :) |
@arimunandar struct EmptyComponent: Component, Equatable {
var height: CGFloat
func renderContent() -> UIView {
return UIView()
}
func render(in view: UIView) {}
func referenceSize(in bounds: CGRect) -> CGSize? {
return CGSize(width: bounds.width, height: height)
}
} footer: !isHide ? ViewNode(EmptyComponent(height: placeholderHeight)) : ViewNode(KyotoLicense {
let url = URL(string: "https://unsplash.com/")!
UIApplication.shared.open(url)
}) |
I understood. In UIKit, to change the header or footer we should to reload section. var isHide: Bool = true {
didSet { render() }
}
override func viewDidLoad() {
super.viewDidLoad()
title = "Kyoto"
collectionView?.collectionViewLayout = layout
collectionView.contentInset.bottom = 24
renderer.updater.alwaysRenderVisibleComponents = false // It's default.
renderer.updater.skipReloadComponents = false // It's default.
render()
}
func render() {
renderer.render(
Section(
id: ID.top,
header: ViewNode(KyotoTop())
),
Section(
id: ID.gallery,
header: ViewNode(Header(title: "PHOTOS")),
cells: photo.enumerated().map({ _, data in
CellNode(KyotoImage(title: data.name, image: data.image, onSelected: {
self.isHide = false // You should `weak self`.
}) {
self.isHide = true
})
})
),
Section(
id: ID.footer,
footer: !isHide ? nil : ViewNode(KyotoLicense {
let url = URL(string: "https://unsplash.com/")!
UIApplication.shared.open(url)
})
)
} |
Did you solve this? |
i'm trying to show hide section with UICollectionView, but every rendering component its like ugly animation, how to implement show hide with UICollectionView?
Thanks for helping :)
The text was updated successfully, but these errors were encountered: