Slide 1

Slide 1 text

೥ؒӡ༻͞Εͯ දࣔ଎౓͕௿Լͨ͠ৄࡉը໘Λ վળ͢ΔաఔͰಘͨ஌ݟ by marty-suzuki / @marty_suzuki iOSDC Japan 2020

Slide 2

Slide 2 text

marty_suzuki CyberAgent, Inc. marty-suzuki Taiki Suzuki

Slide 3

Slide 3 text

ͲΜͳৄࡉը໘ͳͷ͔Λ ؆қతʹ঺հ

Slide 4

Slide 4 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ ίϯςϯπͷαϜωΠϧ

Slide 5

Slide 5 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ λΠτϧ΍ࢹௌظݶͳͲ

Slide 6

Slide 6 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ ֤छΞΫγϣϯϘλϯ

Slide 7

Slide 7 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ ίϯςϯπʹඥͮ͘ΤϐιʔυҰཡ

Slide 8

Slide 8 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ Ϩίϝϯυ͞ΕΔίϯςϯπҰཡ

Slide 9

Slide 9 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ λοϓ͢Δ

Slide 10

Slide 10 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ ৄࡉ৘ใ Ωϟετ ελοϑ ޿͕ͬͯৄࡉ৘ใදࣔ

Slide 11

Slide 11 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ ը໘ճస͢Δ

Slide 12

Slide 12 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ

Slide 13

Slide 13 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ

Slide 14

Slide 14 text

Y ΤϐιʔυҰཡ J ΦεεϝͷΤϐιʔυ ΋ͬͱΈΔʼ ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ ϑϧεΫϦʔϯ ίϯςϯπ͕ࢹௌՄೳͳ৔߹

Slide 15

Slide 15 text

Y ΤϐιʔυҰཡ J ΦεεϝͷΤϐιʔυ ΋ͬͱΈΔʼ ্ʹҾ্͖͛Δ

Slide 16

Slide 16 text

Y ΤϐιʔυҰཡ J Ϩίϝϯυදࣔ ΦεεϝͷΤϐιʔυ ΋ͬͱΈΔʼ

Slide 17

Slide 17 text

Y ΤϐιʔυҰཡ J ΦεεϝͷΤϐιʔυ ΋ͬͱΈΔʼ λοϓ͢Δ

Slide 18

Slide 18 text

Y ΤϐιʔυҰཡ J ΦεεϝͷΤϐιʔυ ΋ͬͱΈΔʼ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ ίϯςϯπʹඥͮ͘ΤϐιʔυҰཡ

Slide 19

Slide 19 text

Y ΤϐιʔυҰཡ J ΦεεϝͷΤϐιʔυ ΋ͬͱΈΔʼ γʔΫ͢Δ

Slide 20

Slide 20 text

Y ΤϐιʔυҰཡ J ΦεεϝͷΤϐιʔυ ΋ͬͱΈΔʼ γʔϯαϜωΠϧΛදࣔ

Slide 21

Slide 21 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ View͕ݟ͍͑ͯΔ෦෼Ҏ্ʹଟ͍ը໘

Slide 22

Slide 22 text

ը໘දࣔͷվળ

Slide 23

Slide 23 text

AppStore൛ iPhone6s iOS11 AppStore൛ iPhone8 iOS12

Slide 24

Slide 24 text

දࣔ଎౓ վળલ iPhone XS Max iOS13 iPhone 8 iOS12 ॳճ 1360ms 2100ms ճ໨Ҏ߱ 760ms 1180ms

Slide 25

Slide 25 text

ը໘දࣔ଎౓Λ ͲͷΑ͏ʹܭଌ͔ͨ͠

Slide 26

Slide 26 text

class VideoFullscreenViewController: UIViewController { init() { super.init(nibName: nil, bundle: nil) } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) } } init͔ΒviewDidAppear·ͰΛը໘͕දࣔ͞Ε·Ͱͱఆٛ

Slide 27

Slide 27 text

import os.signpost class VideoFullscreenViewController: UIViewController { let osLog: OSLog init() { self.osLog = OSLog(subsystem: "jp.co.marty-suzuki", category: .pointsOfInterest) os_signpost(.begin, log: osLog, name: "viewDidAppear Measurement") super.init(nibName: nil, bundle: nil) } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) os_signpost(.end, log: osLog, name: "viewDidAppear Measurement") } }

Slide 28

Slide 28 text

import os.signpost class VideoFullscreenViewController: UIViewController { let osLog: OSLog init() { self.osLog = OSLog(subsystem: "jp.co.marty-suzuki", category: .pointsOfInterest) os_signpost(.begin, log: osLog, name: "viewDidAppear Measurement") super.init(nibName: nil, bundle: nil) } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) os_signpost(.end, log: osLog, name: "viewDidAppear Measurement") } }

Slide 29

Slide 29 text

import os.signpost class VideoFullscreenViewController: UIViewController { let osLog: OSLog init() { self.osLog = OSLog(subsystem: "jp.co.marty-suzuki", category: .pointsOfInterest) os_signpost(.begin, log: osLog, name: "viewDidAppear Measurement") super.init(nibName: nil, bundle: nil) } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) os_signpost(.end, log: osLog, name: "viewDidAppear Measurement") } }

Slide 30

Slide 30 text

import os.signpost class VideoFullscreenViewController: UIViewController { let osLog: OSLog init() { self.osLog = OSLog(subsystem: "jp.co.marty-suzuki", category: .pointsOfInterest) os_signpost(.begin, log: osLog, name: "viewDidAppear Measurement") super.init(nibName: nil, bundle: nil) } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) os_signpost(.end, log: osLog, name: "viewDidAppear Measurement") } }

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

init͔ΒviewDidAppear·Ͱͷ଎౓ΛՄࢹԽ

Slide 33

Slide 33 text

Ͳ͏͍͏ը໘ߏ੒͔ͩͬͨ

Slide 34

Slide 34 text

VideoPlayerViewController ɾಈըͷ࠶ੜશൠ

Slide 35

Slide 35 text

DetailViewController ɾίϯςϯπͷৄࡉ৘ใදࣔ

Slide 36

Slide 36 text

VideoFullscreenViewController ɾ%FUBJMͱ7JEFP1MBZFSͷ఻ୡ ɾUSBOTJUJPOͷॲཧ

Slide 37

Slide 37 text

class VideoFullscreenViewController: UINavigationController { private let detailViewController: DetailViewController private let videoPlayerViewController: VideoPlayerViewController init() { self.detailViewController = DetailViewController() self.videoPlayerViewController = detailViewController.videoPlayerViewController super.init(nibName: nil, bundle: nil) setViewControllers([detailViewController], animated: false) } override func viewDidLoad() { super.viewDidLoad() detailViewController.loadViewIfNeeded() videoPlayerViewController.setup(completion: { ... }) } } class DetailViewController: UIViewController { private lazy var videoPlayerViewController = VideoPlayerViewController(...) private lazy var viewModel = DetailViewModel() override func viewDidLoad() { super.viewDidLoad() addChild(videoPlayerViewController) view.addSubview(videoPlayerViewController.view) videoPlayerViewController.didMove(toParent: self) } } class VideoPlayerViewController: UIViewController { private(set) lazy var videoPlayerView = VideoPlayerView() private(set) lazy var videoPlayerViewModel = VideoPlayerViewModel() }

Slide 38

Slide 38 text

class VideoFullscreenViewController: UINavigationController { private let detailViewController: DetailViewController private let videoPlayerViewController: VideoPlayerViewController init() { self.detailViewController = DetailViewController() self.videoPlayerViewController = detailViewController.videoPlayerViewController super.init(nibName: nil, bundle: nil) setViewControllers([detailViewController], animated: false) } override func viewDidLoad() { super.viewDidLoad() detailViewController.loadViewIfNeeded() videoPlayerViewController.setup(completion: { ... }) } } class DetailViewController: UIViewController { private lazy var videoPlayerViewController = VideoPlayerViewController(...) private lazy var viewModel = DetailViewModel() override func viewDidLoad() { super.viewDidLoad() addChild(videoPlayerViewController) view.addSubview(videoPlayerViewController.view) videoPlayerViewController.didMove(toParent: self) } } class VideoPlayerViewController: UIViewController { private(set) lazy var videoPlayerView = VideoPlayerView() private(set) lazy var videoPlayerViewModel = VideoPlayerViewModel() }

Slide 39

Slide 39 text

class VideoFullscreenViewController: UINavigationController { private let detailViewController: DetailViewController private let videoPlayerViewController: VideoPlayerViewController init() { self.detailViewController = DetailViewController() self.videoPlayerViewController = detailViewController.videoPlayerViewController super.init(nibName: nil, bundle: nil) setViewControllers([detailViewController], animated: false) } override func viewDidLoad() { super.viewDidLoad() detailViewController.loadViewIfNeeded() videoPlayerViewController.setup(completion: { ... }) } } class DetailViewController: UIViewController { private lazy var videoPlayerViewController = VideoPlayerViewController(...) private lazy var viewModel = DetailViewModel() override func viewDidLoad() { super.viewDidLoad() addChild(videoPlayerViewController) view.addSubview(videoPlayerViewController.view) videoPlayerViewController.didMove(toParent: self) } } class VideoPlayerViewController: UIViewController { private(set) lazy var videoPlayerView = VideoPlayerView() private(set) lazy var videoPlayerViewModel = VideoPlayerViewModel() }

Slide 40

Slide 40 text

class VideoFullscreenViewController: UINavigationController { private let detailViewController: DetailViewController private let videoPlayerViewController: VideoPlayerViewController init() { self.detailViewController = DetailViewController() self.videoPlayerViewController = detailViewController.videoPlayerViewController super.init(nibName: nil, bundle: nil) setViewControllers([detailViewController], animated: false) } override func viewDidLoad() { super.viewDidLoad() detailViewController.loadViewIfNeeded() videoPlayerViewController.setup(completion: { ... }) } } class DetailViewController: UIViewController { private lazy var videoPlayerViewController = VideoPlayerViewController(...) private lazy var viewModel = DetailViewModel() override func viewDidLoad() { super.viewDidLoad() addChild(videoPlayerViewController) view.addSubview(videoPlayerViewController.view) videoPlayerViewController.didMove(toParent: self) } } class VideoPlayerViewController: UIViewController { private(set) lazy var videoPlayerView = VideoPlayerView() private(set) lazy var videoPlayerViewModel = VideoPlayerViewModel() }

Slide 41

Slide 41 text

class VideoFullscreenViewController: UINavigationController { private let detailViewController: DetailViewController private let videoPlayerViewController: VideoPlayerViewController init() { self.detailViewController = DetailViewController() self.videoPlayerViewController = detailViewController.videoPlayerViewController super.init(nibName: nil, bundle: nil) setViewControllers([detailViewController], animated: false) } override func viewDidLoad() { super.viewDidLoad() detailViewController.loadViewIfNeeded() videoPlayerViewController.setup(completion: { ... }) } } class DetailViewController: UIViewController { private lazy var videoPlayerViewController = VideoPlayerViewController(...) private lazy var viewModel = DetailViewModel() override func viewDidLoad() { super.viewDidLoad() addChild(videoPlayerViewController) view.addSubview(videoPlayerViewController.view) videoPlayerViewController.didMove(toParent: self) } } class VideoPlayerViewController: UIViewController { private(set) lazy var videoPlayerView = VideoPlayerView() private(set) lazy var videoPlayerViewModel = VideoPlayerViewModel() }

Slide 42

Slide 42 text

class VideoFullscreenViewController: UINavigationController { private let detailViewController: DetailViewController private let videoPlayerViewController: VideoPlayerViewController init() { self.detailViewController = DetailViewController() self.videoPlayerViewController = detailViewController.videoPlayerViewController super.init(nibName: nil, bundle: nil) setViewControllers([detailViewController], animated: false) } override func viewDidLoad() { super.viewDidLoad() detailViewController.loadViewIfNeeded() videoPlayerViewController.setup(completion: { ... }) } } class DetailViewController: UIViewController { private lazy var videoPlayerViewController = VideoPlayerViewController(...) private lazy var viewModel = DetailViewModel() override func viewDidLoad() { super.viewDidLoad() addChild(videoPlayerViewController) view.addSubview(videoPlayerViewController.view) videoPlayerViewController.didMove(toParent: self) } } class VideoPlayerViewController: UIViewController { private(set) lazy var videoPlayerView = VideoPlayerView() private(set) lazy var videoPlayerViewModel = VideoPlayerViewModel() } wfunc setup(completion:)ͰvideoPlayerView΍ videoPlayerViewModelΛॳظԽͯ͠ϨΠΞ΢τ ॲཧΛ࣮ߦ͢Δ

