Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit d9fcef5

Browse files
authored
Route includes presentation style (#2447)
* route includes presentation style * attach router
1 parent c767399 commit d9fcef5

11 files changed

+92
-31
lines changed

Classes/Image Upload/ImageUploadTableViewController.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ class ImageUploadTableViewController: UITableViewController {
202202
}
203203

204204
@IBAction func didPressPreviewImage() {
205-
let previewViewController = NYTPhotosViewController(photos: [IssueCommentPhoto(image: image, data: nil)])
206-
present(previewViewController, animated: trueUnlessReduceMotionEnabled)
205+
route_present(to: NYTPhotosViewController(photos: [IssueCommentPhoto(image: image, data: nil)]))
207206
}
208207
}
209208

Classes/Issues/Comments/IssueCommentSectionController.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ final class IssueCommentSectionController: ListBindingSectionController<IssueCom
136136
edit.delegate = self
137137
let nav = UINavigationController(rootViewController: edit)
138138
nav.modalPresentationStyle = .formSheet
139-
self?.viewController?.present(nav, animated: trueUnlessReduceMotionEnabled)
139+
self?.viewController?.route_present(to: nav)
140140
})
141141
}
142142

@@ -166,10 +166,7 @@ final class IssueCommentSectionController: ListBindingSectionController<IssueCom
166166
let nav = UINavigationController(
167167
rootViewController: ViewMarkdownViewController(markdown: markdown)
168168
)
169-
self?.viewController?.present(
170-
nav,
171-
animated: trueUnlessReduceMotionEnabled
172-
)
169+
self?.viewController?.route_present(to: nav)
173170
}
174171
)
175172
}

Classes/Settings/SettingsViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ GitHubSessionListener {
173173
viewController.delegate = self
174174
let navController = UINavigationController(rootViewController: viewController)
175175
navController.modalPresentationStyle = .formSheet
176-
present(navController, animated: trueUnlessReduceMotionEnabled)
176+
route_present(to: navController)
177177
}
178178

