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

Commit

Permalink
feature/survey (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
decanus authored Apr 29, 2021
1 parent d36d77a commit 4ec4479
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 3 deletions.
23 changes: 23 additions & 0 deletions Assets.xcassets/survey.dude.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "survey.dude.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "survey.dude@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "survey.dude@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return
}

nav.presentNotificiationPrompt()
if nav.presentNotificiationPrompt() {
return
}

_ = nav.presentSurveyPrompt()
}
}

Expand Down
8 changes: 6 additions & 2 deletions Sources/NavigationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,12 @@ class NavigationViewController: UINavigationController {
present(preview, animated: true)
}

func presentNotificiationPrompt() {
UserPrompts.promptForNotifications(onView: self)
func presentNotificiationPrompt() -> Bool {
return UserPrompts.promptForNotifications(onView: self)
}

func presentSurveyPrompt() -> Bool {
return UserPrompts.promptForPMFSurvey(onView: self)
}

private func showClosedError() {
Expand Down
103 changes: 103 additions & 0 deletions Sources/Scenes/PMFSurveyPrompt/PMFSurveyPromptViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import SafariServices
import UIKit

class PMFSurveyPromptViewController: DrawerViewController {
override init() {
super.init()

manager.drawer.openHeightBehavior = .fitting
manager.drawer.backgroundColor = .foreground
}

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .foreground

let image = UIImageView(image: UIImage(named: "survey.dude"))
image.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(image)

let title = UILabel()
title.translatesAutoresizingMaskIntoConstraints = false
title.text = "We want your feedback!"
title.font = .rounded(forTextStyle: .title1, weight: .bold)
title.numberOfLines = 0
title.textColor = .white
title.textAlignment = .center
view.addSubview(title)

let content = UILabel()
content.translatesAutoresizingMaskIntoConstraints = false
content.text = "Please take the time to complete this quick 2 minute survey. Your answers will help us create a better Soapbox experience for you!"
content.numberOfLines = 0
content.textColor = .white
content.font = .rounded(forTextStyle: .body, weight: .semibold)
view.addSubview(content)

let survey = Button(size: .large)
survey.translatesAutoresizingMaskIntoConstraints = false
survey.setTitle("Complete Survey", for: .normal)
survey.addTarget(self, action: #selector(openSurvey), for: .touchUpInside)
view.addSubview(survey)

let cancelButton = UIButton()
cancelButton.setTitle("Not Now", for: .normal)
cancelButton.setTitleColor(.secondaryLabel, for: .normal)
cancelButton.translatesAutoresizingMaskIntoConstraints = false
cancelButton.titleLabel?.font = .rounded(forTextStyle: .title3, weight: .bold)
cancelButton.addTarget(self, action: #selector(close), for: .touchUpInside)
view.addSubview(cancelButton)

NSLayoutConstraint.activate([
image.centerXAnchor.constraint(equalTo: view.centerXAnchor),
image.topAnchor.constraint(equalTo: handle.bottomAnchor, constant: 40),
])

NSLayoutConstraint.activate([
title.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 60),
title.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -60),
title.topAnchor.constraint(equalTo: image.bottomAnchor, constant: 20),
])

NSLayoutConstraint.activate([
content.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 30),
content.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -30),
content.topAnchor.constraint(equalTo: title.bottomAnchor, constant: 40),
])

NSLayoutConstraint.activate([
survey.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 20),
survey.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -20),
survey.topAnchor.constraint(equalTo: content.bottomAnchor, constant: 20),
])

NSLayoutConstraint.activate([
cancelButton.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 20),
cancelButton.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -20),
cancelButton.topAnchor.constraint(equalTo: survey.bottomAnchor, constant: 20),
cancelButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -20),
])
}

required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

@objc private func openSurvey() {
let parent = presentingViewController!

let url = "https://soapboxsocial.typeform.com/to/X2RBcn2C#user_id=\(UserDefaults.standard.integer(forKey: UserDefaultsKeys.userId))"
dismiss(animated: true, completion: {
DispatchQueue.main.async {
let safari = SFSafariViewController(url: URL(string: url)!)
safari.modalPresentationStyle = .overFullScreen
parent.present(safari, animated: true)
}
})
}

@objc private func close() {
dismiss(animated: true)
}
}
4 changes: 4 additions & 0 deletions Sources/UserDefaultsKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ class UserDefaultsKeys {
class var lastNotificationsStartupPrompted: String {
return "lastNotificationsStartupPrompted"
}

class var hasAskedForPMFSurvey: String {
return "hasAskedForPMFSurvey"
}
}
15 changes: 15 additions & 0 deletions Sources/UserPrompts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,19 @@ class UserPrompts {

return true
}

static func promptForPMFSurvey(onView view: UIViewController) -> Bool {
if UserDefaults.standard.bool(forKey: UserDefaultsKeys.hasAskedForPMFSurvey) {
return false
}

if UserDefaults.standard.integer(forKey: UserDefaultsKeys.userId) == 19 {
return false
}

view.present(PMFSurveyPromptViewController(), animated: true)
UserDefaults.standard.set(true, forKey: UserDefaultsKeys.hasAskedForPMFSurvey)

return true
}
}

0 comments on commit 4ec4479

Please sign in to comment.