Slide 43

Slide 43 text

ॳظ͸DetailViewControllerͷΈ͕ͩͬͨ ػೳ͕૿͑ΔʹͭΕͯViewController΋૿͑ͨ

Slide 44

Slide 44 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 45

Slide 45 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 46

Slide 46 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 47

Slide 47 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 48

Slide 48 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ ৄࡉ৘ใ Ωϟετ ελοϑ VideoPlayerViewController.view VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) }
 } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 49

Slide 49 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 50

Slide 50 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 51

Slide 51 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 52

Slide 52 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 53

Slide 53 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 54

Slide 54 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } } wUIScrollView಺ͷUIStackViewʹaddArrangedSubview͞Ε͍ͯΔͨΊ DPMMFDUJPO7JFX಺ͷDFMMΛ͢΂ͯඳը͍ͯ͠Δ wॳظ࣮૷౰ॳ͸݅·Ͱ͔͠දࣔ͠ͳ͍࢓༷ͩͬͨͷͰڐ༰Ͱ͖͕ͨ ͕࣌ܦͬͯमਖ਼લͷஈ֊Ͱ݅·ͰϨίϝϯυ͕දࣔ͞ΕΔΑ͏ʹͳ͍ͬͯͨ

Slide 55

Slide 55 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 56

Slide 56 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 57

Slide 57 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 58

Slide 58 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view HorizontalStackView { ThumbnailView ScrollView { VerticalStackView { SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 59

Slide 59 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view HorizontalStackView { ThumbnailView ScrollView { VerticalStackView { SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 60

Slide 60 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view HorizontalStackView { ThumbnailView ScrollView { VerticalStackView { SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 61

Slide 61 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view
 VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 62

Slide 62 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoPlayerViewController.view
 VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 63

Slide 63 text

දࣔΛ஗͍ͯͨ͘͠ ओͳཁҼ͸ʁ

Slide 64

Slide 64 text

දࣔ଎౓ վળલ iPhone XS Max iOS13 iPhone 8 iOS12 ॳճ 1360ms 2100ms ճ໨Ҏ߱ 760ms 1180ms ॳճͱճ໨Ҏ߱Ͱදࣔ଎౓ͷ͕ࠩ͋Δ

Slide 65

Slide 65 text

https://developer.apple.com/documentation/uikit/uinib A UINib object caches the contents of a nib file in memory, ready for unarchiving and instantiation. When your application needs to instantiate the contents of the nib file it can do so without having to load the data from the nib file first, improving performance. The UINib object can automatically release this cached nib data to free up memory for your application under low-memory conditions, reloading that data the next time your application instantiates the nib.

Slide 66

Slide 66 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VideoFullscreenViewController.VideoPlayerView (xib)
 VerticalStackView { ScrollView { VerticalStackView { ThumbnailView (xib) SummaryView (xib) { VerticalStackView { Label ContentInfoView (xib) } } OtherView (xib) { VerticalStackView { ActionButtonsView EpisodeListView (xib) } } RecommendView (xib) { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 67

Slide 67 text

protocol Nibable: AnyObject { associatedtype Instance static func makeFromNib() -> Instance static var nib: UINib { get } static var nibName: String { get } } extension Nibable { static func makeFromNib() -> Instance { let osLog = OSLog(subsystem: "jp.co.marty-suzuki", category: .pointsOfInterest) defer { os_signpost(.end, log: osLog, name: "makeFromNib Measurement", "%@", nibName) } os_signpost(.begin, log: osLog, name: "makeFromNib Measurement", "%@", nibName) return nib.instantiate(withOwner: nil, options: nil).first as! Instance } }

Slide 68

Slide 68 text

protocol Nibable: AnyObject { associatedtype Instance static func makeFromNib() -> Instance static var nib: UINib { get } static var nibName: String { get } } extension Nibable { static func makeFromNib() -> Instance { let osLog = OSLog(subsystem: "jp.co.marty-suzuki", category: .pointsOfInterest) defer { os_signpost(.end, log: osLog, name: "makeFromNib Measurement", "%@", nibName) } os_signpost(.begin, log: osLog, name: "makeFromNib Measurement", "%@", nibName) return nib.instantiate(withOwner: nil, options: nil).first as! Instance } }

Slide 69

Slide 69 text

protocol Nibable: AnyObject { associatedtype Instance static func makeFromNib() -> Instance static var nib: UINib { get } static var nibName: String { get } } extension Nibable { static func makeFromNib() -> Instance { let osLog = OSLog(subsystem: "jp.co.marty-suzuki", category: .pointsOfInterest) defer { os_signpost(.end, log: osLog, name: "makeFromNib Measurement", "%@", nibName) } os_signpost(.begin, log: osLog, name: "makeFromNib Measurement", "%@", nibName) return nib.instantiate(withOwner: nil, options: nil).first as! Instance } }

Slide 70

Slide 70 text

ॳظԽ࣌ؒ (iPhone8 iOS12) ॳճ 2ճ໨Ҏ߱ 7JEFP1MBZFS7JFX 394.11ms 124.37ms 5IVNCOBJM7JFX 5.97ms 1.27ms 4VNNBSZ7JFX 27.53ms 0.24ms $POUFOU*OGP7JFX 15.66ms 7.22ms 0UIFS7JFX 8.02ms 2.34ms &QJTPEF-JTU7JFX 14.25ms 6.29ms 3FDPNNFOE7JFX 13.90ms 1.39ms

Slide 71

Slide 71 text

Α͋͘Δxibͷϩʔυ͕஗͘ͳΔཁҼ wxib্Ͱద༻͍ͯ͠ΔΧελϜϑΥϯτ͕ ಡΈࠐΊ͍ͯͳ͍ wSystem Font͕ద༻͞Ε͍ͯͨͷͰ ಛʹ໰୊͸ͳͦ͞͏ w୯७ʹViewͷੜ੒ʹ͕͔͔͍࣌ؒͬͯΔ!ʁ

Slide 72

Slide 72 text

ͲͷΑ͏ʹViewΛੜ੒͢Δ͔

Slide 73

Slide 73 text

վળ͢ΔͨΊͷΞϓϩʔν wxibΛར༻ͤͣίʔυϨΠΞ΢τʹม͑Δ w଎͘͸ͳΔͱࢥ͏͕ɺେ෯ʹ࡟ݮͰ͖Δ͔ ͸࣮૷ͯ͠Έͳ͍ͱΘ͔Βͳ͍ wViewΛੜ੒Λ஗Ԇͤ͞Δ wओཁͳViewͷੜ੒Λ͠ͳ͍৔߹ʹද͕ࣔ ଎͘ͳΔͷͰվળͷՄೳੑେ

Slide 74

Slide 74 text

վળલͷ࣮૷

Slide 75

Slide 75 text

class DetailViewController: UIViewController { @IBOutlet private weak var contentStackView: UIStackView! { didSet { contentStackView.addArrangedSubview(thumbnailView) contentStackView.addArrangedSubview(summaryView) contentStackView.addArrangedSubview(otherView) contentStackView.addArrangedSubview(recommendView) } } private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private let thumbnailView = ThumbnailView.makeFromNib() private let summaryView = SummaryView.makeFromNib() private let otherView = OtherView.makeFromNib() private let recommendView = RecommendView.makeFromNib() private lazy var viewModel = DetailViewModel( ... toggleContentInfo: summaryView.didTapContentInfo ) override func viewDidLoad() { super.viewDidLoad() viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: disposeBag) viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: disposeBag) viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: disposeBag) viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: disposeBag) ... } }

Slide 76

Slide 76 text

class DetailViewController: UIViewController { @IBOutlet private weak var contentStackView: UIStackView! { didSet { contentStackView.addArrangedSubview(thumbnailView) contentStackView.addArrangedSubview(summaryView) contentStackView.addArrangedSubview(otherView) contentStackView.addArrangedSubview(recommendView) } } private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private let thumbnailView = ThumbnailView.makeFromNib() private let summaryView = SummaryView.makeFromNib() private let otherView = OtherView.makeFromNib() private let recommendView = RecommendView.makeFromNib() private lazy var viewModel = DetailViewModel( ... toggleContentInfo: summaryView.didTapContentInfo ) override func viewDidLoad() { super.viewDidLoad() viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: disposeBag) viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: disposeBag) viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: disposeBag) viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: disposeBag) ... } }

Slide 77

Slide 77 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Observable<[Episode]> let isRecommendListHidden: Observable let isContentInfoHidden: Observable init(id: String, episodeAction: EpisodeAction, toggleContentInfo: Observable) { let _episodeDetail = BehaviorRelay(value: nil) let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) self.episodeDetail = _episodeDetail .flatMap { $0.map(Observable.just) ?? .empty() } self.recommendList = _recommendList.asObservable() self.isRecommendListHidden = _recommendList .map { $0.isEmpty } self.isContentInfoHidden = _isContentInfoHidden.asObservable() episodeAction.getEpisode(id: id) .bind(to: _episodeDetail) .disposed(by: disposeBag) episodeAction.getRecommendList() .bind(to: _recommendList) .disposed(by: disposeBag) toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) } }

Slide 78

Slide 78 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Observable<[Episode]> let isRecommendListHidden: Observable let isContentInfoHidden: Observable init(id: String, episodeAction: EpisodeAction, toggleContentInfo: Observable) { let _episodeDetail = BehaviorRelay(value: nil) let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) self.episodeDetail = _episodeDetail .flatMap { $0.map(Observable.just) ?? .empty() } self.recommendList = _recommendList.asObservable() self.isRecommendListHidden = _recommendList .map { $0.isEmpty } self.isContentInfoHidden = _isContentInfoHidden.asObservable() episodeAction.getEpisode(id: id) .bind(to: _episodeDetail) .disposed(by: disposeBag) episodeAction.getRecommendList() .bind(to: _recommendList) .disposed(by: disposeBag) toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) } } w_episodeDetail͕nilͰͳ͔ͬͨͱ͖ʹ஋Λྲྀ͢

Slide 79

Slide 79 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Observable<[Episode]> let isRecommendListHidden: Observable let isContentInfoHidden: Observable init(id: String, episodeAction: EpisodeAction, toggleContentInfo: Observable) { let _episodeDetail = BehaviorRelay(value: nil) let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) self.episodeDetail = _episodeDetail .flatMap { $0.map(Observable.just) ?? .empty() } self.recommendList = _recommendList.asObservable() self.isRecommendListHidden = _recommendList .map { $0.isEmpty } self.isContentInfoHidden = _isContentInfoHidden.asObservable() episodeAction.getEpisode(id: id) .bind(to: _episodeDetail) .disposed(by: disposeBag) episodeAction.getRecommendList() .bind(to: _recommendList) .disposed(by: disposeBag) toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) } } wॳظԽ͞ΕͨλΠϛϯάͰৄࡉ৘ใऔಘΛ࣮ߦ

Slide 80

Slide 80 text

class DetailViewController: UIViewController { @IBOutlet private weak var contentStackView: UIStackView! { didSet { contentStackView.addArrangedSubview(thumbnailView) contentStackView.addArrangedSubview(summaryView) contentStackView.addArrangedSubview(otherView) contentStackView.addArrangedSubview(recommendView) } } private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private let thumbnailView = ThumbnailView.makeFromNib() private let summaryView = SummaryView.makeFromNib() private let otherView = OtherView.makeFromNib() private let recommendView = RecommendView.makeFromNib() private lazy var viewModel = DetailViewModel( ... toggleContentInfo: summaryView.didTapContentInfo ) override func viewDidLoad() { super.viewDidLoad() viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: disposeBag) viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: disposeBag) viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: disposeBag) viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: disposeBag) ... } }

Slide 81

Slide 81 text

class DetailViewController: UIViewController { @IBOutlet private weak var contentStackView: UIStackView! { didSet { contentStackView.addArrangedSubview(thumbnailView) contentStackView.addArrangedSubview(summaryView) contentStackView.addArrangedSubview(otherView) contentStackView.addArrangedSubview(recommendView) } } private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private let thumbnailView = ThumbnailView.makeFromNib() private let summaryView = SummaryView.makeFromNib() private let otherView = OtherView.makeFromNib() private let recommendView = RecommendView.makeFromNib() private lazy var viewModel = DetailViewModel( ... toggleContentInfo: summaryView.didTapContentInfo ) override func viewDidLoad() { super.viewDidLoad() viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: disposeBag) viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: disposeBag) viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: disposeBag) viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: disposeBag) ... } } wepisodeDetailͷऔಘ׬ྃޙʹϨΠΞ΢τॲཧ

