Skip to content

Commit c05f0c4

Browse files
authored
Merge pull request #18535 from wordpress-mobile/feature/18473-action-sheet-answer-prompt
Blogging Prompts: Add answer prompt flow to prompts action sheet header
2 parents 50814c6 + 1a14b18 commit c05f0c4

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed

WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController+FAB.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension MySiteViewController {
3535
actions.append(PostAction(handler: newPost, source: source))
3636
actions.append(PageAction(handler: newPage, source: source))
3737

38-
let coordinator = CreateButtonCoordinator(self, actions: actions, source: source)
38+
let coordinator = CreateButtonCoordinator(self, actions: actions, source: source, blog: blog)
3939
return coordinator
4040
}
4141

WordPress/Classes/ViewRelated/Post/PostEditor.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,5 @@ enum PostEditorEntryPoint: String {
155155
case postsList
156156
case dashboard
157157
case bloggingPromptsFeatureIntroduction
158+
case bloggingPromptsActionSheetHeader
158159
}

WordPress/Classes/ViewRelated/Post/PostListViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe
193193
(self.tabBarController as? WPTabBarController)?.showStoryEditor(blog: self.blog, title: nil, content: nil)
194194
}, source: Constants.source), at: 0)
195195
}
196-
return CreateButtonCoordinator(self, actions: actions, source: Constants.source)
196+
return CreateButtonCoordinator(self, actions: actions, source: Constants.source, blog: blog)
197197
}()
198198

199199
override func viewDidAppear(_ animated: Bool) {

WordPress/Classes/ViewRelated/System/Action Sheet/BloggingPromptsHeaderView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ class BloggingPromptsHeaderView: UIView, NibLoadable {
1111
@IBOutlet private weak var shareButton: UIButton!
1212
@IBOutlet private weak var dividerView: UIView!
1313

14+
var answerPromptHandler: (() -> Void)?
15+
1416
override func awakeFromNib() {
1517
super.awakeFromNib()
1618
configureView()
1719
}
1820

1921
@IBAction private func answerPromptTapped(_ sender: Any) {
20-
// TODO
22+
answerPromptHandler?()
2123
}
2224

2325
@IBAction private func shareTapped(_ sender: Any) {
@@ -31,7 +33,7 @@ private extension BloggingPromptsHeaderView {
3133

3234
func configureView() {
3335
// TODO: Hide correct UI based on if prompt is answered
34-
answerPromptButton.isHidden = true
36+
answeredStackView.isHidden = true
3537
configureSpacing()
3638
configureStrings()
3739
configureStyles()

WordPress/Classes/ViewRelated/System/Floating Create Button/CreateButtonActionSheet.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ class CreateButtonActionSheet: ActionSheetViewController {
1010
static let title = NSLocalizedString("Create New", comment: "Create New header text")
1111
}
1212

13-
init(actions: [ActionSheetItem]) {
14-
let headerView = FeatureFlag.bloggingPrompts.enabled ? BloggingPromptsHeaderView.loadFromNib() : nil
13+
init(headerView: UIView?, actions: [ActionSheetItem]) {
1514
let buttons = actions.map { $0.makeButton() }
1615
super.init(headerView: headerView, headerTitle: Constants.title, buttons: buttons)
1716
}

WordPress/Classes/ViewRelated/System/Floating Create Button/CreateButtonCoordinator.swift

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,38 @@ import WordPressFlux
5656
}
5757
}
5858

59+
private lazy var promptsHeaderView: BloggingPromptsHeaderView? = {
60+
let headerView = FeatureFlag.bloggingPrompts.enabled ? BloggingPromptsHeaderView.loadFromNib() : nil
61+
headerView?.answerPromptHandler = { [weak self] in
62+
self?.viewController?.dismiss(animated: true) {
63+
guard let blog = self?.blog else {
64+
return
65+
}
66+
let editor = EditPostViewController(blog: blog, prompt: .examplePrompt)
67+
editor.modalPresentationStyle = .fullScreen
68+
editor.entryPoint = .bloggingPromptsActionSheetHeader
69+
self?.viewController?.present(editor, animated: true)
70+
}
71+
}
72+
return headerView
73+
}()
74+
5975
private weak var noticeContainerView: NoticeContainerView?
6076
private let actions: [ActionSheetItem]
6177
private let source: String
78+
private let blog: Blog?
6279

6380
/// Returns a newly initialized CreateButtonCoordinator
6481
/// - Parameters:
6582
/// - viewController: The UIViewController from which the menu should be shown.
66-
/// - newPost: A closure to call when the New Post button is tapped.
67-
/// - newPage: A closure to call when the New Page button is tapped.
68-
/// - newStory: A closure to call when the New Story button is tapped. The New Story button is hidden when value is `nil`.
69-
init(_ viewController: UIViewController, actions: [ActionSheetItem], source: String) {
83+
/// - actions: A list of actions to display in the menu
84+
/// - source: The source where the create button is being presented from
85+
/// - blog: The current blog in context
86+
init(_ viewController: UIViewController, actions: [ActionSheetItem], source: String, blog: Blog? = nil) {
7087
self.viewController = viewController
7188
self.actions = actions
7289
self.source = source
90+
self.blog = blog
7391

7492
super.init()
7593

@@ -143,7 +161,7 @@ import WordPressFlux
143161
}
144162

145163
private func actionSheetController(with traitCollection: UITraitCollection) -> UIViewController {
146-
let actionSheetVC = CreateButtonActionSheet(actions: actions)
164+
let actionSheetVC = CreateButtonActionSheet(headerView: promptsHeaderView, actions: actions)
147165
setupPresentation(on: actionSheetVC, for: traitCollection)
148166
return actionSheetVC
149167
}

0 commit comments

Comments
 (0)