Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-2651 - Add Links to Navigating DAO #2665

Merged
merged 8 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 67 additions & 3 deletions Multisig/UI/ClaimToken/NavigatingDAOViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class NavigatingDAOViewController: UIViewController {

ViewControllerFactory.removeNavigationBarBorder(self)
navigationItem.largeTitleDisplayMode = .never

screenTitle.setStyle(.claimTitle)

introductionParagraph.setStyle(.secondary)
Expand All @@ -44,10 +44,36 @@ class NavigatingDAOViewController: UIViewController {

nextButton.setText("Start claiming", .filled)

discussItemLabel.setStyle(.secondary)
proposeItemLabel.setStyle(.secondary)
discussItemLabel.hyperLinkLabel("Discuss SafeDAO improvements - post topics and discuss in our",
prefixStyle: .secondary,
linkText: "Forum",
linkIcon: nil,
underlined: false,
postfixText: "."
)
openUrlOnTap(link: .discuss, label: discussItemLabel)

proposeItemLabel.hyperLinkLabel("Propose improvements - read our governance ",
prefixStyle: .secondary,
linkText: "process",
linkIcon: nil,
underlined: false,
postfixText: " and post an SIP."
)
openUrlOnTap(link: .propose, label: proposeItemLabel)

let governText = "Govern improvements - vote on our Snapshot."
governItemLabel.setStyle(.secondary)

chatItemLabel.setStyle(.secondary)
chatItemLabel.hyperLinkLabel("Chat with the community - join our Safe ",
prefixStyle: .secondary,
linkText: "Discord",
linkIcon: nil,
underlined: false,
postfixText: "."
)
openUrlOnTap(link: .chat, label: chatItemLabel)

subTitle.setStyle(.headline)
subTitle.textAlignment = .center
Expand All @@ -58,4 +84,42 @@ class NavigatingDAOViewController: UIViewController {
completion?()
}

func openUrlOnTap(link: link, label: UILabel) {
var tapRecognizer: UITapGestureRecognizer
switch link {
case .discuss: tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(discussTap(sender:)))
case .propose: tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(proposeTap(sender:)))
case .chat: tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(chatTap(sender:)))
}
label.addGestureRecognizer(tapRecognizer)
}

@objc
func discussTap(sender: UITapGestureRecognizer) {
guard let url = URL(string: "https://forum.gnosis-safe.io/") else {
biafra23 marked this conversation as resolved.
Show resolved Hide resolved
return
}
openInSafari(url)
}

@objc
func proposeTap(sender: UITapGestureRecognizer) {
guard let url = URL(string: "https://docs.google.com/document/d/1t79exFjYZQO80yDc8X2S61d4Sc1_QjBwnzZgTSWqoUo/edit#heading=h.ao7vqnfg6hyh") else {
biafra23 marked this conversation as resolved.
Show resolved Hide resolved
return
}
openInSafari(url)
}

@objc
func chatTap(sender: UITapGestureRecognizer) {
guard let url = URL(string: "https://discord.com/invite/AjG7AQD9Qn") else {
biafra23 marked this conversation as resolved.
Show resolved Hide resolved
return
}
openInSafari(url)
}

enum link {
case discuss, propose, chat
}
}

8 changes: 4 additions & 4 deletions Multisig/UI/ClaimToken/NavigatingDAOViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<constraint firstAttribute="height" constant="26" id="x8E-JB-FuI"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="Discuss SafeDAO improvements - post topics and discuss in our forum." textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0U3-zK-Me5" userLabel="discussItemLabel">
<label opaque="NO" contentMode="left" verticalHuggingPriority="251" text="Discuss SafeDAO improvements - post topics and discuss in our forum." textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0U3-zK-Me5" userLabel="discussItemLabel">
<rect key="frame" x="38" y="0.0" width="344" height="41"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
Expand All @@ -87,7 +87,7 @@
<constraint firstAttribute="width" secondItem="n9l-w0-VpO" secondAttribute="height" id="m1t-m1-pHb"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Propose improvements - read our governance process and post an SIP." lineBreakMode="wordWrap" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="z7G-zp-con" userLabel="proposeItemLabel">
<label opaque="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Propose improvements - read our governance process and post an SIP." lineBreakMode="wordWrap" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="z7G-zp-con" userLabel="proposeItemLabel">
<rect key="frame" x="38" y="0.0" width="344" height="41"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
Expand All @@ -106,7 +106,7 @@
<constraint firstAttribute="height" constant="26" id="Y8Y-FK-pSd"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="Govern improvements - vote on our Snapshot." lineBreakMode="wordWrap" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="c1B-Mu-vEQ" userLabel="governItemLabel">
<label opaque="NO" contentMode="left" verticalHuggingPriority="251" text="Govern improvements - vote on our Snapshot." lineBreakMode="wordWrap" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="c1B-Mu-vEQ" userLabel="governItemLabel">
<rect key="frame" x="38" y="0.0" width="344" height="41"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
Expand All @@ -125,7 +125,7 @@
<constraint firstAttribute="width" secondItem="BLZ-22-2c9" secondAttribute="height" id="pcv-ZC-9Wd"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="Chat with the communiity - join our Safe Discord." lineBreakMode="wordWrap" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="61T-uw-BsL" userLabel="chatItemLabel">
<label opaque="NO" contentMode="left" verticalHuggingPriority="251" text="Chat with the communiity - join our Safe Discord." lineBreakMode="wordWrap" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="61T-uw-BsL" userLabel="chatItemLabel">
<rect key="frame" x="38" y="0.0" width="344" height="41"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
Expand Down
11 changes: 9 additions & 2 deletions Multisig/UI/UI Library/UIFont+Styles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ extension UILabel {
linkText: String = "",
linkStyle: GNOTextStyle = .primaryButton,
linkIcon: UIImage? = UIImage(named: "icon-external-link")!.withTintColor(.primary),
underlined: Bool = true) {
underlined: Bool = true,
postfixText: String = "") {
let result = NSMutableAttributedString()

if !prefixText.isEmpty {
Expand All @@ -121,7 +122,7 @@ extension UILabel {
}

// text + non-breaking space
let attributedLinkText = NSMutableAttributedString(string: "\(linkText)\u{00A0}")
let attributedLinkText = NSMutableAttributedString(string: "\(linkText)")
attributedLinkText.addAttributes(linkStyle.attributes, range: NSRange(location: 0, length: attributedLinkText.length))
if underlined {
attributedLinkText.addAttributes([NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue], range: NSRange(location: 0, length: attributedLinkText.length))
Expand All @@ -130,6 +131,9 @@ extension UILabel {
result.append(attributedLinkText)

if let icon = linkIcon {
let nbsp = NSMutableAttributedString(string: "\u{00A0}")
result.append(nbsp)

let attachment = NSTextAttachment(image: icon.withTintColor(.primary))
// for some reason the image sticks to the 'top' of the line, so we have to offset it vertically
let lineHeight = UIFont.gnoFont(forTextStyle: linkStyle).lineHeight
Expand All @@ -139,6 +143,9 @@ extension UILabel {
result.append(attachmentString)
}

let attributedWithPostfix = NSMutableAttributedString(string: postfixText, attributes: prefixStyle.attributes)
result.append(attributedWithPostfix)

attributedText = result
}
}
Expand Down