Slide 1

Slide 1 text

SAM SOFFES AUGUST 15, 2018 Starting a mobile design system

Slide 2

Slide 2 text

Hi, I’m @soffes

Slide 3

Slide 3 text

Agenda • Mobile design system
 • Why
 • What we built • Tooling

Slide 4

Slide 4 text

Inspiration

Slide 5

Slide 5 text

Mobile design system

Slide 6

Slide 6 text

Our needs

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Scalable

Slide 10

Slide 10 text

Goals

Slide 11

Slide 11 text

Consistent & flexible

Slide 12

Slide 12 text

Native

Slide 13

Slide 13 text

Lyft Product Language

Slide 14

Slide 14 text

Attributes Components Templates Principles

Slide 15

Slide 15 text

C O L O R E L E V AT I O N I C O N O G R A P H Y T Y P O G R A P H Y I L L U S T R AT I O N A N I M AT I O N Yellow Red Indigo Purple Pink Rose Mint Green Lime Citron Amber Sunset Orange Teal Cyan Blue Ly 3 D C O P Y Attributes

Slide 16

Slide 16 text

B U T T O N S S E L E C T I O N C O N T R O L S T E X T F I E L D S Components

Slide 17

Slide 17 text

Templates A L E R T S S H E E T S

Slide 18

Slide 18 text

Single source of truth

Slide 19

Slide 19 text

Repo with JSON

Slide 20

Slide 20 text

{ "identifier": "typography", "title": "Typography", "comment": "Definitions for typography.", "documentation_url": "https://go.lyft.com/lpl-typography", "fontFamilies": [ { "identifier": "primary", "name": "ProximaNova", "weights": [ "regular", "medium", "bold" ] }, { "identifier": "secondary", "name": "LyftProUI", "weights": [ "bold" ]

Slide 21

Slide 21 text

Protocol buffers

Slide 22

Slide 22 text

syntax = "proto3"; // Lyft Product Language typography attribute message TypographyAttribute { // Font weights enum Weight { // Regular weight regular = 0; // Medium weight medium = 1; // Bold weight bold = 2; } message FontFamily { // Identifier (primary, secondary) string identifier = 1;

Slide 23

Slide 23 text

lpltool

Slide 24

Slide 24 text

Code generation

Slide 25

Slide 25 text

// ⚠ This file is generated. Do not edit. import UIKit /// Definitions for color. /// /// {{ documentation_url }} public struct Color { /// Underlying UIColor public let underlyingColor: UIColor /// Initialize a color /// /// - parameter red: P3 red component

Slide 26

Slide 26 text

{% for group in spectrum %} /// {{ group.title }} extension Color { {% for color in group.colors %} /// {{ color|hex }} public static let {{ color.identifier }} = Color(red: {{ color.red|tff }}, green: {{ color.green|tff }}, blue: {{ color.blue|tff }}) {% endfor %}}{% endfor %}

Slide 27

Slide 27 text

Enables other tooling

Slide 28

Slide 28 text

$ lpltool Commands: + generate - Generate code from an attribute and template + generate-icon-asset-catalog - Generate icons from SVG to an asset catalog + nearest-color - Find the nearest spectrum color for a given color + lint-ib-colors - Lint all colors found in Interface Builder files + snap-ib-colors - Snap all colors found in Interface Builder files to defined color spectrum

Slide 29

Slide 29 text

Closer look

Slide 30

Slide 30 text

Color

Slide 31

Slide 31 text

public struct Color { public let underlyingColor: UIColor private init(red: CGFloat, green: CGFloat, blue: CGFloat) { self.underlyingColor = UIColor( displayP3Red: red, green: green, blue: blue, alpha: 1) } }

Slide 32

Slide 32 text

/// Brand extension Color { /// #FF00BF public static let lyftPink = Color(red: 1, green: 0, blue: 0.749) } /// Red extension Color { /// #FFFAFB public static let red0 = Color(red: 1, green: 0.98, blue: 0.984) /// #FFE5E9

Slide 33

Slide 33 text

Control

Slide 34

Slide 34 text

Accessibility

Slide 35

Slide 35 text

var traits = self.baseAccessibilityTraits if self.isSelected { traits = traits | UIAccessibilityTraitSelected } if !self.isEnabled || self.isLoading { traits = traits | UIAccessibilityTraitNotEnable } self.accessibilityTraits = traits

Slide 36

Slide 36 text

var accessibilityPathCornerRadius: CGFloat?

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Greedy touch handling

Slide 39

Slide 39 text

func point(inside point: CGPoint, with event: UIEvent?) -> Bool

Slide 40

Slide 40 text

func gestureRecognizerShouldBegin( _ gestureRecognizer: UIGestureRecognizer) -> Bool

Slide 41

Slide 41 text

Button

Slide 42

Slide 42 text

Control instead of UIButton

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

Two view models

Slide 46

Slide 46 text

extension Button { public struct Size { public var font: UIFont public var height: CGFloat public var activityIndicatorSize: ActivityIndicatorView.Size } }

Slide 47

Slide 47 text

extension Button { public struct Style { public var text: Color public var disabledText: Color public var background: Color public var touchDownBackground: Color public var disabledBackground: Color public var border: Border? public var loadingIndicator: Color public var hasRoundedCorners: Bool public var isElevated: Bool } }

Slide 48

Slide 48 text

extension Button.Style { public static let primary = Button.Style( text: .white, background: .purple60, touchDownBackground: .purple80, disabledBackground: .purple30) public static let primaryElevated: Button.Style = { var style = Button.Style.primary style.isElevated = true return style }()

Slide 49

Slide 49 text

Composable

Slide 50

Slide 50 text

Button(size: .small, style: .primary)

Slide 51

Slide 51 text

Consistency & flexibility

Slide 52

Slide 52 text

private extension Button.Size { static let verySmall = Button.Size( font: .primaryFont(ofSize: 15, weight: .bold), height: 40, activityIndicatorSize: .small) }

Slide 53

Slide 53 text

State Animator

Slide 54

Slide 54 text

public protocol StateAnimator { associatedtype State: Hashable var pacing: Pacing { get } var curve: Curve { get } func set(_ state: State, animated isAnimated: Bool) }

Slide 55

Slide 55 text

let animator = ViewStateAnimator(view: self) animator.set(.identity, for: \.transform, when: .normal) animator.set(.elevatedTouchDownScale, for: \.transform, when: .touchDown)

Slide 56

Slide 56 text

let animator = LayerStateAnimator(layer: self.backgroundLayer) animator.set(fillColor: .purple60, when: .normal) animator.set(fillColor: .purple80, when: .touchDown) animator.set(shadow: .level2, when: .normal) animator.set(shadow: nil, when: .touchDown, .loading)

Slide 57

Slide 57 text

self.animator.set(self.componentState, animated: true)

Slide 58

Slide 58 text

Paradigm

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

Easier than we thought

Slide 61

Slide 61 text

Just UIKit

Slide 62

Slide 62 text

Tools are just apps

Slide 63

Slide 63 text

Start small

Slide 64

Slide 64 text

Thank you AUGUST 15, 2018