Skip to content

Commit

Permalink
Align navigation to hey
Browse files Browse the repository at this point in the history
  • Loading branch information
lazaronixon committed Oct 7, 2023
1 parent 9d20522 commit c33ad41
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"settings": {},
"rules": [
{ "patterns": [".*"], "properties": { "uri": "turbo://fragment/web", "pull_to_refresh_enabled": true } },
{ "patterns": ["/refresh_historical_location"], "properties": { "presentation": "refresh" } },
{ "patterns": ["/recede_historical_location"], "properties": { "presentation": "pop" } },
{ "patterns": ["/resume_historical_location"], "properties": { "presentation": "none" } },
{ "patterns": ["^/$"], "properties": { "uri": "turbo://fragment/web/home", "presentation": "replace_all" } },
{ "patterns": ["/refresh_historical_location"], "properties": { "presentation": "refresh" } },
{ "patterns": ["/new$", "/edit$", "/signin$", "/strada-form$"], "properties": { "context": "modal", "uri": "turbo://fragment/web/modal", "pull_to_refresh_enabled": false } },
{ "patterns": ["^/$"], "properties": { "uri": "turbo://fragment/web/home", "presentation": "replace_all" } },
{ "patterns": ["/numbers$"], "properties": { "uri": "turbo://fragment/numbers", "title": "Numbers" } }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"settings": {},
"rules": [
{ "patterns": [".*"], "properties": { "uri": "turbo://fragment/web", "pull_to_refresh_enabled": true } },
{ "patterns": ["/refresh_historical_location"], "properties": { "presentation": "refresh" } },
{ "patterns": ["/recede_historical_location"], "properties": { "presentation": "pop" } },
{ "patterns": ["/resume_historical_location"], "properties": { "presentation": "none" } },
{ "patterns": ["^/$"], "properties": { "uri": "turbo://fragment/web/home", "presentation": "replace_all" } },
{ "patterns": ["/refresh_historical_location"], "properties": { "presentation": "refresh" } },
{ "patterns": ["/new$", "/edit$", "/signin$", "/strada-form$"], "properties": { "context": "modal", "uri": "turbo://fragment/web/modal", "pull_to_refresh_enabled": false } },
{ "patterns": ["^/$"], "properties": { "uri": "turbo://fragment/web/home", "presentation": "replace_all" } },
{ "patterns": ["/numbers$"], "properties": { "uri": "turbo://fragment/numbers", "title": "Numbers" } }
]
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"settings": {},
"rules": [
{ "patterns": ["/refresh_historical_location"], "properties": { "presentation": "refresh", "visitable": false } },
{ "patterns": ["/recede_historical_location"], "properties": { "presentation": "pop", "visitable": false } },
{ "patterns": ["/recede_historical_location"], "properties": { "presentation": "back", "visitable": false } },
{ "patterns": ["/resume_historical_location"], "properties": { "presentation": "none", "visitable": false } },
{ "patterns": ["/refresh_historical_location"], "properties": { "presentation": "refresh", "visitable": false } },
{ "patterns": ["/new$", "/edit$", "/signin$", "/strada-form$"], "properties": { "presentation": "modal", "pull-to-refresh-enabled": false } },
{ "patterns": ["^/$"], "properties": { "presentation": "replace-all" } },
{ "patterns": ["/new$", "/edit$", "/signin$", "/strada-form$"], "properties": { "presentation": "modal" } },
{ "patterns": ["/numbers$"], "properties": { "view-controller": "numbers" } }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ extension TurboNavigationController {
return properties["presentation"] as? String == "modal"
}

private func isPop(_ properties: PathProperties) -> Bool {
return properties["presentation"] as? String == "pop"
private func isBack(_ properties: PathProperties) -> Bool {
return properties["presentation"] as? String == "back"
}

private func isRefresh(_ properties: PathProperties) -> Bool {
Expand All @@ -71,6 +71,14 @@ extension TurboNavigationController {
return properties["visitable"] as? Bool ?? true
}

private func isPullToRefreshEnabled(_ properties: PathProperties) -> Bool {
return properties["pull-to-refresh-enabled"] as? Bool ?? true
}

private func title(from properties: PathProperties) -> String? {
return properties["title"] as? String
}

private func noticeMessage(from url: URL) -> String? {
URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems?.first(where: { $0.name == "notice" })?.value
}
Expand All @@ -90,13 +98,16 @@ extension TurboNavigationController {
}
}

return TurboWebViewController(url: url)
let viewController = TurboWebViewController(url: url)
viewController.pullToRefreshEnabled = isPullToRefreshEnabled(properties)
viewController.title = title(from: properties)
return viewController
}

private func navigate(to viewController: UIViewController, action: VisitAction, properties: PathProperties = [:]) {
if isModal(properties) {
present(UINavigationController(rootViewController: viewController), animated: true)
} else if isPop(properties) {
} else if isBack(properties) {
popViewController(animated: true)
} else if isRefresh(properties) {
session.reload()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import WebKit

final class TurboWebViewController: VisitableViewController, ErrorPresenter, BridgeDestination {

var pullToRefreshEnabled = true

private lazy var bridgeDelegate: BridgeDelegate = {
BridgeDelegate(location: visitableURL.absoluteString, destination: self, componentTypes: BridgeComponent.allTypes)
}()
Expand All @@ -20,6 +22,8 @@ final class TurboWebViewController: VisitableViewController, ErrorPresenter, Bri

navigationItem.backButtonTitle = "Back"

visitableView.allowsPullToRefresh = pullToRefreshEnabled

if presentingViewController != nil {
navigationItem.leftBarButtonItem = dismissModalButton
}
Expand Down Expand Up @@ -49,6 +53,10 @@ final class TurboWebViewController: VisitableViewController, ErrorPresenter, Bri

// MARK: Visitable

override func visitableDidRender() {
title = title ?? visitableView.webView?.title
}

override func visitableDidActivateWebView(_ webView: WKWebView) {
bridgeDelegate.webViewDidBecomeActive(webView)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"settings": {},
"rules": [
{ "patterns": ["/refresh_historical_location"], "properties": { "presentation": "refresh", "visitable": false } },
{ "patterns": ["/recede_historical_location"], "properties": { "presentation": "pop", "visitable": false } },
{ "patterns": ["/recede_historical_location"], "properties": { "presentation": "back", "visitable": false } },
{ "patterns": ["/resume_historical_location"], "properties": { "presentation": "none", "visitable": false } },
{ "patterns": ["/refresh_historical_location"], "properties": { "presentation": "refresh", "visitable": false } },
{ "patterns": ["/new$", "/edit$", "/signin$", "/strada-form$"], "properties": { "presentation": "modal", "pull-to-refresh-enabled": false } },
{ "patterns": ["^/$"], "properties": { "presentation": "replace-all" } },
{ "patterns": ["/new$", "/edit$", "/signin$", "/strada-form$"], "properties": { "presentation": "modal" } },
{ "patterns": ["/numbers$"], "properties": { "view-controller": "numbers" } }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ extension TurboNavigationController {
return properties["presentation"] as? String == "modal"
}

private func isPop(_ properties: PathProperties) -> Bool {
return properties["presentation"] as? String == "pop"
private func isBack(_ properties: PathProperties) -> Bool {
return properties["presentation"] as? String == "back"
}

private func isRefresh(_ properties: PathProperties) -> Bool {
Expand All @@ -71,6 +71,14 @@ extension TurboNavigationController {
return properties["visitable"] as? Bool ?? true
}

private func isPullToRefreshEnabled(_ properties: PathProperties) -> Bool {
return properties["pull-to-refresh-enabled"] as? Bool ?? true
}

private func title(from properties: PathProperties) -> String? {
return properties["title"] as? String
}

private func noticeMessage(from url: URL) -> String? {
URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems?.first(where: { $0.name == "notice" })?.value
}
Expand All @@ -90,13 +98,16 @@ extension TurboNavigationController {
}
}

return TurboWebViewController(url: url)
let viewController = TurboWebViewController(url: url)
viewController.pullToRefreshEnabled = isPullToRefreshEnabled(properties)
viewController.title = title(from: properties)
return viewController
}

private func navigate(to viewController: UIViewController, action: VisitAction, properties: PathProperties = [:]) {
if isModal(properties) {
present(UINavigationController(rootViewController: viewController), animated: true)
} else if isPop(properties) {
} else if isBack(properties) {
popViewController(animated: true)
} else if isRefresh(properties) {
session.reload()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import WebKit

final class TurboWebViewController: VisitableViewController, ErrorPresenter, BridgeDestination {

var pullToRefreshEnabled = true

private lazy var bridgeDelegate: BridgeDelegate = {
BridgeDelegate(location: visitableURL.absoluteString, destination: self, componentTypes: BridgeComponent.allTypes)
}()
Expand All @@ -20,6 +22,8 @@ final class TurboWebViewController: VisitableViewController, ErrorPresenter, Bri

navigationItem.backButtonTitle = "Back"

visitableView.allowsPullToRefresh = pullToRefreshEnabled

if presentingViewController != nil {
navigationItem.leftBarButtonItem = dismissModalButton
}
Expand Down Expand Up @@ -49,6 +53,10 @@ final class TurboWebViewController: VisitableViewController, ErrorPresenter, Bri

// MARK: Visitable

override func visitableDidRender() {
title = title ?? visitableView.webView?.title
}

override func visitableDidActivateWebView(_ webView: WKWebView) {
bridgeDelegate.webViewDidBecomeActive(webView)
}
Expand Down

0 comments on commit c33ad41

Please sign in to comment.