Skip to content

Commit

Permalink
Merge branch 'main' into twn
Browse files Browse the repository at this point in the history
  • Loading branch information
tonisevener authored Nov 6, 2024
2 parents dfad1bd + 4ca3b34 commit c3d531b
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Wikipedia/Code/ArticleViewController+Announcements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extension ArticleViewController {

let globalRect = CGRect(x: globalPoint.x, y: globalPoint.y, width: button.frame.width, height: button.frame.height)

let donateCoordinator = DonateCoordinator(navigationController: navigationController, donateButtonGlobalRect: globalRect, source: .articleCampaignModal(articleURL, asset.metricsID, donateURL), dataStore: dataStore, theme: theme, setLoadingBlock: { isLoading in
let donateCoordinator = DonateCoordinator(navigationController: navigationController, donateButtonGlobalRect: globalRect, source: .articleCampaignModal(articleURL, asset.metricsID, donateURL), dataStore: dataStore, theme: theme, navigationStyle: .dismissThenPush, setLoadingBlock: { isLoading in
guard let fundraisingPanelVC = viewController as? FundraisingAnnouncementPanelViewController else {
return
}
Expand Down
2 changes: 0 additions & 2 deletions Wikipedia/Code/ArticleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,6 @@ class ArticleViewController: ViewController, HintPresenting {
// Year in Review modal presentations
} else if needsYearInReviewAnnouncement() {
presentYearInReviewAnnouncement()
} else if yirCoordinator?.needsSurveyPresentation ?? false {
yirCoordinator?.presentSurveyIfNeeded()

// Campaign modal presentations
} else {
Expand Down
101 changes: 75 additions & 26 deletions Wikipedia/Code/DonateCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import WMF
import PassKit
import WMFComponents
import WMFData

import CocoaLumberjackSwift

// Helper class to access donate coordinator logic from Obj-c
@objc class WMFDonateCoordinatorWrapper: NSObject {
Expand All @@ -27,18 +27,21 @@ class DonateCoordinator: Coordinator {
case yearInReview // TODO: Do it properly T376062
}

enum NavigationStyle {
case dismissThenPush
case present
}

// MARK: Properties

var navigationController: UINavigationController
private let donateButtonGlobalRect: CGRect
private let source: Source
private let navigationStyle: NavigationStyle

// Code to run when we are fetching donate configs. Typically this changes some donate button into a spinner.
private let setLoadingBlock: (Bool) -> Void

/// Code to run after navigation controller dismisses any modals it's currently presenting, but before it pushes on the donate (native or web view) form
private var dismissalBlock: (() -> Void)?

private let dataStore: MWKDataStore
private let theme: Theme

Expand Down Expand Up @@ -93,14 +96,14 @@ class DonateCoordinator: Coordinator {

// MARK: Lifecycle

init(navigationController: UINavigationController, donateButtonGlobalRect: CGRect, source: Source, dataStore: MWKDataStore, theme: Theme, setLoadingBlock: @escaping (Bool) -> Void, dismissalBlock: (() -> Void)? = nil) {
init(navigationController: UINavigationController, donateButtonGlobalRect: CGRect, source: Source, dataStore: MWKDataStore, theme: Theme, navigationStyle: NavigationStyle, setLoadingBlock: @escaping (Bool) -> Void) {
self.navigationController = navigationController
self.donateButtonGlobalRect = donateButtonGlobalRect
self.source = source
self.dataStore = dataStore
self.theme = theme
self.navigationStyle = navigationStyle
self.setLoadingBlock = setLoadingBlock
self.dismissalBlock = dismissalBlock
}

static func metricsID(for donateSource: Source, languageCode: String?) -> String? {
Expand Down Expand Up @@ -142,10 +145,7 @@ class DonateCoordinator: Coordinator {

guard let donateViewModel = self.nativeDonateFormViewModel(countryCode: countryCode) else {

self.navigationController.dismiss(animated: true, completion: { [weak self] in
self?.dismissalBlock?()
self?.pushToOtherPaymentMethod()
})
self.navigateToOtherPaymentMethod()

return
}
Expand Down Expand Up @@ -219,10 +219,7 @@ class DonateCoordinator: Coordinator {
case .yearInReview:
DonateFunnel.shared.logYearInReviewDidTapDonateApplePay(metricsID: metricsID)
}
self.navigationController.dismiss(animated: true, completion: {
self.dismissalBlock?()
self.pushToNativeDonateForm(donateViewModel: donateViewModel)
})
self.navigateToNativeDonateForm(donateViewModel: donateViewModel)
})
alert.addAction(applePayAction)

Expand All @@ -248,10 +245,7 @@ class DonateCoordinator: Coordinator {
case .yearInReview:
DonateFunnel.shared.logYearInReviewDidTapDonateOtherPaymentMethod(metricsID: metricsID)
}
self.navigationController.dismiss(animated: true, completion: {
self.dismissalBlock?()
self.pushToOtherPaymentMethod()
})
navigateToOtherPaymentMethod()
}))

alert.preferredAction = applePayAction
Expand Down Expand Up @@ -359,13 +353,28 @@ class DonateCoordinator: Coordinator {
return viewModel
}

private func pushToNativeDonateForm(donateViewModel: WMFDonateViewModel) {
private func navigateToNativeDonateForm(donateViewModel: WMFDonateViewModel) {
let donateViewController = WMFDonateViewController(viewModel: donateViewModel)

navigationController.pushViewController(donateViewController, animated: true)
switch navigationStyle {
case .dismissThenPush:
navigationController.dismiss(animated: true) {
self.navigationController.pushViewController(donateViewController, animated: true)
}
case .present:

guard let presentedViewController = navigationController.presentedViewController else {
DDLogError("Unexpected navigation controller state. Skipping donate form presentation.")
return
}

let newNavigationController = WMFThemeableNavigationController(rootViewController: donateViewController)
presentedViewController.present(newNavigationController, animated: true)
}

}

private func pushToOtherPaymentMethod() {
private func navigateToOtherPaymentMethod() {
guard let webViewURL else { return }

let completeButtonTitle: String
Expand All @@ -377,7 +386,23 @@ class DonateCoordinator: Coordinator {
}
let donateConfig = SinglePageWebViewController.WebViewDonateConfig(donateCoordinatorDelegate: self, donateLoggingDelegate: self, donateCompleteButtonTitle: completeButtonTitle)
let webVC = SinglePageWebViewController(url: webViewURL, theme: theme, donateConfig: donateConfig)
navigationController.pushViewController(webVC, animated: true)

switch navigationStyle {
case .dismissThenPush:
self.navigationController.dismiss(animated: true, completion: {
self.navigationController.pushViewController(webVC, animated: true)
})
case .present:

guard let presentedViewController = navigationController.presentedViewController else {
DDLogError("Unexpected navigation controller state. Skipping donate form presentation.")
return
}

let newNavigationController = WMFThemeableNavigationController(rootViewController: webVC)
newNavigationController.modalPresentationStyle = .formSheet
presentedViewController.present(newNavigationController, animated: true)
}
}
}

Expand Down Expand Up @@ -453,16 +478,40 @@ extension DonateCoordinator: DonateCoordinatorDelegate {
}

private func popAndShowSuccessToastFromNativeForm() {
self.navigationController.popViewController(animated: true)

DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
switch navigationStyle {
case .dismissThenPush:
self.navigationController.popViewController(animated: true)
case .present:
guard let presentedVC = navigationController.presentedViewController else {
DDLogError("Unexpected navigation controller state. Skipping auto-dismissal.")
return
}

WMFAlertManager.sharedInstance.showBottomAlertWithMessage(CommonStrings.donateThankTitle, subtitle: CommonStrings.donateThankSubtitle, image: UIImage.init(systemName: "heart.fill"), type: .custom, customTypeName: "donate-success", duration: -1, dismissPreviousAlerts: true)
presentedVC.dismiss(animated: true) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {

WMFAlertManager.sharedInstance.showBottomAlertWithMessage(CommonStrings.donateThankTitle, subtitle: CommonStrings.donateThankSubtitle, image: UIImage.init(systemName: "heart.fill"), type: .custom, customTypeName: "donate-success", duration: -1, dismissPreviousAlerts: true)
}
}
}


}

private func popFromWebFormThankYouPage() {
navigationController.popViewController(animated: true)

switch navigationStyle {
case .dismissThenPush:
navigationController.popViewController(animated: true)
case .present:
guard let presentedVC = navigationController.presentedViewController else {
DDLogError("Unexpected navigation controller state. Skipping auto-dismissal.")
return
}

presentedVC.dismiss(animated: true)
}
}

private func displayThankYouToastAfterDelay() {
Expand Down
2 changes: 0 additions & 2 deletions Wikipedia/Code/ExploreViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,6 @@ extension ExploreViewController {

if needsYearInReviewAnnouncement() {
presentYearInReviewAnnouncement()
} else if yirCoordinator?.needsSurveyPresentation ?? false {
yirCoordinator?.presentSurveyIfNeeded()
} else if needsImageRecommendationsFeatureAnnouncement() {
presentImageRecommendationsFeatureAnnouncement()
} else if needsAltTextFeatureAnnouncement() {
Expand Down
2 changes: 1 addition & 1 deletion Wikipedia/Code/ProfileCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ final class ProfileCoordinator: NSObject, Coordinator, ProfileCoordinatorDelegat
return
}

let donateCoordinator = DonateCoordinator(navigationController: navigationController, donateButtonGlobalRect: targetRects.donateButtonFrame, source: donateSouce, dataStore: dataStore, theme: theme, setLoadingBlock: { isLoading in
let donateCoordinator = DonateCoordinator(navigationController: navigationController, donateButtonGlobalRect: targetRects.donateButtonFrame, source: donateSouce, dataStore: dataStore, theme: theme, navigationStyle: .dismissThenPush, setLoadingBlock: { isLoading in
viewModel.isLoadingDonateConfigs = isLoading
})

Expand Down
13 changes: 12 additions & 1 deletion Wikipedia/Code/SinglePageWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ class SinglePageWebViewController: ViewController {
var fetched = false

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: false)

if navigationController?.viewControllers.first === self {
let closeButton = UIBarButtonItem.wmf_buttonType(WMFButtonType.X, target: self, action: #selector(closeButtonTapped(_:)))
navigationItem.leftBarButtonItem = closeButton
}

super.viewWillAppear(animated)

guard !fetched else {
return
Expand All @@ -155,6 +158,14 @@ class SinglePageWebViewController: ViewController {
donateConfig?.donateLoggingDelegate?.handleDonateLoggingAction(.webViewFormDidAppear)
}
}

public override var preferredContentSize: CGSize {
get {
return CGSize(width: 1400, height: 1400)
} set {
super.preferredContentSize = newValue
}
}

func setupDonationCompleteView() {
webView.addSubview(donationCompleteButtonContainer)
Expand Down
16 changes: 2 additions & 14 deletions Wikipedia/Code/YearInReviewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ final class YearInReviewCoordinator: NSObject, Coordinator {
private let targetRects = WMFProfileViewTargetRects()
let dataController: WMFYearInReviewDataController
var donateCoordinator: DonateCoordinator?
private(set) var needsSurveyPresentation = false

// Collective base numbers that will change
let collectiveNumArticlesText = WMFLocalizedString("year-in-review-2024-Wikipedia-num-articles", value: "63.69 million articles", comment: "Total number of articles across Wikipedia. This text will be inserted into paragraph text displayed in Wikipedia Year in Review slides for 2024.")
Expand Down Expand Up @@ -272,18 +271,12 @@ final class YearInReviewCoordinator: NSObject, Coordinator {
navigationController.present(hostingController, animated: true, completion: nil)
}

func presentSurveyIfNeeded() {
guard needsSurveyPresentation else {
return
}

private func presentSurveyIfNeeded() {
if !self.dataController.hasPresentedYiRSurvey {
let surveyVC = surveyViewController()
navigationController.present(surveyVC, animated: true)
self.dataController.hasPresentedYiRSurvey = true
}

self.needsSurveyPresentation = false
}

private func surveyViewController() -> UIViewController {
Expand Down Expand Up @@ -369,17 +362,13 @@ extension YearInReviewCoordinator: YearInReviewCoordinatorDelegate {
DonateFunnel.shared.logYearInReviewDidTapDonate(slideLoggingID: slideLoggingID, metricsID: metricsID)
}

let donateCoordinator = DonateCoordinator(navigationController: navigationController, donateButtonGlobalRect: rect, source: .yearInReview, dataStore: dataStore, theme: theme, setLoadingBlock: { [weak self] loading in
let donateCoordinator = DonateCoordinator(navigationController: navigationController, donateButtonGlobalRect: rect, source: .yearInReview, dataStore: dataStore, theme: theme, navigationStyle: .present, setLoadingBlock: { [weak self] loading in
guard let self,
let viewModel = self.viewModel else {
return
}

viewModel.isLoading = loading
}, dismissalBlock: { [weak self] in
if isLastSlide {
self?.needsSurveyPresentation = true
}
})

self.donateCoordinator = donateCoordinator
Expand Down Expand Up @@ -412,7 +401,6 @@ extension YearInReviewCoordinator: YearInReviewCoordinatorDelegate {

guard isLastSlide else { return }

self.needsSurveyPresentation = true
self.presentSurveyIfNeeded()
})
}
Expand Down

0 comments on commit c3d531b

Please sign in to comment.