Slide 82

Slide 82 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Observable<[Episode]> let isRecommendListHidden: Observable let isContentInfoHidden: Observable init(id: String, episodeAction: EpisodeAction, toggleContentInfo: Observable) { let _episodeDetail = BehaviorRelay(value: nil) let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) self.episodeDetail = _episodeDetail .flatMap { $0.map(Observable.just) ?? .empty() } self.recommendList = _recommendList.asObservable() self.isRecommendListHidden = _recommendList .map { $0.isEmpty } self.isContentInfoHidden = _isContentInfoHidden.asObservable() episodeAction.getEpisode(id: id) .bind(to: _episodeDetail) .disposed(by: disposeBag) episodeAction.getRecommendList() .bind(to: _recommendList) .disposed(by: disposeBag) toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) } }

Slide 83

Slide 83 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Observable<[Episode]> let isRecommendListHidden: Observable let isContentInfoHidden: Observable init(id: String, episodeAction: EpisodeAction, toggleContentInfo: Observable) { let _episodeDetail = BehaviorRelay(value: nil) let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) self.episodeDetail = _episodeDetail .flatMap { $0.map(Observable.just) ?? .empty() } self.recommendList = _recommendList.asObservable() self.isRecommendListHidden = _recommendList .map { $0.isEmpty } self.isContentInfoHidden = _isContentInfoHidden.asObservable() episodeAction.getEpisode(id: id) .bind(to: _episodeDetail) .disposed(by: disposeBag) episodeAction.getRecommendList() .bind(to: _recommendList) .disposed(by: disposeBag) toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) } } wଈ࣌ʹϨίϝϯυͷ஋͕ྲྀΕΔ

Slide 84

Slide 84 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Observable<[Episode]> let isRecommendListHidden: Observable let isContentInfoHidden: Observable init(id: String, episodeAction: EpisodeAction, toggleContentInfo: Observable) { let _episodeDetail = BehaviorRelay(value: nil) let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) self.episodeDetail = _episodeDetail .flatMap { $0.map(Observable.just) ?? .empty() } self.recommendList = _recommendList.asObservable() self.isRecommendListHidden = _recommendList .map { $0.isEmpty } self.isContentInfoHidden = _isContentInfoHidden.asObservable() episodeAction.getEpisode(id: id) .bind(to: _episodeDetail) .disposed(by: disposeBag) episodeAction.getRecommendList() .bind(to: _recommendList) .disposed(by: disposeBag) toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) } } wϨίϝϯυ͕ۭ͔Ͳ͏͔͔Βม׵ͨ͠ ஋͕ଈ࣌ʹྲྀΕΔ

Slide 85

Slide 85 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Observable<[Episode]> let isRecommendListHidden: Observable let isContentInfoHidden: Observable init(id: String, episodeAction: EpisodeAction, toggleContentInfo: Observable) { let _episodeDetail = BehaviorRelay(value: nil) let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) self.episodeDetail = _episodeDetail .flatMap { $0.map(Observable.just) ?? .empty() } self.recommendList = _recommendList.asObservable() self.isRecommendListHidden = _recommendList .map { $0.isEmpty } self.isContentInfoHidden = _isContentInfoHidden.asObservable() episodeAction.getEpisode(id: id) .bind(to: _episodeDetail) .disposed(by: disposeBag) episodeAction.getRecommendList() .bind(to: _recommendList) .disposed(by: disposeBag) toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) } } wॳظԽ͞ΕͨλΠϛϯάͰϨίϝϯυऔಘΛ࣮ߦ

Slide 86

Slide 86 text

class DetailViewController: UIViewController { @IBOutlet private weak var contentStackView: UIStackView! { didSet { contentStackView.addArrangedSubview(thumbnailView) contentStackView.addArrangedSubview(summaryView) contentStackView.addArrangedSubview(otherView) contentStackView.addArrangedSubview(recommendView) } } private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private let thumbnailView = ThumbnailView.makeFromNib() private let summaryView = SummaryView.makeFromNib() private let otherView = OtherView.makeFromNib() private let recommendView = RecommendView.makeFromNib() private lazy var viewModel = DetailViewModel( ... toggleContentInfo: summaryView.didTapContentInfo ) override func viewDidLoad() { super.viewDidLoad() viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: disposeBag) viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: disposeBag) viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: disposeBag) viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: disposeBag) ... } }

Slide 87

Slide 87 text

class DetailViewController: UIViewController { @IBOutlet private weak var contentStackView: UIStackView! { didSet { contentStackView.addArrangedSubview(thumbnailView) contentStackView.addArrangedSubview(summaryView) contentStackView.addArrangedSubview(otherView) contentStackView.addArrangedSubview(recommendView) } } private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private let thumbnailView = ThumbnailView.makeFromNib() private let summaryView = SummaryView.makeFromNib() private let otherView = OtherView.makeFromNib() private let recommendView = RecommendView.makeFromNib() private lazy var viewModel = DetailViewModel( ... toggleContentInfo: summaryView.didTapContentInfo ) override func viewDidLoad() { super.viewDidLoad() viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: disposeBag) viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: disposeBag) viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: disposeBag) viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: disposeBag) ... } } wisHidden͕trueͰଈ࣌ʹྲྀΕͯϨΠΞ΢τॲཧ wAPIͷऔಘ͕׬ྃ͢ΔͱrecommendListͷϨΠΞ΢τॲཧ wͦͷޙʹisHidden͕falseͰϨΠΞ΢τॲཧ

Slide 88

Slide 88 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Observable<[Episode]> let isRecommendListHidden: Observable let isContentInfoHidden: Observable init(id: String, episodeAction: EpisodeAction, toggleContentInfo: Observable) { let _episodeDetail = BehaviorRelay(value: nil) let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) self.episodeDetail = _episodeDetail .flatMap { $0.map(Observable.just) ?? .empty() } self.recommendList = _recommendList.asObservable() self.isRecommendListHidden = _recommendList .map { $0.isEmpty } self.isContentInfoHidden = _isContentInfoHidden.asObservable() episodeAction.getEpisode(id: id) .bind(to: _episodeDetail) .disposed(by: disposeBag) episodeAction.getRecommendList() .bind(to: _recommendList) .disposed(by: disposeBag) toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) } }

Slide 89

Slide 89 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Observable<[Episode]> let isRecommendListHidden: Observable let isContentInfoHidden: Observable init(id: String, episodeAction: EpisodeAction, toggleContentInfo: Observable) { let _episodeDetail = BehaviorRelay(value: nil) let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) self.episodeDetail = _episodeDetail .flatMap { $0.map(Observable.just) ?? .empty() } self.recommendList = _recommendList.asObservable() self.isRecommendListHidden = _recommendList .map { $0.isEmpty } self.isContentInfoHidden = _isContentInfoHidden.asObservable() episodeAction.getEpisode(id: id) .bind(to: _episodeDetail) .disposed(by: disposeBag) episodeAction.getRecommendList() .bind(to: _recommendList) .disposed(by: disposeBag) toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) } } w˝·ͨ͸ContentInfoView͕λοϓ͞ΕΔͱൃՐ

Slide 90

Slide 90 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Observable<[Episode]> let isRecommendListHidden: Observable let isContentInfoHidden: Observable init(id: String, episodeAction: EpisodeAction, toggleContentInfo: Observable) { let _episodeDetail = BehaviorRelay(value: nil) let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) self.episodeDetail = _episodeDetail .flatMap { $0.map(Observable.just) ?? .empty() } self.recommendList = _recommendList.asObservable() self.isRecommendListHidden = _recommendList .map { $0.isEmpty } self.isContentInfoHidden = _isContentInfoHidden.asObservable() episodeAction.getEpisode(id: id) .bind(to: _episodeDetail) .disposed(by: disposeBag) episodeAction.getRecommendList() .bind(to: _recommendList) .disposed(by: disposeBag) toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) } } wଈ࣌ʹ_isContentInfoHiddenͷ஋͕ྲྀΕΔ

Slide 91

Slide 91 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Observable<[Episode]> let isRecommendListHidden: Observable let isContentInfoHidden: Observable init(id: String, episodeAction: EpisodeAction, toggleContentInfo: Observable) { let _episodeDetail = BehaviorRelay(value: nil) let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) self.episodeDetail = _episodeDetail .flatMap { $0.map(Observable.just) ?? .empty() } self.recommendList = _recommendList.asObservable() self.isRecommendListHidden = _recommendList .map { $0.isEmpty } self.isContentInfoHidden = _isContentInfoHidden.asObservable() episodeAction.getEpisode(id: id) .bind(to: _episodeDetail) .disposed(by: disposeBag) episodeAction.getRecommendList() .bind(to: _recommendList) .disposed(by: disposeBag) toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) } } wΠϕϯτ͕ྲྀΕΔͱ_isContentInfoHiddenͷ ஋Λ൓సͤ͞Δ

Slide 92

Slide 92 text

class DetailViewController: UIViewController { @IBOutlet private weak var contentStackView: UIStackView! { didSet { contentStackView.addArrangedSubview(thumbnailView) contentStackView.addArrangedSubview(summaryView) contentStackView.addArrangedSubview(otherView) contentStackView.addArrangedSubview(recommendView) } } private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private let thumbnailView = ThumbnailView.makeFromNib() private let summaryView = SummaryView.makeFromNib() private let otherView = OtherView.makeFromNib() private let recommendView = RecommendView.makeFromNib() private lazy var viewModel = DetailViewModel( ... toggleContentInfo: summaryView.didTapContentInfo ) override func viewDidLoad() { super.viewDidLoad() viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: disposeBag) viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: disposeBag) viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: disposeBag) viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: disposeBag) ... } }

Slide 93

Slide 93 text

class DetailViewController: UIViewController { @IBOutlet private weak var contentStackView: UIStackView! { didSet { contentStackView.addArrangedSubview(thumbnailView) contentStackView.addArrangedSubview(summaryView) contentStackView.addArrangedSubview(otherView) contentStackView.addArrangedSubview(recommendView) } } private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private let thumbnailView = ThumbnailView.makeFromNib() private let summaryView = SummaryView.makeFromNib() private let otherView = OtherView.makeFromNib() private let recommendView = RecommendView.makeFromNib() private lazy var viewModel = DetailViewModel( ... toggleContentInfo: summaryView.didTapContentInfo ) override func viewDidLoad() { super.viewDidLoad() viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: disposeBag) viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: disposeBag) viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: disposeBag) viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: disposeBag) ... } } wisHidden͕trueͰଈ࣌ʹ஋͕ྲྀΕ͖ͯͯϨΠΞ΢τॲཧ

Slide 94

Slide 94 text

class DetailViewController: UIViewController { @IBOutlet private weak var contentStackView: UIStackView! { didSet { contentStackView.addArrangedSubview(thumbnailView) contentStackView.addArrangedSubview(summaryView) contentStackView.addArrangedSubview(otherView) contentStackView.addArrangedSubview(recommendView) } } private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private let thumbnailView = ThumbnailView.makeFromNib() private let summaryView = SummaryView.makeFromNib() private let otherView = OtherView.makeFromNib() private let recommendView = RecommendView.makeFromNib() private lazy var viewModel = DetailViewModel( ... toggleContentInfo: summaryView.didTapContentInfo ) override func viewDidLoad() { super.viewDidLoad() viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: disposeBag) viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: disposeBag) viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: disposeBag) viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: disposeBag) ... } } wtoggleContentInfo͕ൃՐ͢ΔͱϨΠΞ΢τॲཧ

Slide 95

Slide 95 text

վળޙͷ࣮૷

Slide 96

Slide 96 text

extension DetailViewController { class LazyViews { let thumbnailView: ThumbnailView let summaryView: SummaryView let otherView: OtherView let recommendView: RecommendView init(thumbnailView: ThumbnailView, summaryView: SummaryView, otherView: OtherView, recommendView: RecommendView) { ... } } class LazyRelays { let didTapContentInfo = PublishRelay() let didFinishInitializingViews = PublishRelay() } }

Slide 97

Slide 97 text

