Skip to content

Instantly share code, notes, and snippets.

View factoryhr's full-sized avatar

Factory.dev factoryhr

View GitHub Profile
protocol CustomCollectionViewDelegate: UICollectionViewDelegate{
func collectionView(sectionPosition collectionView: UICollectionView, for indexPath: IndexPath) -> CollectionPosition
}
// MARK: CustomLayoutInvalidationContext
class CustomLayoutInvalidationContext: UICollectionViewLayoutInvalidationContext {
var invalidatedBecauseOfBoundsChange: Bool = false
}
// MARK: CustomCollectionViewLayout
class CustomCollectionViewLayout: UICollectionViewLayout {
private enum ContentUpdateValue{
case fixed(value: CGFloat)
class CustomLayoutInvalidationContext: UICollectionViewLayoutInvalidationContext {
var invalidatedBecauseOfBoundsChange: Bool = false
}
override func invalidateLayout(with context: UICollectionViewLayoutInvalidationContext) {
let invalidationContext = context as! CustomLayoutInvalidationContext
if invalidationContext.invalidatedBecauseOfBoundsChange || invalidationContext.invalidateEverything {
layoutAttributesForItems.removeAll()
}
super.invalidateLayout(with: invalidationContext)
}
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
var visibleLayoutAttributes: [UICollectionViewLayoutAttributes] = []
for attributes in layoutAttributesForItems.values {
if attributes.frame.intersects(rect) {
visibleLayoutAttributes.append(attributes)
}
}
return visibleLayoutAttributes
}
override func prepare(){
//Here we calculate all the dimensions we need for our collection view
//Stuff like item height, item width and collection view size
//We create x and y offsets for our items based on their collection position
//Also we create layout attributes for each item inside our collection view
//Layout attributes are cached so we wouldn’t need to recalculate them
//every time attribute is requested
}
enum Item{
case title(title: String)
case image(image: String)
case button(button: String)
case details(details: String)
case relatedProduct(relatedProduct: String)
var preferedPosition: CollectionPosition{
switch self {
case .details:
enum CollectionPosition {
case start
case end
case inline
}
<?php
/**
* @var \Pimcore\Templating\PhpEngine $this
* @var \Pimcore\Templating\PhpEngine $view
* @var \Pimcore\Templating\GlobalVariables $app
*/
$this->extend('layout.html.php');
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Pimcore\Model\DataObject\Brand;
use Pimcore\Model\DataObject\Product;
class BrandController extends AbstractController
{
/**
* @Route("/en/brandpages/{id}", name="brand")
*/