Skip to content

Commit

Permalink
ハイパーリンクが正常に動作しない不具合を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
YuigaWada committed Apr 14, 2020
1 parent eade244 commit d3033d2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion MissCat/Others/Extension/UIViewController+MissCat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ extension UIViewController {
// MARK: Utilities

func openLink(url: String) {
guard let url = URL(string: url), let rootVC = UIApplication.shared.windows[0].rootViewController else { return }
// URLをデコードしておく
guard let url = URL(string: url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? url),
let rootVC = UIApplication.shared.windows[0].rootViewController else { return }
let safari = SFSafariViewController(url: url)

// i dont know why but it seems that we must launch a safari VC from the root VC.
Expand Down
13 changes: 11 additions & 2 deletions MissCat/View/PostDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,17 @@ class PostDetailViewController: NoteDisplay, UITableViewDelegate, FooterTabBarDe
// MARK: Delegate

override func tappedLink(text: String) {
navigationController?.popViewController(animated: true)
super.tappedLink(text: text)
let (linkType, value) = text.analyzeHyperLink()
switch linkType {
case .url:
homeViewController?.openLink(url: value)
case .user:
homeViewController?.move2Profile(userId: value)
case .hashtag:
navigationController?.popViewController(animated: true)
homeViewController?.emulateFooterTabTap(tab: .home)
homeViewController?.searchHashtag(tag: value)
}
}

func tappedNotifications() {
Expand Down
5 changes: 2 additions & 3 deletions MissCat/View/ProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,14 @@ class ProfileViewController: ButtonBarPagerTabStripViewController, UITextViewDel
}

func tappedLink(text: String) {
navigationController?.popViewController(animated: true)

let (linkType, value) = text.analyzeHyperLink()
switch linkType {
case .url:
homeViewController?.openUserPage(username: value)
homeViewController?.openLink(url: value)
case .user:
homeViewController?.move2Profile(userId: value)
case .hashtag:
navigationController?.popViewController(animated: true)
homeViewController?.emulateFooterTabTap(tab: .home)
homeViewController?.searchHashtag(tag: value)
}
Expand Down

0 comments on commit d3033d2

Please sign in to comment.