extension DetailViewController { class LazyViews { let thumbnailView: ThumbnailView let summaryView: SummaryView let otherView: OtherView let recommendView: RecommendView init(thumbnailView: ThumbnailView, summaryView: SummaryView, otherView: OtherView, recommendView: RecommendView) { ... } } class LazyRelays { let didTapContentInfo = PublishRelay() let didFinishInitializingViews = PublishRelay() } } ஗ԆॳظԽΛͨ͠ViewΛอ࣋͢ΔΫϥε

Slide 98

Slide 98 text

extension DetailViewController { class LazyViews { let thumbnailView: ThumbnailView let summaryView: SummaryView let otherView: OtherView let recommendView: RecommendView init(thumbnailView: ThumbnailView, summaryView: SummaryView, otherView: OtherView, recommendView: RecommendView) { ... } } class LazyRelays { let didTapContentInfo = PublishRelay() let didFinishInitializingViews = PublishRelay() } } ஗ԆॳظԽΛͨ͠ViewͷObservableͱ ViewModelΛܨ͙PublishRelayΛอ࣋͢ΔΫϥε

Slide 99

Slide 99 text

final class DetailViewController: UIViewController { @IBOutlet weak var contentStackView: UIStackView! private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private var lazyViews: LazyViews? private let lazyRelays = LazyRelays() private lazy var viewModel = DetailViewModel( ... viewDidAppear: rx.methodInvoked(#selector(viewDidAppear(_:))).map { _ in }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) override func viewDidLoad() { super.viewDidLoad() viewModel.readyForInitializingViews .bind(to: Binder(self) { me, _ in let summaryView = SummaryView.makeFromNib() me.viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: me.disposeBag) summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: me.disposeBag) let recommendView = RecommendView.makeFromNib() me.viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: me.disposeBag) me.viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: me.disposeBag) me.contentStackView.addArrangedSubview(...) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } }

Slide 100

Slide 100 text

final class DetailViewController: UIViewController { @IBOutlet weak var contentStackView: UIStackView! private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private var lazyViews: LazyViews? private let lazyRelays = LazyRelays() private lazy var viewModel = DetailViewModel( ... viewDidAppear: rx.methodInvoked(#selector(viewDidAppear(_:))).map { _ in }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) override func viewDidLoad() { super.viewDidLoad() viewModel.readyForInitializingViews .bind(to: Binder(self) { me, _ in let summaryView = SummaryView.makeFromNib() me.viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: me.disposeBag) summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: me.disposeBag) let recommendView = RecommendView.makeFromNib() me.viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: me.disposeBag) me.viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: me.disposeBag) me.contentStackView.addArrangedSubview(...) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } }

Slide 101

Slide 101 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Observable<[Episode]> let isRecommendListHidden: Observable let isContentInfoHidden: Observable let readyForInitializingViews: Observable init(..., viewDidAppear: Observable, toggleContentInfo: Observable, didFinishInitializingViews: Observable) { let _episodeDetail = BehaviorRelay(value: nil) let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) self.episodeDetail = _episodeDetail .flatMap { $0.map(Observable.just) ?? .empty() } self.recommendList = _recommendList.asObservable() self.isRecommendListHidden = _recommendList .map { $0.isEmpty } self.isContentInfoHidden = _isContentInfoHidden.asObservable() self.readyForInitializingViews = Observable.combineLatest(episodeDetail, viewDidAppear) .map { _ in }.take(1) episodeAction.getEpisode(id: id) .bind(to: _episodeDetail) .disposed(by: disposeBag) didFinishInitializingViews.take(1).flatMap { _ in episodeAction.getRecommendList() } .bind(to: _recommendList) .disposed(by: disposeBag) toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) } }

Slide 102

Slide 102 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Observable<[Episode]> let isRecommendListHidden: Observable let isContentInfoHidden: Observable let readyForInitializingViews: Observable init(..., viewDidAppear: Observable, toggleContentInfo: Observable, didFinishInitializingViews: Observable) { let _episodeDetail = BehaviorRelay(value: nil) let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) self.episodeDetail = _episodeDetail .flatMap { $0.map(Observable.just) ?? .empty() } self.recommendList = _recommendList.asObservable() self.isRecommendListHidden = _recommendList .map { $0.isEmpty } self.isContentInfoHidden = _isContentInfoHidden.asObservable() self.readyForInitializingViews = Observable.combineLatest(episodeDetail, viewDidAppear) .map { _ in }.take(1) episodeAction.getEpisode(id: id) .bind(to: _episodeDetail) .disposed(by: disposeBag) didFinishInitializingViews.take(1).flatMap { _ in episodeAction.getRecommendList() } .bind(to: _recommendList) .disposed(by: disposeBag) toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) } } wepisodeDetailͷऔಘ͕׬ྃ͢Δ͔ͭviewDidAppear
 ͕࣮ߦ͞ΕΔͱ౓͚ͩྲྀΕΔ

Slide 103

Slide 103 text

final class DetailViewController: UIViewController { @IBOutlet weak var contentStackView: UIStackView! private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private var lazyViews: LazyViews? private let lazyRelays = LazyRelays() private lazy var viewModel = DetailViewModel( ... viewDidAppear: rx.methodInvoked(#selector(viewDidAppear(_:))).map { _ in }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) override func viewDidLoad() { super.viewDidLoad() viewModel.readyForInitializingViews .bind(to: Binder(self) { me, _ in let summaryView = SummaryView.makeFromNib() me.viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: me.disposeBag) summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: me.disposeBag) let recommendView = RecommendView.makeFromNib() me.viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: me.disposeBag) me.viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: me.disposeBag) me.contentStackView.addArrangedSubview(...) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } }

Slide 104

Slide 104 text

final class DetailViewController: UIViewController { @IBOutlet weak var contentStackView: UIStackView! private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private var lazyViews: LazyViews? private let lazyRelays = LazyRelays() private lazy var viewModel = DetailViewModel( ... viewDidAppear: rx.methodInvoked(#selector(viewDidAppear(_:))).map { _ in }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) override func viewDidLoad() { super.viewDidLoad() viewModel.readyForInitializingViews .bind(to: Binder(self) { me, _ in let summaryView = SummaryView.makeFromNib() me.viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: me.disposeBag) summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: me.disposeBag) let recommendView = RecommendView.makeFromNib() me.viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: me.disposeBag) me.viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: me.disposeBag) me.contentStackView.addArrangedSubview(...) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } }

Slide 105

Slide 105 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Observable<[Episode]> let isRecommendListHidden: Observable let isContentInfoHidden: Observable let readyForInitializingViews: Observable init(..., viewDidAppear: Observable, toggleContentInfo: Observable, didFinishInitializingViews: Observable) { let _episodeDetail = BehaviorRelay(value: nil) let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) self.episodeDetail = _episodeDetail .flatMap { $0.map(Observable.just) ?? .empty() } self.recommendList = _recommendList.asObservable() self.isRecommendListHidden = _recommendList .map { $0.isEmpty } self.isContentInfoHidden = _isContentInfoHidden.asObservable() self.readyForInitializingViews = Observable.combineLatest(episodeDetail, viewDidAppear) .map { _ in }.take(1) episodeAction.getEpisode(id: id) .bind(to: _episodeDetail) .disposed(by: disposeBag) didFinishInitializingViews.take(1).flatMap { _ in episodeAction.getRecommendList() } .bind(to: _recommendList) .disposed(by: disposeBag) toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) } }

Slide 106

Slide 106 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Observable<[Episode]> let isRecommendListHidden: Observable let isContentInfoHidden: Observable let readyForInitializingViews: Observable init(..., viewDidAppear: Observable, toggleContentInfo: Observable, didFinishInitializingViews: Observable) { let _episodeDetail = BehaviorRelay(value: nil) let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) self.episodeDetail = _episodeDetail .flatMap { $0.map(Observable.just) ?? .empty() } self.recommendList = _recommendList.asObservable() self.isRecommendListHidden = _recommendList .map { $0.isEmpty } self.isContentInfoHidden = _isContentInfoHidden.asObservable() self.readyForInitializingViews = Observable.combineLatest(episodeDetail, viewDidAppear) .map { _ in }.take(1) episodeAction.getEpisode(id: id) .bind(to: _episodeDetail) .disposed(by: disposeBag) didFinishInitializingViews.take(1).flatMap { _ in episodeAction.getRecommendList() } .bind(to: _recommendList) .disposed(by: disposeBag) toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) } } wViewͷ஗ԆॳظԽ͕׬ྃ͢ΔͱྲྀΕΔ

Slide 107

Slide 107 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Observable<[Episode]> let isRecommendListHidden: Observable let isContentInfoHidden: Observable let readyForInitializingViews: Observable init(..., viewDidAppear: Observable, toggleContentInfo: Observable, didFinishInitializingViews: Observable) { let _episodeDetail = BehaviorRelay(value: nil) let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) self.episodeDetail = _episodeDetail .flatMap { $0.map(Observable.just) ?? .empty() } self.recommendList = _recommendList.asObservable() self.isRecommendListHidden = _recommendList .map { $0.isEmpty } self.isContentInfoHidden = _isContentInfoHidden.asObservable() self.readyForInitializingViews = Observable.combineLatest(episodeDetail, viewDidAppear) .map { _ in }.take(1) episodeAction.getEpisode(id: id) .bind(to: _episodeDetail) .disposed(by: disposeBag) didFinishInitializingViews.take(1).flatMap { _ in episodeAction.getRecommendList() } .bind(to: _recommendList) .disposed(by: disposeBag) toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) } } wViewͷ஗ԆॳظԽ͕׬ྃޙʹϨίϝϯυͷ औಘΛ࣮ߦ͢Δ

Slide 108

Slide 108 text

