Skip to content

Commit

Permalink
Update docs and template for ViewEnvironment
Browse files Browse the repository at this point in the history
  • Loading branch information
bencochran committed Mar 4, 2020
1 parent 25c241e commit 6a46f0e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
16 changes: 10 additions & 6 deletions docs/tutorial/building-a-view-controller-from-screen.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ controller from a view model update.
struct DemoScreen: Screen {
let title: String
let onTap: () -> Void

func viewControllerDescription(environment: ViewEnvironment) -> ViewControllerDescription {
return DemoScreenViewController.description(for: self, environment: environment)
}
}


class DemoScreenViewController: ScreenViewController<DemoScreen> {

private let button: UIButton

required init(screen: DemoScreen) {
required init(screen: DemoScreen, environment: ViewEnvironment) {
button = UIButton()
super.init(screen: screen)
super.init(screen: screen, environment: environment)

update(screen: screen)
}
Expand All @@ -39,8 +43,8 @@ class DemoScreenViewController: ScreenViewController<DemoScreen> {
button.frame = view.bounds
}

override func screenDidChange(from previousScreen: DemoScreen) {
super.screenDidChange(from: previousScreen)
override func screenDidChange(from previousScreen: DemoScreen, previousEnvironment: ViewEnvironment) {
super.screenDidChange(from: previousScreen, previousEnvironment: previousEnvironment)
update(screen: screen)
}

Expand All @@ -64,5 +68,5 @@ class DemoScreenViewController: ScreenViewController<DemoScreen> {
1. The button is tapped. When the callback is called, we call the `onTap` closure passed into the
screen. The workflow will handle this event, update its state, and a new screen will be rendered.
1. The updated screen is passed to the view controller via the
`screenDidChange(from previousScreen:)` method. Again, the view controller updates the title of
the button based on what was passed in the screen.
`screenDidChange(from previousScreen: previousEnvironment: previousEnvironment:)` method. Again,
the view controller updates the title of the button based on what was passed in the screen.
4 changes: 2 additions & 2 deletions swift/Samples/Tutorial/Tutorial1.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ struct WelcomeScreen: Screen {
/// Callback when the login button is tapped.
var onLoginTapped: () -> Void

var viewControllerDescription: ViewControllerDescription {
return WelcomeViewController.description(for: self)
func viewControllerDescription(environment: ViewEnvironment) -> ViewControllerDescription {
return WelcomeViewController.description(for: self, environment: environment)
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions swift/Samples/Tutorial/Tutorial3.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ The `Screen` protocol also requires a `viewControllerDescription` property. This

```swift
extension TodoEditScreen {
var viewControllerDescription: ViewControllerDescription {
TodoEditViewController.description(for: self)
func viewControllerDescription(environment: ViewEnvironment) -> ViewControllerDescription {
TodoEditViewController.description(for: self, environment: environment)
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ struct ___VARIABLE_productName___Screen: Screen {
// It should also contain callbacks for any UI events, for example:
// var onButtonTapped: () -> Void

var viewControllerDescription: ViewControllerDescription {
return ___VARIABLE_productName___ViewController.description(for: self)
func viewControllerDescription(environment: ViewEnvironment) -> ViewControllerDescription {
return ___VARIABLE_productName___ViewController.description(for: self, environment: environment)
}
}


final class ___VARIABLE_productName___ViewController: ScreenViewController<___VARIABLE_productName___Screen> {

required init(screen: ___VARIABLE_productName___Screen) {
super.init(screen: screen)
update(with: screen)
required init(screen: ___VARIABLE_productName___Screen, environment: ViewEnvironment) {
super.init(screen: screen, environment: environment)
update(with: screen, environment: environment)
}

override func screenDidChange(from previousScreen: ___VARIABLE_productName___Screen) {
update(with: screen)
override func screenDidChange(from previousScreen: ___VARIABLE_productName___Screen, previousEnvironment: ViewEnvironment) {
update(with: screen, environment: environment)
}

private func update(with screen: ___VARIABLE_productName___Screen) {
private func update(with screen: ___VARIABLE_productName___Screen, environment: ViewEnvironment) {
/// Update UI
}

Expand Down
4 changes: 2 additions & 2 deletions swift/WorkflowUI/Sources/Screen/ScreenViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import UIKit
/// Using this base class, a screen can be implemented as:
/// ```
/// struct MyScreen: Screen {
/// var viewControllerDescription: ViewControllerDescription {
/// func viewControllerDescription(environment: ViewEnvironment) -> ViewControllerDescription {
/// return MyScreenViewController.description(for: self)
/// }
/// }
///
/// private class MyScreenViewController: ScreenViewController<MyScreen> {
/// override func screenDidChange(from previousScreen: MyScreen) {
/// override func screenDidChange(from previousScreen: MyScreen, previousEnvironment: ViewEnvironment) {
/// // … update views as necessary
/// }
/// }
Expand Down

0 comments on commit 6a46f0e

Please sign in to comment.