component-driven uis - mobile era 2016

27
@JOHNSUNDELL BUILDING COMPONENT-DRIVEN UIS John Sundell Lead iOS Developer, Spotify

Upload: john-sundell

Post on 08-Jan-2017

282 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Component-driven UIs - Mobile Era 2016

@JOHNSUNDELL

BUILDING COMPONENT-DRIVEN UIS

John Sundell Lead iOS Developer, Spotify

Page 2: Component-driven UIs - Mobile Era 2016

! "

Page 3: Component-driven UIs - Mobile Era 2016

! "#

CocoaPods/Carthage

Fastlane

Swift

Protocol oriented programming

Model-View-ViewModel

Promises / Operations / Rx

Page 4: Component-driven UIs - Mobile Era 2016

UI

Page 5: Component-driven UIs - Mobile Era 2016
Page 6: Component-driven UIs - Mobile Era 2016

// MARK: - UITableViewDataSource func numberOfSections(in tableView: UITableView) -> Int { return 2 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { if section == 0 { return model.unreadMessages.count } return model.readMessages.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "message", for: indexPath) let message: Message if indexPath.section == 0 { message = model.unreadMessages[indexPath.row] } else { message = model.readMessages[indexPath.row] } cell.textLabel?.text = message.subject cell.detailTextLabel?.text = "From: \(message.sender)" return cell }

Page 7: Component-driven UIs - Mobile Era 2016

UITableViewDelegate

UITableViewDataSource

Caching

UIViewController subclass

JSON parsing

Integrate view controller with the rest of the app

Setup UITableView

Register UITableViewCell classUITableViewCell subclass

Handle network errors

Handle slow connections

OfflinePerform HTTP request

View Model

City Model

BACKEND

Page 8: Component-driven UIs - Mobile Era 2016
Page 9: Component-driven UIs - Mobile Era 2016
Page 10: Component-driven UIs - Mobile Era 2016

Render state

[ Image(“Tokyo”), Image(“Gothenburg”), Row(“Berlin”, “Germany”), Row(“Beijing”, “China”), Row(“Paris”, “France”), Row(“San Francisco”, “USA”), User(“Julia”), User(“Mathew”), User(“Caroline”), User(“David”), Row(“Athens”, “Greece”), Row(“Oslo”, “Norway”), Row(“Stockholm”, “Sweden”)

]

Page 11: Component-driven UIs - Mobile Era 2016

UI = fn(state)

Page 12: Component-driven UIs - Mobile Era 2016
Page 13: Component-driven UIs - Mobile Era 2016

1. SHARED DATA MODEL

Page 14: Component-driven UIs - Mobile Era 2016

struct Image { var url: URL }

struct City { var name: String var country: String }struct User {

var name: String var imageUrl: URL }

Page 15: Component-driven UIs - Mobile Era 2016

ComponentModel

ComponentModel

ComponentModel

ViewModel

Page 16: Component-driven UIs - Mobile Era 2016

struct { var title: String var subtitle: String var imageUrl: URL ... }

ComponentModel

Page 17: Component-driven UIs - Mobile Era 2016

2. PROTOCOL-ORIENTED VIEWS

Page 18: Component-driven UIs - Mobile Era 2016

Components

UICollectionView

protocol Component {var view: UIView? { get }

func loadView()

}func configure(withModel: ComponentModel)

var preferredViewSize: CGSize { get }var layoutTraits: [LayoutTrait] { get }

UICollectionViewLayout

Page 19: Component-driven UIs - Mobile Era 2016

3. A DECLARATIVE API

Page 20: Component-driven UIs - Mobile Era 2016

$

Logic to load content Respond to Interactions

COMPONENTSCOMPONENT

MODELS

Page 21: Component-driven UIs - Mobile Era 2016

CONTENT OPERATIONSViewModelBuilder Content

BACKEND

MODELS

Page 22: Component-driven UIs - Mobile Era 2016

COMPONENTSCOMPONENT

MODELSCONTENT

OPERATIONS

DECLARERENDER

Page 23: Component-driven UIs - Mobile Era 2016

1. SHARED DATA MODEL

2. PROTOCOL-ORIENTED VIEWS

3. A DECLARATIVE API

Page 24: Component-driven UIs - Mobile Era 2016

THE HUB FRAMEWORK

Page 25: Component-driven UIs - Mobile Era 2016

DEMO

Page 26: Component-driven UIs - Mobile Era 2016

OPEN SOURCE! %

Page 27: Component-driven UIs - Mobile Era 2016

GITHUB.COM/JOHNSUNDELL

@JOHNSUNDELL