$30 off During Our Annual Pro Sale. View Details »

Compose - Interfaces complexas e dinâmicas

Compose - Interfaces complexas e dinâmicas

Palestra do 26º CocoaheadsSP. Nesta palestra apresentamos sobre como estamos resolvendo o problema de interfaces complexas e dinâmicas no VivaReal. Também anunciamos que vamos deixar nossa solução open source

Bruno Bilescky

October 25, 2016
Tweet

Other Decks in Technology

Transcript

  1. Página de detalhe do imóvel Baseada em CollectionView Alguns blocos

    são visíveis apenas em algumas situações
  2. func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell switch indexPath.row

    { case 0: return pictureCell(collectionView, atIndexPath: indexPath) case 1: return contactStatusCell(collectionView, atIndexPath: indexPath) case 2: return infosCell(collectionView, atIndexPath: indexPath) case 3: return mapsCell(collectionView, atIndexPath: indexPath) case 4: if self.userPlaces.count > 0 { return userPlacesCell(collectionView, atIndexPath: indexPath) } else { return emptyUserPlacesCell(collectionView, atIndexPath: indexPath) } }
  3. func collectionView(collectionView:UICollectionView, heightForItemAtIndexPath indexPath:NSIndexPath, withWidth:CGFloat) -> CGFloat switch atIndex.row {

    case 0: return CGSizeMake(collectionViewWidth, 232) case 1: if property.contactInfo != nil { return CGSizeMake(collectionViewWidth, 48) } else { return CGSizeZero } case 2: return CGSizeMake(collectionViewWidth, 227) case 3: return CGSizeMake(collectionViewWidth, 230) case 4: if userPlaces.count > 0 { return CGSizeMake(collectionViewWidth, 130+CGFloat(userPlaces.count*72)) } else { return CGSizeMake(collectionViewWidth, 178.0) } }
  4. let collectionViewLayout: CollectionViewLayout = collectionView.collectionViewLayout as! CollectionViewLayout let bigInterface =

    isBigInterface(collectionView) if ! bigInterface || collectionViewLayout.numberOfColumns == 1 { return property.isNewDevelopment ? 9 : 10 } else { return property.isNewDevelopment ? 7 : 8 } func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
  5. if indexPath.row == 3 { let mapOrigin = currentVisibleFrameForCellAtIndexPath(indexPath, collectionView:

    collectionView) delegate?.showMapInFullScreen(mapOrigin) } func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
  6. func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int func collectionView(collectionView:

    UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
  7. func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int func collectionView(collectionView:

    UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) X
  8. Como facilitar a manutenção dessa estrutura e reduzir o tempo

    de implementação dessa funcionalidade?
  9. Primeiro vamos separar em unidades cada um destes blocos Cada

    unidade irá conter todas as informações necessárias para exibir este bloco
  10. Primeiro vamos separar em unidades cada um destes blocos Cada

    unidade irá conter todas as informações necessárias para exibir este bloco A Collection então deverá exibir uma lista de unidades
  11. let contactInfo: String? = "teste" let myPlaces: [String] = ["Place1","Place2","Place3"]

    var units: [ComposingUnit] = [] units.add { let header = HeaderUnit() let descUnit = DescriptionUnit() return [header, descUnit] } units.add(ifLet: contactInfo) { info in let unit = ContactInfoUnit(info: info) return unit } units.add(if: myPlaces.count > 0) { let unit = MyPlacesUnit(places: myPlaces) return unit }
  12. ComposingUnit var identifier: String var heightUnit: DimensionUnit var widthUnit: DimensionUnit

    func configure(view: UIView) func reuseIdentifier()-> String func register(in collectionView: UICollectionView) func register(in tableView: UITableView)
  13. ComposingUnit DimensionUnit Valores absolutos, percentual de altura|largura do container, total

    do container +|- valor fixo, lógica customizada (altura de textos)