179179
func onViewSource() {

Classes/Systems/AppRouter/IssueRoute+RoutePerformable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import GitHawkRoutes
1212

1313
extension IssueRoute: RoutePerformable {
1414
func perform(props: RoutePerformableProps) -> RoutePerformableResult {
15-
return .show(IssuesViewController(
15+
return .push(IssuesViewController(
1616
client: props.client,
1717
model: IssueDetailsModel(owner: owner, repo: repo, number: number),
1818
scrollToBottom: true

Classes/Systems/AppRouter/RepoRoute+RoutePerformable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ extension RepoRoute: RoutePerformable {
1919
defaultBranch: branch,
2020
hasIssuesEnabled: true
2121
)
22-
return .show(RepositoryViewController(client: props.client, repo: model))
22+
return .push(RepositoryViewController(client: props.client, repo: model))
2323
}
2424
}

Classes/Systems/AppRouter/RoutePerformable.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import GitHubSession
1212
enum RoutePerformableResult {
1313
case error
1414
case custom
15-
case show(UIViewController)
15+
case push(UIViewController)
16+
case setDetail(UIViewController)
17+
case present(UIViewController)
1618

1719
var wasHandled: Bool {
1820
switch self {
1921
case .error: return false
20-
case .custom, .show: return true
22+
default: return true
2123
}
2224
}
2325
}

Classes/Systems/AppRouter/Router.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ extension UIViewController {
9090
router?.detail(controller: controller)
9191
}
9292

93+
func route_present(to controller: UIViewController) {
94+
if router == nil { print("ERROR: router was not wired up") }
95+
router?.present(from: self, to: controller)
96+
}
97+
9398
}
9499

95100
protocol RouterPropsSource: class {
@@ -149,12 +154,17 @@ final class Router: NSObject {
149154
let result = route.perform(props: props)
150155
switch result {
151156
case .custom, .error: break
152-
case .show(let toController):
157+
case .push(let toController):
158+
// if trying to push but not given an origin, fallback to detail
153159
if let controller = controller {
154160
push(from: controller, to: toController)
155161
} else {
156162
detail(controller: toController, split: props.splitViewController)
157163
}
164+
case .present(let toController):
165+
present(from: controller ?? props.splitViewController, to: toController)
166+
case .setDetail(let toController):
167+
detail(controller: toController, split: props.splitViewController)
158168
}
159169
return result
160170
}
@@ -167,6 +177,11 @@ final class Router: NSObject {
167177
)
168178
}
169179

180+
func present(from: UIViewController, to: UIViewController) {
181+
to.router = self
182+
from.present(to, animated: trueUnlessReduceMotionEnabled)
183+
}
184+
170185
func detail(controller: UIViewController) {
171186
guard let split = propsSource?.props(for: self)?.splitViewController
172187
else { return }

Classes/Systems/PhotoViewHandler.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ IssueCommentHtmlCellImageDelegate {
3030
let photo = IssueCommentPhoto(image: image, data: animatedImageData)
3131
let photosViewController = NYTPhotosViewController(photos: [photo])
3232
photosViewController.delegate = self
33-
viewController?.present(photosViewController, animated: trueUnlessReduceMotionEnabled)
33+
viewController?.route_present(to: photosViewController)
3434
}
3535

3636
// MARK: NYTPhotosViewControllerDelegate
@@ -52,8 +52,7 @@ IssueCommentHtmlCellImageDelegate {
5252
) { [weak self] (image, data, _, _) in
5353
if let image = image {
5454
let photo = IssueCommentPhoto(image: image, data: nil)
55-
let photosViewController = NYTPhotosViewController(photos: [photo])
56-
self?.viewController?.present(photosViewController, animated: trueUnlessReduceMotionEnabled)
55+
self?.viewController?.route_present(to: NYTPhotosViewController(photos: [photo]))
5756
} else {
5857
Squawk.showGenericError()
5958
}

Classes/View Controllers/UIViewController+Safari.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ extension UIViewController {
1313

1414
func presentSafari(url: URL) {
1515
guard let safariViewController = try? SFSafariViewController.configured(with: url) else { return }
16-
present(safariViewController, animated: trueUnlessReduceMotionEnabled)
16+
route_present(to: safariViewController)
1717
}
1818

1919
func presentProfile(login: String) {
2020
guard let controller = CreateProfileViewController(login: login) else { return }
21+
route_present(to: controller)
2122
present(controller, animated: trueUnlessReduceMotionEnabled)
2223
}
2324

Classes/Views/IssueTextActionsView+Markdown.swift

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,43 +29,83 @@ extension IssueTextActionsView {
2929
repo: repo
3030
))
3131
}),
32-
name: NSLocalizedString("Message Preview", comment: "The name of the action for previewing a message from the markdown actions bar")),
32+
name: NSLocalizedString(
33+
"Message Preview",
34+
comment: "The name of the action for previewing a message from the markdown actions bar"
35+
)
36+
),
3337
IssueTextActionOperation(
3438
icon: UIImage(named: "bar-mention"),
3539
operation: .wrap("@", ""),
36-
name: NSLocalizedString("Add mention to text", comment: "The name of the action for making text a mention from the markdown actions bar")),
40+
name: NSLocalizedString(
41+
"Add mention to text",
42+
comment: "The name of the action for making text a mention from the markdown actions bar"
43+
)
44+
),
3745
IssueTextActionOperation(
3846
icon: UIImage(named: "bar-bold"),
3947
operation: .wrap("**", "**"),
40-
name: NSLocalizedString("Make text bold", comment: "The name of the action for making text bold from the markdown actions bar")),
48+
name: NSLocalizedString(
49+
"Make text bold",
50+
comment: "The name of the action for making text bold from the markdown actions bar"
51+
)
52+
),
4153
IssueTextActionOperation(
4254
icon: UIImage(named: "bar-italic"),
4355
operation: .wrap("_", "_"),
44-
name: NSLocalizedString("Make text italic", comment: "The name of the action for making text italic from the markdown actions bar")),
56+
name: NSLocalizedString(
57+
"Make text italic",
58+
comment: "The name of the action for making text italic from the markdown actions bar"
59+
)
60+
),
4561
IssueTextActionOperation(
4662
icon: UIImage(named: "bar-code"),
4763
operation: .wrap("`", "`"),
48-
name: NSLocalizedString("Make text monospaced", comment: "The name of the action for making text monospaced / appear as code from the markdown actions bar")),
64+
name: NSLocalizedString(
65+
"Make text monospaced",
66+
comment: "The name of the action for making text monospaced / appear as code from the markdown actions bar"
67+
)
68+
),
4969
IssueTextActionOperation(
5070
icon: UIImage(named: "bar-code-block"),
5171
operation: .wrap("```\n", "\n```"),
52-
name: NSLocalizedString("Make text appear as code", comment: "The name of the action for making text appear as code from the markdown actions bar")),
72+
name: NSLocalizedString(
73+
"Make text appear as code",
74+
comment: "The name of the action for making text appear as code from the markdown actions bar"
75+
)
76+
),
5377
IssueTextActionOperation(
5478
icon: UIImage(named: "bar-strikethrough"),
5579
operation: .wrap("~~", "~~"),
56-
name: NSLocalizedString("Strikethrough text", comment: "The name of the action for making text strikethrough from the markdown actions bar")),
80+
name: NSLocalizedString(
81+
"Strikethrough text",
82+
comment: "The name of the action for making text strikethrough from the markdown actions bar"
83+
)
84+
),
5785
IssueTextActionOperation(
5886
icon: UIImage(named: "bar-header"),
5987
operation: .line("#"),
60-
name: NSLocalizedString("Add header to text", comment: "The name of the action for making text a header from the markdown actions bar")),
88+
name: NSLocalizedString(
89+
"Add header to text",
90+
comment: "The name of the action for making text a header from the markdown actions bar"
91+
)
92+
),
6193
IssueTextActionOperation(
6294
icon: UIImage(named: "bar-ul"),
6395
operation: .line("- "),
64-
name: NSLocalizedString("Make text a list item", comment: "The name of the action for making text a list item from the markdown actions bar")),
96+
name: NSLocalizedString(
97+
"Make text a list item",
98+
comment: "The name of the action for making text a list item from the markdown actions bar"
99+
)
100+
),
65101
IssueTextActionOperation(
66102
icon: UIImage(named: "bar-indent"),
67103
operation: .line(" "),
68-
name: NSLocalizedString("Make text indented", comment: "The name of the action for making text indented from the markdown actions bar")),
104+
name: NSLocalizedString(
105+
"Make text indented",
106+
comment: "The name of the action for making text indented from the markdown actions bar"
107+
)
108+
),
69109
IssueTextActionOperation(
70110
icon: UIImage(named: "bar-link"),
71111
operation: .multi([
@@ -76,14 +116,22 @@ extension IssueTextActionsView {
76116
}
77117
})
78118
]),
79-
name: NSLocalizedString("Wrap text as URL", comment: "The name of the action to wrap text in a markdown URL from the markdown actions bar"))
119+
name: NSLocalizedString(
120+
"Wrap text as URL",
121+
comment: "The name of the action to wrap text in a markdown URL from the markdown actions bar"
122+
)
123+
)
80124
]
81125

82126
if supportsImageUpload {
83127
operations.append(IssueTextActionOperation(
84128
icon: UIImage(named: "bar-upload"),
85129
operation: .uploadImage,
86-
name: NSLocalizedString("Upload Image", comment: "The name of the action to upload an image from the markdown actions bar")))
130+
name: NSLocalizedString(
131+
"Upload Image",
132+
comment: "The name of the action to upload an image from the markdown actions bar"
133+
)
134+
))
87135
}
88136

89137
let actions = IssueTextActionsView(operations: operations, showSendButton: showSendButton)
@@ -96,3 +144,4 @@ extension IssueTextActionsView {
96144
}
97145

98146
}
147+

0 commit comments

Comments
 (0)