Slide 1

Slide 1 text

Como implementar interfaces complexas e dinâmicas

Slide 2

Slide 2 text

Desenvolvedor iOS Bruno Bilescky @bgondim

Slide 3

Slide 3 text

Interfaces complexas e dinâmicas

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Página de detalhe do imóvel

Slide 9

Slide 9 text

Página de detalhe do imóvel Baseada em CollectionView Alguns blocos são visíveis apenas em algumas situações

Slide 10

Slide 10 text

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) } }

Slide 11

Slide 11 text

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) } }

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

if indexPath.row == 3 { let mapOrigin = currentVisibleFrameForCellAtIndexPath(indexPath, collectionView: collectionView) delegate?.showMapInFullScreen(mapOrigin) } func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

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)

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Como facilitar a manutenção dessa estrutura e reduzir o tempo de implementação dessa funcionalidade?

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Primeiro vamos separar em unidades cada um destes blocos

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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 }

Slide 25

Slide 25 text

Compose by

Slide 26

Slide 26 text

Separação de componentes em unidades

Slide 27

Slide 27 text

Separação de componentes em unidades Cada unidade é responsável por exibir e configurar uma View.

Slide 28

Slide 28 text

Separação de componentes em unidades Como cada View é implementada fica a critério do Desenvolvedor

Slide 29

Slide 29 text

Separação de componentes em unidades Diversas formas de calcular a altura|largura da unidade

Slide 30

Slide 30 text

Separação de componentes em unidades Suporte para: UICollectionView UITableView

Slide 31

Slide 31 text

ComposingUnit

Slide 32

Slide 32 text

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)

Slide 33

Slide 33 text

ComposingUnit Struct ou Class Value Type ou Reference

Slide 34

Slide 34 text

ComposingUnit DimensionUnit Valores absolutos, percentual de altura|largura do container, total do container +|- valor fixo, lógica customizada (altura de textos)

Slide 35

Slide 35 text

ComposingContainer

Slide 36

Slide 36 text

ComposingContainer var direction: ComposingContainerDirection var state: [ComposingUnit]

Slide 37

Slide 37 text

ComposingContainer UICollectionView: ComposingCollectionView UITableView: ComposingTableView

Slide 38

Slide 38 text

ComposingContainer Suporte automático para [inserção|remoção|atualização] de ComposingUnits UICollectionView: ComposingCollectionView UITableView: ComposingTableView

Slide 39

Slide 39 text

ComposingContainer UICollectionView: ComposingCollectionView UITableView: ComposingTableView Suporte para diversos delegates como willDisplay, didDisplay, didSelect, canSelect, didHighlight através de Protocolos

Slide 40

Slide 40 text

Hands on

Slide 41

Slide 41 text

Tela utilizando Compose

Slide 42

Slide 42 text

Tela utilizando Compose

Slide 43

Slide 43 text

https://github.com/vivareal/compose (em breve)

Slide 44

Slide 44 text

Dúvidas? [email protected] @bgondim (twitter) @bbilescky (slack)

Slide 45

Slide 45 text

Obrigado!