Skip to content

Commit

Permalink
More navigation clean ups. Yay, for adaptive layout.
Browse files Browse the repository at this point in the history
  • Loading branch information
twostraws committed May 4, 2019
1 parent 7c62506 commit c353db7
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 62 deletions.
15 changes: 7 additions & 8 deletions Unwrap/Activities/Awards/AwardPointsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import UIKit

/// The view controller that handles visually awarding points to users.
class AwardPointsViewController: UIViewController, Storyboarded {
var coordinator: Awarding?
var coordinator: Awarding? {
didSet {
configureNavigation()
}
}

@IBOutlet var statusView: StatusView!
@IBOutlet var totalPoints: CountingLabel!
Expand All @@ -28,14 +32,9 @@ class AwardPointsViewController: UIViewController, Storyboarded {
return .lightContent
}

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
fatalError("Not implemented")
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
/// Run all our navigation bar code super early to avoid bad animations on iPhone
func configureNavigation() {
navigationItem.largeTitleDisplayMode = .never

}

override func viewDidLoad() {
Expand Down
2 changes: 1 addition & 1 deletion Unwrap/Activities/Challenges/ChallengesCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class ChallengesCoordinator: Coordinator, Awarding, Skippable, AnswerHandling {
func askQuestion() {
if let currentQuestion = questions.popLast() {
let viewController = currentQuestion.instantiate()
viewController.coordinator = self
viewController.questionNumber = 10 - questions.count
viewController.coordinator = self

let detailNav = CoordinatedNavigationController(rootViewController: viewController)
splitViewController.showDetailViewController(detailNav, sender: self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ class MultipleSelectReviewViewController: ReviewViewController, Storyboarded {

var dataSource: MultipleSelectReviewDataSource!

/// Run all our navigation bar code super early to avoid bad animations on iPhone
override func configureNavigation() {
super.configureNavigation()
title = getTitle()
}

override func viewDidLoad() {
super.viewDidLoad()

title = getTitle()
dataSource = MultipleSelectReviewDataSource(review: review)
tableView.dataSource = dataSource
tableView.delegate = dataSource
Expand Down
17 changes: 7 additions & 10 deletions Unwrap/Activities/Learn/Review/ReviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import UIKit

class ReviewViewController: UIViewController, PracticingViewController {
var coordinator: (AnswerHandling & Skippable)?
var coordinator: (AnswerHandling & Skippable)? {
didSet {
configureNavigation()
}
}

var questionNumber = 1

Expand All @@ -18,14 +22,8 @@ class ReviewViewController: UIViewController, PracticingViewController {
var sectionName = ""
var review: StudyReview!

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
fatalError("Not implemented")
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

// We need to configure our navigation items super early to avoid janky animations thanks to our adaptive layout
/// Run all our navigation bar code super early to avoid bad animations on iPhone
func configureNavigation() {
navigationItem.largeTitleDisplayMode = .never
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Skip", style: .plain, target: self, action: #selector(skip))
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Hint", style: .plain, target: self, action: #selector(hint))
Expand All @@ -34,7 +32,6 @@ class ReviewViewController: UIViewController, PracticingViewController {

override func viewDidLoad() {
super.viewDidLoad()

assert(coordinator != nil, "You must set a coordinator before presenting this view controller.")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ class SingleSelectReviewViewController: ReviewViewController, Storyboarded {
/// A lexer to highlight our source code.
let lexer = SwiftLexer()

/// Run all our navigation bar code super early to avoid bad animations on iPhone
override func configureNavigation() {
super.configureNavigation()
title = "Review" + (coordinator?.titleSuffix(for: self) ?? "")
}

override func viewDidLoad() {
super.viewDidLoad()

title = "Review" + (coordinator?.titleSuffix(for: self) ?? "")
prompt.attributedText = review.question.fromSimpleHTML()

code.theme = User.current.sourceCodeTheme
Expand Down
19 changes: 9 additions & 10 deletions Unwrap/Activities/Learn/Study/StudyViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ import UIKit

/// Responsible for showing one chapter of the book as text.
class StudyViewController: UIViewController, TappableTextViewDelegate {
var coordinator: LearnCoordinator?
var coordinator: LearnCoordinator? {
didSet {
configureNavigation()
}
}

var studyTextView = StudyTextView()
var chapter = ""

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
func configureNavigation() {
navigationItem.largeTitleDisplayMode = .never
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
extendedLayoutIncludesOpaqueBars = true
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Next", style: .plain, target: coordinator, action: #selector(LearnCoordinator.finishedStudying))
}

override func loadView() {
Expand All @@ -33,9 +35,6 @@ class StudyViewController: UIViewController, TappableTextViewDelegate {

assert(coordinator != nil, "You must set a coordinator before presenting this view controller.")

extendedLayoutIncludesOpaqueBars = true
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Next", style: .plain, target: coordinator, action: #selector(LearnCoordinator.finishedStudying))

// always include the safe area insets in the scroll view content adjustment
studyTextView.contentInsetAdjustmentBehavior = .always
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import UIKit

/// The view controller that handles Free Coding practice activities.
class FreeCodingViewController: UIViewController, Storyboarded, PracticingViewController {
var coordinator: (Skippable & AnswerHandling)?
var coordinator: (Skippable & AnswerHandling)? {
didSet {
configureNavigation()
}
}

var practiceType = "free-coding"

@IBOutlet var prompt: UILabel!
Expand All @@ -30,9 +35,8 @@ class FreeCodingViewController: UIViewController, Storyboarded, PracticingViewCo
let lexer = SwiftLexer()

/// Run all our navigation bar code super early to avoid bad animations on iPhone
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

func configureNavigation() {
title = "Free Coding" + (coordinator?.titleSuffix(for: self) ?? "")
navigationItem.largeTitleDisplayMode = .never
extendedLayoutIncludesOpaqueBars = true

Expand All @@ -47,8 +51,6 @@ class FreeCodingViewController: UIViewController, Storyboarded, PracticingViewCo
assert(coordinator != nil, "You must set a coordinator before presenting this view controller.")
assert(practiceData != nil, "You must assign some practice data before presenting this view controller.")

title = "Free Coding" + (coordinator?.titleSuffix(for: self) ?? "")

// The prompt can only be simple HTML (e.g. <code></code>), but the source code is fully syntax highlighted.
prompt.attributedText = practiceData.question.fromSimpleHTML()
textView.theme = User.current.sourceCodeTheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PredictTheOutputViewController: UIViewController, Storyboarded, Practicing
var questionNumber = 1

/// Run all our navigation bar code super early to avoid bad animations on iPhone
private func configureNavigation() {
func configureNavigation() {
title = "Predict the Output" + (coordinator?.titleSuffix(for: self) ?? "")
navigationItem.largeTitleDisplayMode = .never
extendedLayoutIncludesOpaqueBars = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import UIKit

/// The view controller that handles Rearrange the Lines practice activities.
class RearrangeTheLinesViewController: UIViewController, Storyboarded, PracticingViewController {
var coordinator: (Skippable & AnswerHandling)?
var coordinator: (Skippable & AnswerHandling)? {
didSet {
configureNavigation()
}
}

var practiceType = "rearrange-the-lines"

@IBOutlet var prompt: UILabel!
Expand All @@ -27,9 +32,8 @@ class RearrangeTheLinesViewController: UIViewController, Storyboarded, Practicin
var questionNumber = 1

/// Run all our navigation bar code super early to avoid bad animations on iPhone
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

func configureNavigation() {
title = "Rearrange the Lines" + (coordinator?.titleSuffix(for: self) ?? "")
navigationItem.largeTitleDisplayMode = .never
extendedLayoutIncludesOpaqueBars = true

Expand All @@ -44,8 +48,6 @@ class RearrangeTheLinesViewController: UIViewController, Storyboarded, Practicin
assert(coordinator != nil, "You must set a coordinator before presenting this view controller.")
assert(practiceData != nil, "You must assign some practice data before presenting this view controller.")

title = "Rearrange the Lines" + (coordinator?.titleSuffix(for: self) ?? "")

dataSource = RearrangeTheLinesDataSource(practiceData: practiceData)
tableView.dataSource = dataSource
tableView.delegate = dataSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import UIKit

/// The view controller that handles Spot the Error practice activities.
class SpotTheErrorViewController: UIViewController, Storyboarded, PracticingViewController {
var coordinator: (Skippable & AnswerHandling)?
var coordinator: (Skippable & AnswerHandling)? {
didSet {
configureNavigation()
}
}

var practiceType = "spot-the-error"

@IBOutlet var prompt: UILabel!
Expand All @@ -27,9 +32,8 @@ class SpotTheErrorViewController: UIViewController, Storyboarded, PracticingView
var questionNumber = 1

/// Run all our navigation bar code super early to avoid bad animations on iPhone
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

func configureNavigation() {
title = "Spot the Error" + (coordinator?.titleSuffix(for: self) ?? "")
navigationItem.largeTitleDisplayMode = .never
extendedLayoutIncludesOpaqueBars = true

Expand All @@ -44,8 +48,6 @@ class SpotTheErrorViewController: UIViewController, Storyboarded, PracticingView
assert(coordinator != nil, "You must set a coordinator before presenting this view controller.")
assert(practiceData != nil, "You must assign some practice data before presenting this view controller.")

title = "Spot the Error" + (coordinator?.titleSuffix(for: self) ?? "")

dataSource = SpotTheErrorDataSource(practiceData: practiceData)
dataSource.delegate = self
tableView.dataSource = dataSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import UIKit

/// The view controller that handles Tap to Code practice activities.
class TapToCodeViewController: UIViewController, Storyboarded, PracticingViewController {
var coordinator: (Skippable & AnswerHandling)?
var coordinator: (Skippable & AnswerHandling)? {
didSet {
configureNavigation()
}
}

var practiceType = "tap-to-code"

@IBOutlet var prompt: UILabel!
Expand All @@ -37,9 +42,8 @@ class TapToCodeViewController: UIViewController, Storyboarded, PracticingViewCon
var questionNumber = 1

/// Run all our navigation bar code super early to avoid bad animations on iPhone
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

func configureNavigation() {
title = "Tap to Code" + (coordinator?.titleSuffix(for: self) ?? "")
navigationItem.largeTitleDisplayMode = .never
extendedLayoutIncludesOpaqueBars = true

Expand All @@ -54,8 +58,6 @@ class TapToCodeViewController: UIViewController, Storyboarded, PracticingViewCon
assert(coordinator != nil, "You must set a coordinator before presenting this view controller.")
assert(practiceData != nil, "You must assign some practice data before presenting this view controller.")

title = "Tap to Code" + (coordinator?.titleSuffix(for: self) ?? "")

if practiceData.existingCode.isEmpty {
// Hide the existing code label and disable the collection view constraint that positions it below. This will make Auto Layout rely on a second vertical spacing constraint that positions the collection view relative to the prompt view.
existingCode.isHidden = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import UIKit

/// The view controller that handles Type Checker practice activities.
class TypeCheckerViewController: UIViewController, Storyboarded, PracticingViewController {
var coordinator: (Skippable & AnswerHandling)?
var coordinator: (Skippable & AnswerHandling)? {
didSet {
configureNavigation()
}
}

var practiceType = "type-practice"

@IBOutlet var prompt: UILabel!
Expand All @@ -27,9 +32,8 @@ class TypeCheckerViewController: UIViewController, Storyboarded, PracticingViewC
var questionNumber = 1

/// Run all our navigation bar code super early to avoid bad animations on iPhone
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

func configureNavigation() {
title = "Type Practice" + (coordinator?.titleSuffix(for: self) ?? "")
navigationItem.largeTitleDisplayMode = .never
extendedLayoutIncludesOpaqueBars = true

Expand All @@ -43,8 +47,6 @@ class TypeCheckerViewController: UIViewController, Storyboarded, PracticingViewC

assert(coordinator != nil, "You must set a coordinator before presenting this view controller.")

title = "Type Practice" + (coordinator?.titleSuffix(for: self) ?? "")

// Users need to be able to check all the rows they want, so our data source is used for the table view's data source and delegate.
dataSource = TypeCheckerDataSource(review: review)
tableView.dataSource = dataSource
Expand Down

0 comments on commit c353db7

Please sign in to comment.