final class DetailViewController: UIViewController { @IBOutlet weak var contentStackView: UIStackView! private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private var lazyViews: LazyViews? private let lazyRelays = LazyRelays() private lazy var viewModel = DetailViewModel( ... viewDidAppear: rx.methodInvoked(#selector(viewDidAppear(_:))).map { _ in }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) override func viewDidLoad() { super.viewDidLoad() viewModel.readyForInitializingViews .bind(to: Binder(self) { me, _ in let summaryView = SummaryView.makeFromNib() me.viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: me.disposeBag) summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: me.disposeBag) let recommendView = RecommendView.makeFromNib() me.viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: me.disposeBag) me.viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: me.disposeBag) me.contentStackView.addArrangedSubview(...) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } }

Slide 109

Slide 109 text

final class DetailViewController: UIViewController { @IBOutlet weak var contentStackView: UIStackView! private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private var lazyViews: LazyViews? private let lazyRelays = LazyRelays() private lazy var viewModel = DetailViewModel( ... viewDidAppear: rx.methodInvoked(#selector(viewDidAppear(_:))).map { _ in }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) override func viewDidLoad() { super.viewDidLoad() viewModel.readyForInitializingViews .bind(to: Binder(self) { me, _ in let summaryView = SummaryView.makeFromNib() me.viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: me.disposeBag) summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: me.disposeBag) let recommendView = RecommendView.makeFromNib() me.viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: me.disposeBag) me.viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: me.disposeBag) me.contentStackView.addArrangedSubview(...) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } }

Slide 110

Slide 110 text

final class DetailViewController: UIViewController { @IBOutlet weak var contentStackView: UIStackView! private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private var lazyViews: LazyViews? private let lazyRelays = LazyRelays() private lazy var viewModel = DetailViewModel( ... viewDidAppear: rx.methodInvoked(#selector(viewDidAppear(_:))).map { _ in }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) override func viewDidLoad() { super.viewDidLoad() viewModel.readyForInitializingViews .bind(to: Binder(self) { me, _ in let summaryView = SummaryView.makeFromNib() me.viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: me.disposeBag) summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: me.disposeBag) let recommendView = RecommendView.makeFromNib() me.viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: me.disposeBag) me.viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: me.disposeBag) me.contentStackView.addArrangedSubview(...) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } } wViewͷ஗ԆॳظԽ͕׬ྃҎ߱ʹϨίϝϯυ ͷ஋ΛϨΠΞ΢τॲཧ

Slide 111

Slide 111 text

final class DetailViewController: UIViewController { @IBOutlet weak var contentStackView: UIStackView! private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private var lazyViews: LazyViews? private let lazyRelays = LazyRelays() private lazy var viewModel = DetailViewModel( ... viewDidAppear: rx.methodInvoked(#selector(viewDidAppear(_:))).map { _ in }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) override func viewDidLoad() { super.viewDidLoad() viewModel.readyForInitializingViews .bind(to: Binder(self) { me, _ in let summaryView = SummaryView.makeFromNib() me.viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: me.disposeBag) summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: me.disposeBag) let recommendView = RecommendView.makeFromNib() me.viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: me.disposeBag) me.viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: me.disposeBag) me.contentStackView.addArrangedSubview(...) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } }

Slide 112

Slide 112 text

final class DetailViewController: UIViewController { @IBOutlet weak var contentStackView: UIStackView! private(set) lazy var videoPlayerViewController = VideoPlayerViewController() private var lazyViews: LazyViews? private let lazyRelays = LazyRelays() private lazy var viewModel = DetailViewModel( ... viewDidAppear: rx.methodInvoked(#selector(viewDidAppear(_:))).map { _ in }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) override func viewDidLoad() { super.viewDidLoad() viewModel.readyForInitializingViews .bind(to: Binder(self) { me, _ in let summaryView = SummaryView.makeFromNib() me.viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: me.disposeBag) summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: me.disposeBag) let recommendView = RecommendView.makeFromNib() me.viewModel.recommendList .bind(to: Binder(recommendView) { $0.setRecommendList($1) }) .disposed(by: me.disposeBag) me.viewModel.isRecommendListHidden .bind(to: recommendView.rx.isHidden) .disposed(by: me.disposeBag) me.contentStackView.addArrangedSubview(...) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } } w஗ԆॳظԽ࣌ʹϨΠΞ΢τॲཧͱbind

Slide 113

Slide 113 text

class VideoFullscreenViewController: UINavigationController { private let detailViewController: DetailViewController private let videoPlayerViewController: VideoPlayerViewController override func viewDidLoad() { super.viewDidLoad() detailViewController.loadViewIfNeeded() videoPlayerViewController.setup(completion: { ... }) } } class VideoPlayerViewController: UIViewController { private var videoPlayerView: VideoPlayerView? private var videoPlayerViewModel: VideoPlayerViewModel? func setup(completion: () -> Void) { DispatchQueue.main.async { let videoPlayerView = VideoPlayerView.makeFromNib() let viewModel = VideoPlayerViewModel() self.videoPlayerView = videoPlayerView self.videoPlayerViewModel = viewModel } ... completion() } }

Slide 114

Slide 114 text

class VideoFullscreenViewController: UINavigationController { private let detailViewController: DetailViewController private let videoPlayerViewController: VideoPlayerViewController override func viewDidLoad() { super.viewDidLoad() detailViewController.loadViewIfNeeded() videoPlayerViewController.setup(completion: { ... }) } } class VideoPlayerViewController: UIViewController { private var videoPlayerView: VideoPlayerView? private var videoPlayerViewModel: VideoPlayerViewModel? func setup(completion: () -> Void) { DispatchQueue.main.async { let videoPlayerView = VideoPlayerView.makeFromNib() let viewModel = VideoPlayerViewModel() self.videoPlayerView = videoPlayerView self.videoPlayerViewModel = viewModel } ... completion() } }

Slide 115

Slide 115 text

දࣔ଎౓ վળޙ iPhone XS Max iOS13 iPhone 8 iOS12 ॳճ 776ms 1060ms ճ໨Ҏ߱ 580ms 653ms

Slide 116

Slide 116 text

දࣔ଎౓ iPhone XS Max iOS13 iPhone 8 iOS12 ॳճ 1360ms
 ↓
 776ms 2100ms
 ↓
 1060ms ճ໨Ҏ߱ 760ms
 ↓
 580ms 1180ms
 ↓
 653ms

Slide 117

Slide 117 text

վળ൛ iPhone6s iOS11 AppStore൛ iPhone8 iOS12

Slide 118

Slide 118 text

վળ఺ͷҰཡ w UIStackViewͷdidSetͰarrangedSubview͍ͯͨ͠ViewΛɺviewDidAppearޙ ʹ஗ԆॳظԽͦ͠ͷλΠϛϯάͰarrangedSubview͢ΔΑ͏मਖ਼ w viewDidLoadͰbind͍ͯͨ͠ObserverɾObservableΛLazyRelaysͷ PublishRelayΛܦ༝͢ΔΑ͏ʹͯ͠஗ԆॳظԽʹରԠ w ϨίϝϯυͷऔಘΛViewͷ஗ԆॳظԽޙʹมߋʢϨίϝϯυͷඳը͕ͦͷ͋ ͱʹͳΔʣ

Slide 119

Slide 119 text

ը໘ճసͷվળ

Slide 120

Slide 120 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 121

Slide 121 text

ը໘ճస଎౓ վળલ ˞ճ࣮ࢪ iPhone 8 iOS12 ࠷খ 1100ms ฏۉ 1130ms ࠷େ 1300ms

Slide 122

Slide 122 text

import UIKit import os.signpost class VideoFullscreenViewController: UIViewController { let osLog = = OSLog(subsystem: "jp.co.marty-suzuki", category: .pointsOfInterest) override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) { super.willTransition(to: newCollection, with: coordinator) os_signpost(.begin, log: osLog, name: "Rotation Measurement”) coordinator.animate(alongsideTransition: nil) { [osLog] _ in os_signpost(.end, log: osLog, name: "Rotation Measurement") } } }

Slide 123

Slide 123 text

import UIKit import os.signpost class VideoFullscreenViewController: UIViewController { let osLog = = OSLog(subsystem: "jp.co.marty-suzuki", category: .pointsOfInterest) override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) { super.willTransition(to: newCollection, with: coordinator) os_signpost(.begin, log: osLog, name: "Rotation Measurement”) coordinator.animate(alongsideTransition: nil) { [osLog] _ in os_signpost(.end, log: osLog, name: "Rotation Measurement") } } }

Slide 124

Slide 124 text

վળલͷ࣮૷

Slide 125

Slide 125 text

class RecommendView: UIView { private let collectionView = UICollectionView(...) private lazy var collectionViewHeightConstraint = collectionView.heightAnchor.constraint(equalToConstant: 0) private var recommendList: [Episode] = [] init() { ... addSubview(collectionView) NSLayoutConstraint.activate([ ..., collectionViewHeightConstraint ]) } func setRecommendList(_ recommendList: [Episode]) { self.recommendList = recommendList collectionView.reloadData() collectionView.layoutIfNeeded() collectionViewHeightConstraint.constant = collectionView.collectionViewLayout.collectionViewContentSize.height layoutIfNeeded() } }

Slide 126

Slide 126 text

class RecommendView: UIView { private let collectionView = UICollectionView(...) private lazy var collectionViewHeightConstraint = collectionView.heightAnchor.constraint(equalToConstant: 0) private var recommendList: [Episode] = [] init() { ... addSubview(collectionView) NSLayoutConstraint.activate([ ..., collectionViewHeightConstraint ]) } func setRecommendList(_ recommendList: [Episode]) { self.recommendList = recommendList collectionView.reloadData() collectionView.layoutIfNeeded() collectionViewHeightConstraint.constant = collectionView.collectionViewLayout.collectionViewContentSize.height layoutIfNeeded() } }

Slide 127

Slide 127 text

class RecommendView: UIView { private let collectionView = UICollectionView(...) private lazy var collectionViewHeightConstraint = collectionView.heightAnchor.constraint(equalToConstant: 0) private var recommendList: [Episode] = [] init() { ... addSubview(collectionView) NSLayoutConstraint.activate([ ..., collectionViewHeightConstraint ]) } func setRecommendList(_ recommendList: [Episode]) { self.recommendList = recommendList collectionView.reloadData() collectionView.layoutIfNeeded() collectionViewHeightConstraint.constant = collectionView.collectionViewLayout.collectionViewContentSize.height layoutIfNeeded() } } $PMMFDUJPO7JFXͷ$POUFOU4J[Fͷߴ͞ʹ߹Θͤͯ 7JFXͷߴ͞ΛΞοϓσʔτ͢ΔͨΊ$FMMͷ࠶ར༻͸͞Ε͍ͯͳ͍ঢ়ଶ

Slide 128

Slide 128 text

class DetailViewModel { ... let isContentInfoHidden: Observable let readyForInitializingViews: Observable let stackAxis: Observable let addThumbnailToRoot: Observable let addThumbnailToContent: Observable init(..., traitCollectionDidChange: Observable, toggleContentInfo: Observable, didFinishInitializingViews: Observable) { ... let _isContentInfoHidden = BehaviorRelay(value: true) let _isPortrait = BehaviorRelay(value: true) ... self.isContentInfoHidden = _isContentInfoHidden.asObservable() self.stackAxis = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .map { $0 ? .vertical : .horizontal } self.addThumbnailToRoot = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .flatMap { $0 ? Observable.empty() : .just(()) } self.addThumbnailToContent = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .flatMap { $0 ? Observable.just(()) : .empty() } ... toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) traitCollectionDidChange .map { $0.verticalSizeClass == .regular && $0.horizontalSizeClass == .compact } .bind(to: _isPortrait) .disposed(by: disposeBag) } }

Slide 129

Slide 129 text

class DetailViewModel { ... let isContentInfoHidden: Observable let readyForInitializingViews: Observable let stackAxis: Observable let addThumbnailToRoot: Observable let addThumbnailToContent: Observable init(..., traitCollectionDidChange: Observable, toggleContentInfo: Observable, didFinishInitializingViews: Observable) { ... let _isContentInfoHidden = BehaviorRelay(value: true) let _isPortrait = BehaviorRelay(value: true) ... self.isContentInfoHidden = _isContentInfoHidden.asObservable() self.stackAxis = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .map { $0 ? .vertical : .horizontal } self.addThumbnailToRoot = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .flatMap { $0 ? Observable.empty() : .just(()) } self.addThumbnailToContent = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .flatMap { $0 ? Observable.just(()) : .empty() } ... toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) traitCollectionDidChange .map { $0.verticalSizeClass == .regular && $0.horizontalSizeClass == .compact } .bind(to: _isPortrait) .disposed(by: disposeBag) } } wtraitCollectionΛ΋ͱʹॎɾԣΛ൑ఆ

Slide 130

Slide 130 text

class DetailViewModel { ... let isContentInfoHidden: Observable let readyForInitializingViews: Observable let stackAxis: Observable let addThumbnailToRoot: Observable let addThumbnailToContent: Observable init(..., traitCollectionDidChange: Observable, toggleContentInfo: Observable, didFinishInitializingViews: Observable) { ... let _isContentInfoHidden = BehaviorRelay(value: true) let _isPortrait = BehaviorRelay(value: true) ... self.isContentInfoHidden = _isContentInfoHidden.asObservable() self.stackAxis = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .map { $0 ? .vertical : .horizontal } self.addThumbnailToRoot = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .flatMap { $0 ? Observable.empty() : .just(()) } self.addThumbnailToContent = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .flatMap { $0 ? Observable.just(()) : .empty() } ... toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) traitCollectionDidChange .map { $0.verticalSizeClass == .regular && $0.horizontalSizeClass == .compact } .bind(to: _isPortrait) .disposed(by: disposeBag) } } wViewͷ஗ԆॳظԽ׬ྃҎ߱ʹUIStackViewͷ ελοΫํ޲Λઃఆ

Slide 131

Slide 131 text

final class DetailViewController: UIViewController { @IBOutlet weak var rootStackView: UIStackView! @IBOutlet weak var contentStackView: UIStackView! ... private var lazyViews: LazyViews? private let lazyRelays = LazyRelays() private lazy var viewModel = DetailViewModel( ... traitCollectionDidChange: rx.methodInvoked(#selector(traitCollectionDidChange(_:))).map { ... }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) override func viewDidLoad() { super.viewDidLoad() viewModel.initializeViews .bind(to: Binder(self) { me, _ in ... summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: me.disposeBag) me.contentStackView.addArrangedSubview(…) me.viewModel.stackAxis .bind(to: me.rootStackView.rx[\.axis]) .disposed(by: me.disposeBag) me.viewModel.addThumbnailToRoot .bind(to: Binder(me) { me, _ in guard let thumbnailView = me.lazyViews?.thumbnailView, !me.rootStackView.arrangedSubviews.contains(thumbnailView) else { return } if me.contentStackView.arrangedSubviews.contains(thumbnailView) { me.contentStackView.removeArrangedSubview(thumbnailView) thumbnailView.removeFromSuperview() } me.rootStackView.addArrangedSubview(thumbnailView) }) .disposed(by: me.disposeBag) me.viewModel.addThumbnailToContent .bind(to: ...) .disposed(by: me.disposeBag) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } }

Slide 132

Slide 132 text

final class DetailViewController: UIViewController { @IBOutlet weak var rootStackView: UIStackView! @IBOutlet weak var contentStackView: UIStackView! ... private var lazyViews: LazyViews? private let lazyRelays = LazyRelays() private lazy var viewModel = DetailViewModel( ... traitCollectionDidChange: rx.methodInvoked(#selector(traitCollectionDidChange(_:))).map { ... }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) override func viewDidLoad() { super.viewDidLoad() viewModel.initializeViews .bind(to: Binder(self) { me, _ in ... summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: me.disposeBag) me.contentStackView.addArrangedSubview(…) me.viewModel.stackAxis .bind(to: me.rootStackView.rx[\.axis]) .disposed(by: me.disposeBag) me.viewModel.addThumbnailToRoot .bind(to: Binder(me) { me, _ in guard let thumbnailView = me.lazyViews?.thumbnailView, !me.rootStackView.arrangedSubviews.contains(thumbnailView) else { return } if me.contentStackView.arrangedSubviews.contains(thumbnailView) { me.contentStackView.removeArrangedSubview(thumbnailView) thumbnailView.removeFromSuperview() } me.rootStackView.addArrangedSubview(thumbnailView) }) .disposed(by: me.disposeBag) me.viewModel.addThumbnailToContent .bind(to: ...) .disposed(by: me.disposeBag) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } }

Slide 133

Slide 133 text

class DetailViewModel { ... let isContentInfoHidden: Observable let readyForInitializingViews: Observable let stackAxis: Observable let addThumbnailToRoot: Observable let addThumbnailToContent: Observable init(..., traitCollectionDidChange: Observable, toggleContentInfo: Observable, didFinishInitializingViews: Observable) { ... let _isContentInfoHidden = BehaviorRelay(value: true) let _isPortrait = BehaviorRelay(value: true) ... self.isContentInfoHidden = _isContentInfoHidden.asObservable() self.stackAxis = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .map { $0 ? .vertical : .horizontal } self.addThumbnailToRoot = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .flatMap { $0 ? Observable.empty() : .just(()) } self.addThumbnailToContent = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .flatMap { $0 ? Observable.just(()) : .empty() } ... toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) traitCollectionDidChange .map { $0.verticalSizeClass == .regular && $0.horizontalSizeClass == .compact } .bind(to: _isPortrait) .disposed(by: disposeBag) } }

Slide 134

Slide 134 text

class DetailViewModel { ... let isContentInfoHidden: Observable let readyForInitializingViews: Observable let stackAxis: Observable let addThumbnailToRoot: Observable let addThumbnailToContent: Observable init(..., traitCollectionDidChange: Observable, toggleContentInfo: Observable, didFinishInitializingViews: Observable) { ... let _isContentInfoHidden = BehaviorRelay(value: true) let _isPortrait = BehaviorRelay(value: true) ... self.isContentInfoHidden = _isContentInfoHidden.asObservable() self.stackAxis = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .map { $0 ? .vertical : .horizontal } self.addThumbnailToRoot = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .flatMap { $0 ? Observable.empty() : .just(()) } self.addThumbnailToContent = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .flatMap { $0 ? Observable.just(()) : .empty() } ... toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) traitCollectionDidChange .map { $0.verticalSizeClass == .regular && $0.horizontalSizeClass == .compact } .bind(to: _isPortrait) .disposed(by: disposeBag) } } wViewͷ஗ԆॳظԽ׬ྃҎ߱ʹॎ͔ԣ͔ʹΑͬͯ rootͷUIStackViewʹadd͢Δ͔contentͷ UIStackViewʹadd͢Δ͔ͷΠϕϯτΛྲྀ͢

Slide 135

Slide 135 text

final class DetailViewController: UIViewController { @IBOutlet weak var rootStackView: UIStackView! @IBOutlet weak var contentStackView: UIStackView! ... private var lazyViews: LazyViews? private let lazyRelays = LazyRelays() private lazy var viewModel = DetailViewModel( ... traitCollectionDidChange: rx.methodInvoked(#selector(traitCollectionDidChange(_:))).map { ... }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) override func viewDidLoad() { super.viewDidLoad() viewModel.initializeViews .bind(to: Binder(self) { me, _ in ... summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: me.disposeBag) me.contentStackView.addArrangedSubview(…) me.viewModel.stackAxis .bind(to: me.rootStackView.rx[\.axis]) .disposed(by: me.disposeBag) me.viewModel.addThumbnailToRoot .bind(to: Binder(me) { me, _ in guard let thumbnailView = me.lazyViews?.thumbnailView, !me.rootStackView.arrangedSubviews.contains(thumbnailView) else { return } if me.contentStackView.arrangedSubviews.contains(thumbnailView) { me.contentStackView.removeArrangedSubview(thumbnailView) thumbnailView.removeFromSuperview() } me.rootStackView.addArrangedSubview(thumbnailView) }) .disposed(by: me.disposeBag) me.viewModel.addThumbnailToContent .bind(to: ...) .disposed(by: me.disposeBag) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } }

Slide 136

Slide 136 text

final class DetailViewController: UIViewController { @IBOutlet weak var rootStackView: UIStackView! @IBOutlet weak var contentStackView: UIStackView! ... private var lazyViews: LazyViews? private let lazyRelays = LazyRelays() private lazy var viewModel = DetailViewModel( ... traitCollectionDidChange: rx.methodInvoked(#selector(traitCollectionDidChange(_:))).map { ... }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) override func viewDidLoad() { super.viewDidLoad() viewModel.initializeViews .bind(to: Binder(self) { me, _ in ... summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: me.disposeBag) me.contentStackView.addArrangedSubview(…) me.viewModel.stackAxis .bind(to: me.rootStackView.rx[\.axis]) .disposed(by: me.disposeBag) me.viewModel.addThumbnailToRoot .bind(to: Binder(me) { me, _ in guard let thumbnailView = me.lazyViews?.thumbnailView, !me.rootStackView.arrangedSubviews.contains(thumbnailView) else { return } if me.contentStackView.arrangedSubviews.contains(thumbnailView) { me.contentStackView.removeArrangedSubview(thumbnailView) thumbnailView.removeFromSuperview() } me.rootStackView.addArrangedSubview(thumbnailView) }) .disposed(by: me.disposeBag) me.viewModel.addThumbnailToContent .bind(to: ...) .disposed(by: me.disposeBag) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } }

Slide 137

Slide 137 text

class DetailViewModel { ... let isContentInfoHidden: Observable let readyForInitializingViews: Observable let stackAxis: Observable let addThumbnailToRoot: Observable let addThumbnailToContent: Observable init(..., traitCollectionDidChange: Observable, toggleContentInfo: Observable, didFinishInitializingViews: Observable) { ... let _isContentInfoHidden = BehaviorRelay(value: true) let _isPortrait = BehaviorRelay(value: true) ... self.isContentInfoHidden = _isContentInfoHidden.asObservable() self.stackAxis = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .map { $0 ? .vertical : .horizontal } self.addThumbnailToRoot = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .flatMap { $0 ? Observable.empty() : .just(()) } self.addThumbnailToContent = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .flatMap { $0 ? Observable.just(()) : .empty() } ... toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) traitCollectionDidChange .map { $0.verticalSizeClass == .regular && $0.horizontalSizeClass == .compact } .bind(to: _isPortrait) .disposed(by: disposeBag) } }

Slide 138

Slide 138 text

class DetailViewModel { ... let isContentInfoHidden: Observable let readyForInitializingViews: Observable let stackAxis: Observable let addThumbnailToRoot: Observable let addThumbnailToContent: Observable init(..., traitCollectionDidChange: Observable, toggleContentInfo: Observable, didFinishInitializingViews: Observable) { ... let _isContentInfoHidden = BehaviorRelay(value: true) let _isPortrait = BehaviorRelay(value: true) ... self.isContentInfoHidden = _isContentInfoHidden.asObservable() self.stackAxis = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .map { $0 ? .vertical : .horizontal } self.addThumbnailToRoot = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .flatMap { $0 ? Observable.empty() : .just(()) } self.addThumbnailToContent = Observable.combineLatest(didFinishInitializingViews.take(1), _isPortrait.asObservable()) { $1 } .flatMap { $0 ? Observable.just(()) : .empty() } ... toggleContentInfo.withLatestFrom(_isContentInfoHidden) { !$1 } .bind(to: _isContentInfoHidden) .disposed(by: disposeBag) traitCollectionDidChange .map { $0.verticalSizeClass == .regular && $0.horizontalSizeClass == .compact } .bind(to: _isPortrait) .disposed(by: disposeBag) } }

Slide 139

Slide 139 text

final class DetailViewController: UIViewController { @IBOutlet weak var rootStackView: UIStackView! @IBOutlet weak var contentStackView: UIStackView! ... private var lazyViews: LazyViews? private let lazyRelays = LazyRelays() private lazy var viewModel = DetailViewModel( ... traitCollectionDidChange: rx.methodInvoked(#selector(traitCollectionDidChange(_:))).map { ... }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) override func viewDidLoad() { super.viewDidLoad() viewModel.initializeViews .bind(to: Binder(self) { me, _ in ... summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: me.disposeBag) me.contentStackView.addArrangedSubview(…) me.viewModel.stackAxis .bind(to: me.rootStackView.rx[\.axis]) .disposed(by: me.disposeBag) me.viewModel.addThumbnailToRoot .bind(to: Binder(me) { me, _ in guard let thumbnailView = me.lazyViews?.thumbnailView, !me.rootStackView.arrangedSubviews.contains(thumbnailView) else { return } if me.contentStackView.arrangedSubviews.contains(thumbnailView) { me.contentStackView.removeArrangedSubview(thumbnailView) thumbnailView.removeFromSuperview() } me.rootStackView.addArrangedSubview(thumbnailView) }) .disposed(by: me.disposeBag) me.viewModel.addThumbnailToContent .bind(to: ...) .disposed(by: me.disposeBag) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } }

Slide 140

Slide 140 text

final class DetailViewController: UIViewController { @IBOutlet weak var rootStackView: UIStackView! @IBOutlet weak var contentStackView: UIStackView! ... private var lazyViews: LazyViews? private let lazyRelays = LazyRelays() private lazy var viewModel = DetailViewModel( ... traitCollectionDidChange: rx.methodInvoked(#selector(traitCollectionDidChange(_:))).map { ... }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) override func viewDidLoad() { super.viewDidLoad() viewModel.initializeViews .bind(to: Binder(self) { me, _ in ... summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.isContentInfoHidden .bind(to: summaryView.contentInfoView.rx.isHidden) .disposed(by: me.disposeBag) me.contentStackView.addArrangedSubview(…) me.viewModel.stackAxis .bind(to: me.rootStackView.rx[\.axis]) .disposed(by: me.disposeBag) me.viewModel.addThumbnailToRoot .bind(to: Binder(me) { me, _ in guard let thumbnailView = me.lazyViews?.thumbnailView, !me.rootStackView.arrangedSubviews.contains(thumbnailView) else { return } if me.contentStackView.arrangedSubviews.contains(thumbnailView) { me.contentStackView.removeArrangedSubview(thumbnailView) thumbnailView.removeFromSuperview() } me.rootStackView.addArrangedSubview(thumbnailView) }) .disposed(by: me.disposeBag) me.viewModel.addThumbnailToContent .bind(to: ...) .disposed(by: me.disposeBag) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } }

Slide 141

Slide 141 text

վળޙͷ࣮૷

Slide 142

Slide 142 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ VerticalStackView { CollectionView { DetailContentSection { ContentCell { ThumbnailView } ContentCell { SummaryView } ContentCell (Expand Only) { ContentInfoView } ContentCell { ActionButtonsView } ContentCell { EpisodeListView } } RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } VerticalStackView { ScrollView { VerticalStackView { ThumbnailView SummaryView { VerticalStackView { Label ContentInfoView (Expand Only) } } OtherView { VerticalStackView { ActionButtonsView EpisodeListView } } RecommendView { CollectionView { RecommendSection { RecommendCell RecommendCell ... } RecommendSection { RecommendCell RecommendCell ... } ... } } } } }

Slide 143

Slide 143 text

extension DetailViewController { class LazyViews { let thumbnailView: ThumbnailView let summaryView: SummaryView let contentInfoView: ContentInfoView let otherView: OtherView init(...) { ... } } class ContentCell: UICollectionViewCell { private weak var view: UIView? { didSet { oldValue?.removeFromSuperview() guard let view = view else { return } view.removeFromSuperview() contentView.addSubview(view) } } func setContentView(_ view: UIView) { guard self.view != view else { return } self.view = view } } }

Slide 144

Slide 144 text

extension DetailViewController { class LazyViews { let thumbnailView: ThumbnailView let summaryView: SummaryView let contentInfoView: ContentInfoView let otherView: OtherView init(...) { ... } } class ContentCell: UICollectionViewCell { private weak var view: UIView? { didSet { oldValue?.removeFromSuperview() guard let view = view else { return } view.removeFromSuperview() contentView.addSubview(view) } } func setContentView(_ view: UIView) { guard self.view != view else { return } self.view = view } } } wsummaryViewͷUIStackView্ʹ഑ஔ͞Ε͍ͯͨViewΛ෼཭

Slide 145

Slide 145 text

extension DetailViewController { class LazyViews { let thumbnailView: ThumbnailView let summaryView: SummaryView let contentInfoView: ContentInfoView let otherView: OtherView init(...) { ... } } class ContentCell: UICollectionViewCell { private weak var view: UIView? { didSet { oldValue?.removeFromSuperview() guard let view = view else { return } view.removeFromSuperview() contentView.addSubview(view) } } func setContentView(_ view: UIView) { guard self.view != view else { return } self.view = view } } } wLazyViewsͷViewΛUICollectionView্ʹ දࣔ͢ΔͨΊͷCell

Slide 146

Slide 146 text

import RxDataSources enum SectionModel: Hashable { case content([Item]) case recommend([Item]) enum Item: Hashable { case thumbnail case summary case contentInfo case other case recommend(IndexPath) } } extension SectionModel: AnimatableSectionModelType { var identity: AnyHashable { AnyHashable(self) } var items: [Item] { switch self { case let .content(items), let .recommend(items): return items } } init(original: SectionModel, items: [Item]) { switch original { case .content: self = .content(items) case .recommend: self = .recommend(items) } } } extension SectionModel.Item: IdentifiableType { var identity: AnyHashable { AnyHashable(self) } }

Slide 147

Slide 147 text

import RxDataSources enum SectionModel: Hashable { case content([Item]) case recommend([Item]) enum Item: Hashable { case thumbnail case summary case contentInfo case other case recommend(IndexPath) } } extension SectionModel: AnimatableSectionModelType { var identity: AnyHashable { AnyHashable(self) } var items: [Item] { switch self { case let .content(items), let .recommend(items): return items } } init(original: SectionModel, items: [Item]) { switch original { case .content: self = .content(items) case .recommend: self = .recommend(items) } } } extension SectionModel.Item: IdentifiableType { var identity: AnyHashable { AnyHashable(self) } } wίϯςϯπʹؔ͢ΔηΫγϣϯͱ Ϩίϝϯυʹؔ͢ΔηΫγϣϯΛදݱ

Slide 148

Slide 148 text

import RxDataSources enum SectionModel: Hashable { case content([Item]) case recommend([Item]) enum Item: Hashable { case thumbnail case summary case contentInfo case other case recommend(IndexPath) } } extension SectionModel: AnimatableSectionModelType { var identity: AnyHashable { AnyHashable(self) } var items: [Item] { switch self { case let .content(items), let .recommend(items): return items } } init(original: SectionModel, items: [Item]) { switch original { case .content: self = .content(items) case .recommend: self = .recommend(items) } } } extension SectionModel.Item: IdentifiableType { var identity: AnyHashable { AnyHashable(self) } } wίϯςϯπ·ͨ͸ϨίϝϯυͷηΫγϣϯͰ දࣔ͢ΔཁૉΛදݱ

Slide 149

Slide 149 text

final class DetailViewController: UIViewController { @IBOutlet weak var rootStackView: UIStackView! @IBOutlet weak var contentCollectionView: UICollectionView! ... private var lazyViews: LazyViews? private lazy var viewModel = DetailViewModel( ..., viewDidAppear: rx.methodInvoked(#selector(viewDidAppear(_:))).map { _ in }, traitCollectionDidChange: rx.methodInvoked(#selector(traitCollectionDidChange(_:))).map { ... }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) private typealias DataSource = RxCollectionViewSectionedAnimatedDataSource private lazy var dataSource = DataSource(configureCell: configureCell) private lazy var configureCell: DataSource.ConfigureCell = { [weak self] _, collectionView, indexPath, item in guard let me = self, let lazyView = me.lazyViews else { return collectionView.fallback() } switch item { case .thumbnail: let cell = collectionView.dequeueReusableCell(ContentCell.self, for: indexPath) cell.setContentView(lazyView.thumbnailView) return cell ... case let .recommend(indexPath): let cell = collectionView.dequeueReusableCell(RecommendCell.self, for: indexPath) cell.setEpisode(me.viewModel.recommendList.value[indexPath.row]) return cell } } }

Slide 150

Slide 150 text

final class DetailViewController: UIViewController { @IBOutlet weak var rootStackView: UIStackView! @IBOutlet weak var contentCollectionView: UICollectionView! ... private var lazyViews: LazyViews? private lazy var viewModel = DetailViewModel( ..., viewDidAppear: rx.methodInvoked(#selector(viewDidAppear(_:))).map { _ in }, traitCollectionDidChange: rx.methodInvoked(#selector(traitCollectionDidChange(_:))).map { ... }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) private typealias DataSource = RxCollectionViewSectionedAnimatedDataSource private lazy var dataSource = DataSource(configureCell: configureCell) private lazy var configureCell: DataSource.ConfigureCell = { [weak self] _, collectionView, indexPath, item in guard let me = self, let lazyView = me.lazyViews else { return collectionView.fallback() } switch item { case .thumbnail: let cell = collectionView.dequeueReusableCell(ContentCell.self, for: indexPath) cell.setContentView(lazyView.thumbnailView) return cell ... case let .recommend(indexPath): let cell = collectionView.dequeueReusableCell(RecommendCell.self, for: indexPath) cell.setEpisode(me.viewModel.recommendList.value[indexPath.row]) return cell } } }

Slide 151

Slide 151 text

final class DetailViewController: UIViewController { @IBOutlet weak var rootStackView: UIStackView! @IBOutlet weak var contentCollectionView: UICollectionView! ... private var lazyViews: LazyViews? private lazy var viewModel = DetailViewModel( ..., viewDidAppear: rx.methodInvoked(#selector(viewDidAppear(_:))).map { _ in }, traitCollectionDidChange: rx.methodInvoked(#selector(traitCollectionDidChange(_:))).map { ... }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) private typealias DataSource = RxCollectionViewSectionedAnimatedDataSource private lazy var dataSource = DataSource(configureCell: configureCell) private lazy var configureCell: DataSource.ConfigureCell = { [weak self] _, collectionView, indexPath, item in guard let me = self, let lazyView = me.lazyViews else { return collectionView.fallback() } switch item { case .thumbnail: let cell = collectionView.dequeueReusableCell(ContentCell.self, for: indexPath) cell.setContentView(lazyView.thumbnailView) return cell ... case let .recommend(indexPath): let cell = collectionView.dequeueReusableCell(RecommendCell.self, for: indexPath) cell.setEpisode(me.viewModel.recommendList.value[indexPath.row]) return cell } } }

Slide 152

Slide 152 text

final class DetailViewController: UIViewController { @IBOutlet weak var rootStackView: UIStackView! @IBOutlet weak var contentCollectionView: UICollectionView! ... private var lazyViews: LazyViews? private lazy var viewModel = DetailViewModel( ..., viewDidAppear: rx.methodInvoked(#selector(viewDidAppear(_:))).map { _ in }, traitCollectionDidChange: rx.methodInvoked(#selector(traitCollectionDidChange(_:))).map { ... }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) private typealias DataSource = RxCollectionViewSectionedAnimatedDataSource private lazy var dataSource = DataSource(configureCell: configureCell) private lazy var configureCell: DataSource.ConfigureCell = { [weak self] _, collectionView, indexPath, item in guard let me = self, let lazyView = me.lazyViews else { return collectionView.fallback() } switch item { case .thumbnail: let cell = collectionView.dequeueReusableCell(ContentCell.self, for: indexPath) cell.setContentView(lazyView.thumbnailView) return cell ... case let .recommend(indexPath): let cell = collectionView.dequeueReusableCell(RecommendCell.self, for: indexPath) cell.setEpisode(me.viewModel.recommendList.value[indexPath.row]) return cell } } }

Slide 153

Slide 153 text

final class DetailViewController: UIViewController { @IBOutlet weak var rootStackView: UIStackView! @IBOutlet weak var contentCollectionView: UICollectionView! ... private var lazyViews: LazyViews? private lazy var viewModel = DetailViewModel( ..., viewDidAppear: rx.methodInvoked(#selector(viewDidAppear(_:))).map { _ in }, traitCollectionDidChange: rx.methodInvoked(#selector(traitCollectionDidChange(_:))).map { ... }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) private typealias DataSource = RxCollectionViewSectionedAnimatedDataSource private lazy var dataSource = DataSource(configureCell: configureCell) private lazy var configureCell: DataSource.ConfigureCell = { [weak self] _, collectionView, indexPath, item in guard let me = self, let lazyView = me.lazyViews else { return collectionView.fallback() } switch item { case .thumbnail: let cell = collectionView.dequeueReusableCell(ContentCell.self, for: indexPath) cell.setContentView(lazyView.thumbnailView) return cell ... case let .recommend(indexPath): let cell = collectionView.dequeueReusableCell(RecommendCell.self, for: indexPath) cell.setEpisode(me.viewModel.recommendList.value[indexPath.row]) return cell } } } wཁૉʹ֘౰͢ΔCellΛdequeue͠LazyViews ͔ΒରԠ͢ΔViewΛઃఆ͢Δ

Slide 154

Slide 154 text

final class DetailViewController: UIViewController { @IBOutlet weak var rootStackView: UIStackView! @IBOutlet weak var contentCollectionView: UICollectionView! ... private var lazyViews: LazyViews? private lazy var viewModel = DetailViewModel( ..., viewDidAppear: rx.methodInvoked(#selector(viewDidAppear(_:))).map { _ in }, traitCollectionDidChange: rx.methodInvoked(#selector(traitCollectionDidChange(_:))).map { ... }, toggleContentInfo: lazyRelays.didTapContentInfo.asObservable(), didFinishInitializingViews: lazyRelays.didFinishInitializingViews.asObservable() ) private typealias DataSource = RxCollectionViewSectionedAnimatedDataSource private lazy var dataSource = DataSource(configureCell: configureCell) private lazy var configureCell: DataSource.ConfigureCell = { [weak self] _, collectionView, indexPath, item in guard let me = self, let lazyView = me.lazyViews else { return collectionView.fallback() } switch item { case .thumbnail: let cell = collectionView.dequeueReusableCell(ContentCell.self, for: indexPath) cell.setContentView(lazyView.thumbnailView) return cell ... case let .recommend(indexPath): let cell = collectionView.dequeueReusableCell(RecommendCell.self, for: indexPath) cell.setEpisode(me.viewModel.recommendList.value[indexPath.row]) return cell } } } wϨίϝϯυͷCellΛdequeue͠ίϯςϯπ৘ใΛઃఆ͢Δ

Slide 155

Slide 155 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Property<[Episode]> let readyForInitializingViews: Observable let stackAxis: Observable let addThumbnailToRoot: Observable let sectionModels: Observable<[SectionModel]> init(..., traitCollectionDidChange: Observable, toggleContentInfo: Observable, didFinishInitializingViews: Observable) { let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) let _isPortrait = BehaviorRelay(value: true) let _sectionModels = BehaviorRelay<[SectionModel]>(value: []) self.sectionModels = Observable.combineLatest(didFinishInitializingViews.take(1), _sectionModels.asObservable()) { $1 } self.recommendList = Property(_recommendList) ... Observable.combineLatest(_isPortrait, _isContentInfoHidden, _recommendList) .map { isPortrait, isContentInfoHidden, recommendList -> [SectionModel] in let contentItems: [SectionModel.Item] = [ isPortrait ? .thumbnail : nil, .summary, isContentInfoHidden ? nil : .contentInfo, .other, .episodeList ].compactMap { $0 } let recommendSections: [SectionModel] if recommendList.isEmpty { recommendSections = [] } else { recommendSections = [.recommend( recommendList.enumerated().map { args in .recommend(IndexPath(row: args.offset, section: 0)) } )] } return [SectionModel.content(contentItems)] + recommendSections } .bind(to: _sectionModels) .disposed(by: disposeBag) ... } }

Slide 156

Slide 156 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Property<[Episode]> let readyForInitializingViews: Observable let stackAxis: Observable let addThumbnailToRoot: Observable let sectionModels: Observable<[SectionModel]> init(..., traitCollectionDidChange: Observable, toggleContentInfo: Observable, didFinishInitializingViews: Observable) { let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) let _isPortrait = BehaviorRelay(value: true) let _sectionModels = BehaviorRelay<[SectionModel]>(value: []) self.sectionModels = Observable.combineLatest(didFinishInitializingViews.take(1), _sectionModels.asObservable()) { $1 } self.recommendList = Property(_recommendList) ... Observable.combineLatest(_isPortrait, _isContentInfoHidden, _recommendList) .map { isPortrait, isContentInfoHidden, recommendList -> [SectionModel] in let contentItems: [SectionModel.Item] = [ isPortrait ? .thumbnail : nil, .summary, isContentInfoHidden ? nil : .contentInfo, .other, .episodeList ].compactMap { $0 } let recommendSections: [SectionModel] if recommendList.isEmpty { recommendSections = [] } else { recommendSections = [.recommend( recommendList.enumerated().map { args in .recommend(IndexPath(row: args.offset, section: 0)) } )] } return [SectionModel.content(contentItems)] + recommendSections } .bind(to: _sectionModels) .disposed(by: disposeBag) ... } } wViewͷ஗ԆॳظԽ͕׬ྃͨ͠ΒsectionModelΛൃՐ

Slide 157

Slide 157 text

class DetailViewModel { let episodeDetail: Observable let recommendList: Property<[Episode]> let readyForInitializingViews: Observable let stackAxis: Observable let addThumbnailToRoot: Observable let sectionModels: Observable<[SectionModel]> init(..., traitCollectionDidChange: Observable, toggleContentInfo: Observable, didFinishInitializingViews: Observable) { let _recommendList = BehaviorRelay<[Episode]>(value: []) let _isContentInfoHidden = BehaviorRelay(value: true) let _isPortrait = BehaviorRelay(value: true) let _sectionModels = BehaviorRelay<[SectionModel]>(value: []) self.sectionModels = Observable.combineLatest(didFinishInitializingViews.take(1), _sectionModels.asObservable()) { $1 } self.recommendList = Property(_recommendList) ... Observable.combineLatest(_isPortrait, _isContentInfoHidden, _recommendList) .map { isPortrait, isContentInfoHidden, recommendList -> [SectionModel] in let contentItems: [SectionModel.Item] = [ isPortrait ? .thumbnail : nil, .summary, isContentInfoHidden ? nil : .contentInfo, .other, .episodeList ].compactMap { $0 } let recommendSections: [SectionModel] if recommendList.isEmpty { recommendSections = [] } else { recommendSections = [.recommend( recommendList.enumerated().map { args in .recommend(IndexPath(row: args.offset, section: 0)) } )] } return [SectionModel.content(contentItems)] + recommendSections } .bind(to: _sectionModels) .disposed(by: disposeBag) ... } } wঢ়ଶ͕ߋ৽͞ΕΔͱ഑ྻͷ಺༰΋ߋ৽

Slide 158

Slide 158 text

final class DetailViewController: UIViewController { ... override func viewDidLoad() { super.viewDidLoad() viewModel.readyForInitializingViews .bind(to: Binder(self) { me, _ in let thumbnailView = ThumbnailView.makeFromNib() let summaryView = SummaryView.makeFromNib() me.viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: me.disposeBag) summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.stackAxis .bind(to: me.rootStackView.rx[\.axis]) .disposed(by: me.disposeBag) me.viewModel.addThumbnailToRoot .bind(to: Binder(me) { me, _ in guard let thumbnailView = me.lazyViews?.thumbnailView, !me.rootStackView.arrangedSubviews.contains(thumbnailView) else { return } thumbnailView.removeFromSuperview() me.rootStackView.addArrangedSubview(thumbnailView) }) .disposed(by: me.disposeBag) me.viewModel.sectionModels .bind(to: me.contentCollectionView.rx.items(dataSource: me.dataSource)) .disposed(by: me.disposeBag) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } }

Slide 159

Slide 159 text

final class DetailViewController: UIViewController { ... override func viewDidLoad() { super.viewDidLoad() viewModel.readyForInitializingViews .bind(to: Binder(self) { me, _ in let thumbnailView = ThumbnailView.makeFromNib() let summaryView = SummaryView.makeFromNib() me.viewModel.episodeDetail .bind(to: Binder(summaryView) { $0.setEpisode($1) }) .disposed(by: me.disposeBag) summaryView.didTapContentInfo .bind(to: me.lazyRelays.didTapContentInfo) .disposed(by: me.disposeBag) me.viewModel.stackAxis .bind(to: me.rootStackView.rx[\.axis]) .disposed(by: me.disposeBag) me.viewModel.addThumbnailToRoot .bind(to: Binder(me) { me, _ in guard let thumbnailView = me.lazyViews?.thumbnailView, !me.rootStackView.arrangedSubviews.contains(thumbnailView) else { return } thumbnailView.removeFromSuperview() me.rootStackView.addArrangedSubview(thumbnailView) }) .disposed(by: me.disposeBag) me.viewModel.sectionModels .bind(to: me.contentCollectionView.rx.items(dataSource: me.dataSource)) .disposed(by: me.disposeBag) me.lazyViews = LazyViews(...) me.lazyRelays.didFinishInitializingViews.accept(()) }) .disposed(by: disposeBag) } } wࠓճͷ৔߹RxDataSourcesΛར༻͍ͯ͠ΔͷͰ ࠩ෼ߋ৽ͰΞχϝʔγϣϯ෇͖Ͱը໘Λඳը

Slide 160

Slide 160 text

վળޙͷը໘ճస଎౓

Slide 161

Slide 161 text

ը໘ճస଎౓ վળޙ ˞ճ࣮ࢪ iPhone 8 iOS12 ࠷খ 858ms ฏۉ 897ms ࠷େ 1140ms

Slide 162

Slide 162 text

ը໘ճస଎౓ ˞ճ࣮ࢪ iPhone 8 iOS12 ࠷খ 1100ms→858ms ฏۉ 1130ms→897ms ࠷େ 1300ms→1140ms

Slide 163

Slide 163 text

վળ఺ͷҰཡ w UIScrollView + UIStackViewͷߏ੒͔ΒUICollectionViewʹมߋ w ֤View͔ΒUIStackView + arrangedSubviewsͷ࣮૷ΛผViewʹ෼཭ w UIStackViewͷarrangedSubviewͷisHiddenʹΑΔϨΠΞ΢τߋ৽Λ ࠩ෼ߋ৽ϥΠϒϥϦΛ༻͍ͨUICollectionViewͷΞχϝʔγϣϯʹมߋ

Slide 164

Slide 164 text

ߏ଄มߋʹΑΔ෭࣍తͳޮՌ

Slide 165

Slide 165 text

ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ΤϐιʔυҰཡ ΋ͬͱΈΔʼ ϚΠϏσΦ μ΢ϯϩʔυ γΣΞ ฒͼସ͑ ABςετΛ࣮ࢪ

Slide 166

Slide 166 text

enum SectionModel: Hashable { case content([Item]) case recommend([Item]) enum Item: Hashable { case thumbnail case summary case contentInfo case other case episodeList case recommend(IndexPath) case recommendList(IndexPath) } } final class DetailViewController: UIViewController { ... private lazy var configureCell: DataSource.ConfigureCell = { [weak self] _, collectionView, indexPath, item in ... switch item { ... case let .recommend(indexPath): let cell = collectionView.dequeueReusableCell(RecommendCell.self, for: indexPath) cell.setEpisode(me.viewModel.recommendList.value[indexPath.row]) return cell case let .recommendList(indexPath): let cell = collectionView.dequeueReusableCell(RecommendListCell.self, for: indexPath) cell.setEpisode(me.viewModel.recommendList.value[indexPath.row]) return cell } } }

Slide 167

Slide 167 text

enum SectionModel: Hashable { case content([Item]) case recommend([Item]) enum Item: Hashable { case thumbnail case summary case contentInfo case other case episodeList case recommend(IndexPath) case recommendList(IndexPath) } } final class DetailViewController: UIViewController { ... private lazy var configureCell: DataSource.ConfigureCell = { [weak self] _, collectionView, indexPath, item in ... switch item { ... case let .recommend(indexPath): let cell = collectionView.dequeueReusableCell(RecommendCell.self, for: indexPath) cell.setEpisode(me.viewModel.recommendList.value[indexPath.row]) return cell case let .recommendList(indexPath): let cell = collectionView.dequeueReusableCell(RecommendListCell.self, for: indexPath) cell.setEpisode(me.viewModel.recommendList.value[indexPath.row]) return cell } } } wABςετͷର৅ͱͳΔཁૉͱ࣮૷ͷ௥Ճ

Slide 168

Slide 168 text

class DetailViewModel { ... init(..., abtestManager: ABTestManger, ...) { ... Observable.combineLatest(_isPortrait, _isContentInfoHidden, _recommendList) .map { isPortrait, isContentInfoHidden, recommendList -> [SectionModel] in let contentItems: [SectionModel.Item] = [ isPortrait ? .thumbnail : nil, .summary, isContentInfoHidden ? nil : .contentInfo, .other, .episodeList ].compactMap { $0 } let recommendSections: [SectionModel] if recommendList.isEmpty { recommendSections = [] } else { let recommendItems: [SectionModel.Item] switch abtestManager.recommendPattern { case .list: recommendItems = recommendList.enumerated().map { args in .recommendList(IndexPath(row: args.offset, section: 0)) } case .grid: recommendItems = recommendList.enumerated().map { args in .recommend(IndexPath(row: args.offset, section: 0)) } } recommendSections = [.recommend(recommendItems)] } return [SectionModel.content(contentItems)] + recommendSections } .bind(to: _sectionModels) .disposed(by: disposeBag) } }

Slide 169

Slide 169 text

class DetailViewModel { ... init(..., abtestManager: ABTestManger, ...) { ... Observable.combineLatest(_isPortrait, _isContentInfoHidden, _recommendList) .map { isPortrait, isContentInfoHidden, recommendList -> [SectionModel] in let contentItems: [SectionModel.Item] = [ isPortrait ? .thumbnail : nil, .summary, isContentInfoHidden ? nil : .contentInfo, .other, .episodeList ].compactMap { $0 } let recommendSections: [SectionModel] if recommendList.isEmpty { recommendSections = [] } else { let recommendItems: [SectionModel.Item] switch abtestManager.recommendPattern { case .list: recommendItems = recommendList.enumerated().map { args in .recommendList(IndexPath(row: args.offset, section: 0)) } case .grid: recommendItems = recommendList.enumerated().map { args in .recommend(IndexPath(row: args.offset, section: 0)) } } recommendSections = [.recommend(recommendItems)] } return [SectionModel.content(contentItems)] + recommendSections } .bind(to: _sectionModels) .disposed(by: disposeBag) } } wABςετͷঢ়ଶʹΑͬͯ௥Ճ͢ΔཁૉΛมߋ

Slide 170

Slide 170 text

·ͱΊ

Slide 171

Slide 171 text

·ͱΊ w Xib͸ॳճϩʔυʹେ෯ʹ͕͔͔࣌ؒΔ w ը໘ͷදࣔ଎౓͕஗͘ͳͬͨ৔߹ʹViewͷੜ੒Λ஗Ԇͤ͞ΔͱޮՌ͕ग़΍͍͢ ʢbindͨ͠௚ޙʹॲཧ͕ൃՐ͠ɺϨΠΞ΢τॲཧ͕࣮ߦ͞Εͨ͜ͱʹΑͬͯදࣔ ͕஗Ԇͯ͠͠·͍ͬͯͨՄೳੑ΋͋Δʣ w UICollectionViewʢ·ͨ͸UITableViewʣͰσʔλιʔεͷड͚౉͠Λ஗Ԇͤ͞Ε ͹ɺViewͷੜ੒Λ஗Ԇͤ͞Δ͜ͱ΋Ͱ͖Δ w σʔλιʔεΛએݴతʹ͢Δ͜ͱͰɺϞδϡʔϧͷೖΕସ͑΍௥Ճ͕؆୯ʹͳΔ

Slide 172

Slide 172 text

͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