Skip to content

Commit

Permalink
Merge pull request #18455 from wordpress-mobile/task/site-design-remo…
Browse files Browse the repository at this point in the history
…ve-preview-mode-picker

[Site Design Revamp] Remove preview mode selector from nav bar
  • Loading branch information
twstokes authored Apr 29, 2022
2 parents d45493f + 49e6b1b commit 2830846
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 71 deletions.
4 changes: 2 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ workspace 'WordPress.xcworkspace'
## ===================================
##
def wordpress_shared
pod 'WordPressShared', '~> 1.17.1'
#pod 'WordPressShared', '~> 1.17.1'
#pod 'WordPressShared', :git => 'https://github.com/wordpress-mobile/WordPress-iOS-Shared.git', :tag => ''
#pod 'WordPressShared', :git => 'https://github.com/wordpress-mobile/WordPress-iOS-Shared.git', :branch => ''
pod 'WordPressShared', :git => 'https://github.com/wordpress-mobile/WordPress-iOS-Shared.git', :branch => 'feature/site-design-revamp'
#pod 'WordPressShared', :git => 'https://github.com/wordpress-mobile/WordPress-iOS-Shared.git', :commit => ''
#pod 'WordPressShared', :path => '../WordPress-iOS-Shared'
end
Expand Down
11 changes: 8 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ DEPENDENCIES:
- WordPressAuthenticator (~> 2.0.0)
- WordPressKit (~> 4.50.0)
- WordPressMocks (~> 0.0.15)
- WordPressShared (~> 1.17.1)
- WordPressShared (from `https://github.com/wordpress-mobile/WordPress-iOS-Shared.git`, branch `feature/site-design-revamp`)
- WordPressUI (~> 1.12.5)
- WPMediaPicker (~> 1.8.3)
- Yoga (from `https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/v1.74.0/third-party-podspecs/Yoga.podspec.json`)
Expand Down Expand Up @@ -642,7 +642,6 @@ SPEC REPOS:
- WordPress-Editor-iOS
- WordPressKit
- WordPressMocks
- WordPressShared
- WordPressUI
- WPMediaPicker
- wpxmlrpc
Expand Down Expand Up @@ -753,6 +752,9 @@ EXTERNAL SOURCES:
:git: https://github.com/wordpress-mobile/gutenberg-mobile.git
:submodules: true
:tag: v1.74.0
WordPressShared:
:branch: feature/site-design-revamp
:git: https://github.com/wordpress-mobile/WordPress-iOS-Shared.git
Yoga:
:podspec: https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/v1.74.0/third-party-podspecs/Yoga.podspec.json

Expand All @@ -768,6 +770,9 @@ CHECKOUT OPTIONS:
:git: https://github.com/wordpress-mobile/gutenberg-mobile.git
:submodules: true
:tag: v1.74.0
WordPressShared:
:commit: cd17c7c81d2ad7005a724b580f99e42a50a06bdb
:git: https://github.com/wordpress-mobile/WordPress-iOS-Shared.git

SPEC CHECKSUMS:
Alamofire: 3ec537f71edc9804815215393ae2b1a8ea33a844
Expand Down Expand Up @@ -869,6 +874,6 @@ SPEC CHECKSUMS:
ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba
ZIPFoundation: ae5b4b813d216d3bf0a148773267fff14bd51d37

PODFILE CHECKSUM: 4ec8f8e1fe1324b2079ae08999bcc274e8232655
PODFILE CHECKSUM: b8a2c329dc0c5787b885a9311d168d112338a918

COCOAPODS: 1.11.2
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,6 @@ + (TracksEventPair *)eventPairForStat:(WPAnalyticsStat)stat
case WPAnalyticsStatEnhancedSiteCreationSiteDesignPreviewLoaded:
eventName = @"enhanced_site_creation_site_design_preview_loaded";
break;
case WPAnalyticsStatEnhancedSiteCreationSiteDesignThumbnailModeButtonTapped:
eventName = @"enhanced_site_creation_site_design_thumbnail_mode_button_tapped";
break;
case WPAnalyticsStatEnhancedSiteCreationSiteDesignPreviewModeButtonTapped:
eventName = @"enhanced_site_creation_site_design_preview_mode_button_tapped";
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
let accessoryView: UIView?
let mainTitle: String
let navigationBarTitle: String?
let prompt: String
let prompt: String?
let primaryActionTitle: String
let secondaryActionTitle: String?
let defaultActionTitle: String?
Expand Down Expand Up @@ -189,7 +189,7 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
mainTitle: String,
navigationBarTitle: String? = nil,
headerImage: UIImage? = nil,
prompt: String,
prompt: String? = nil,
primaryActionTitle: String,
secondaryActionTitle: String? = nil,
defaultActionTitle: String? = nil,
Expand Down Expand Up @@ -323,6 +323,7 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
titleView.text = navigationBarTitle ?? mainTitle
titleView.sizeToFit()
largeTitleView.text = mainTitle
promptView.isHidden = prompt == nil
promptView.text = prompt
primaryActionButton.setTitle(primaryActionTitle, for: .normal)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class FilterableCategoriesViewController: CollapsableHeaderViewController {
init(
analyticsLocation: String,
mainTitle: String,
prompt: String,
prompt: String? = nil,
primaryActionTitle: String,
secondaryActionTitle: String? = nil,
defaultActionTitle: String? = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class SiteDesignContentCollectionViewController: FilterableCategoriesViewControl
var selectedIndexPath: IndexPath? = nil
private var sections: [SiteDesignSection] = []
internal override var categorySections: [CategorySection] { get { sections }}

override var selectedPreviewDevice: PreviewDevice {
get { .mobile }
set { /* no op */ }
}

private lazy var previewViewSelectedPreviewDevice = PreviewDevice.default

var siteDesigns = RemoteSiteDesigns() {
didSet {
if oldValue.categories.count == 0 {
Expand All @@ -49,7 +57,6 @@ class SiteDesignContentCollectionViewController: FilterableCategoriesViewControl
tableView.reloadData()
}
}
var previewDeviceButtonItem: UIBarButtonItem?

var selectedDesign: RemoteSiteDesign? {
guard let sectionIndex = selectedItem?.section, let position = selectedItem?.item else { return nil }
Expand All @@ -63,7 +70,6 @@ class SiteDesignContentCollectionViewController: FilterableCategoriesViewControl
super.init(
analyticsLocation: "site_creation",
mainTitle: TextContent.mainTitle,
prompt: TextContent.subtitle,
primaryActionTitle: createsSite ? TextContent.createSiteButton : TextContent.chooseButton,
secondaryActionTitle: TextContent.previewButton
)
Expand All @@ -79,7 +85,6 @@ class SiteDesignContentCollectionViewController: FilterableCategoriesViewControl
fetchSiteDesigns()
configureCloseButton()
configureSkipButton()
configurePreviewDeviceButton()
SiteCreationAnalyticsHelper.trackSiteDesignViewed(previewMode: selectedPreviewDevice)
}

Expand All @@ -106,12 +111,6 @@ class SiteDesignContentCollectionViewController: FilterableCategoriesViewControl
navigationItem.rightBarButtonItem = skip
}

private func configurePreviewDeviceButton() {
let button = UIBarButtonItem(image: UIImage(named: "icon-devices"), style: .plain, target: self, action: #selector(previewDeviceButtonTapped))
previewDeviceButtonItem = button
navigationItem.rightBarButtonItems?.append(button)
}

private func configureCloseButton() {
guard navigationController?.viewControllers.first == self else {
return
Expand All @@ -126,21 +125,6 @@ class SiteDesignContentCollectionViewController: FilterableCategoriesViewControl
completion(nil)
}

@objc private func previewDeviceButtonTapped() {
SiteCreationAnalyticsHelper.trackSiteDesignThumbnailModeButtonTapped(selectedPreviewDevice)
let popoverContentController = PreviewDeviceSelectionViewController()
popoverContentController.selectedOption = selectedPreviewDevice
popoverContentController.onDeviceChange = { [weak self] device in
guard let self = self else { return }
SiteCreationAnalyticsHelper.trackSiteDesignPreviewModeChanged(device)
self.selectedPreviewDevice = device
}

popoverContentController.modalPresentationStyle = .popover
popoverContentController.popoverPresentationController?.delegate = self
self.present(popoverContentController, animated: true, completion: nil)
}

override func primaryActionSelected(_ sender: Any) {
guard let design = selectedDesign else {
completion(nil)
Expand All @@ -153,9 +137,15 @@ class SiteDesignContentCollectionViewController: FilterableCategoriesViewControl
override func secondaryActionSelected(_ sender: Any) {
guard let design = selectedDesign else { return }

let previewVC = SiteDesignPreviewViewController(siteDesign: design, selectedPreviewDevice: selectedPreviewDevice, createsSite: createsSite, onDismissWithDeviceSelected: { [weak self] device in
self?.selectedPreviewDevice = device
}, completion: completion)
let previewVC = SiteDesignPreviewViewController(
siteDesign: design,
selectedPreviewDevice: previewViewSelectedPreviewDevice,
createsSite: createsSite,
onDismissWithDeviceSelected: { [weak self] device in
self?.previewViewSelectedPreviewDevice = device
},
completion: completion
)

let navController = GutenbergLightNavigationController(rootViewController: previewVC)
navController.modalPresentationStyle = .pageSheet
Expand All @@ -170,8 +160,7 @@ class SiteDesignContentCollectionViewController: FilterableCategoriesViewControl
}

private enum TextContent {
static let mainTitle = NSLocalizedString("Choose a design", comment: "Title for the screen to pick a design and homepage for a site.")
static let subtitle = NSLocalizedString("Pick your favorite homepage layout. You can edit and customize it later.", comment: "Prompt for the screen to pick a design and homepage for a site.")
static let mainTitle = NSLocalizedString("Choose a theme", comment: "Title for the screen to pick a theme and homepage for a site.")
static let createSiteButton = NSLocalizedString("Create Site", comment: "Title for the button to progress with creating the site with the selected design.")
static let chooseButton = NSLocalizedString("Choose", comment: "Title for the button to progress with the selected site homepage design.")
static let previewButton = NSLocalizedString("Preview", comment: "Title for button to preview a selected homepage design.")
Expand All @@ -189,30 +178,3 @@ extension SiteDesignContentCollectionViewController: NoResultsViewControllerDele
fetchSiteDesigns()
}
}

// MARK: UIPopoverPresentationDelegate
extension SiteDesignContentCollectionViewController {
func prepareForPopoverPresentation(_ popoverPresentationController: UIPopoverPresentationController) {
guard popoverPresentationController.presentedViewController is PreviewDeviceSelectionViewController else {
return
}

popoverPresentationController.permittedArrowDirections = .up
popoverPresentationController.barButtonItem = previewDeviceButtonItem
}

func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
return .none
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

// Reset our source rect and view for a transition to a new size
guard let popoverPresentationController = presentedViewController?.presentationController as? UIPopoverPresentationController else {
return
}

prepareForPopoverPresentation(popoverPresentationController)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ class SiteCreationAnalyticsHelper {
WPAnalytics.track(.enhancedSiteCreationSiteDesignViewed, withProperties: commonProperties(previewMode))
}

static func trackSiteDesignThumbnailModeButtonTapped(_ previewMode: PreviewDevice) {
WPAnalytics.track(.enhancedSiteCreationSiteDesignThumbnailModeButtonTapped, withProperties: commonProperties(previewMode))
}

static func trackSiteDesignSkipped() {
WPAnalytics.track(.enhancedSiteCreationSiteDesignSkipped)
}
Expand Down
15 changes: 15 additions & 0 deletions WordPress/WordPressTest/SiteCreation/SiteDesignTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,19 @@ class SiteDesignTests: XCTestCase {
let currentTitle = siteDesignPreviewVC.primaryActionButton.currentTitle
XCTAssertEqual(expectedPrimaryTitle, currentTitle)
}

/// Tests that the preview device on the Design view cannot be changed
func testSiteDesignPreviewDeviceIsAlwaysMobile() throws {

// given
let siteDesignVC = SiteDesignContentCollectionViewController(createsSite: false) { _ in }
let expectedDevice = PreviewDeviceSelectionViewController.PreviewDevice.mobile

// when
XCTAssertEqual(siteDesignVC.selectedPreviewDevice, expectedDevice)
siteDesignVC.selectedPreviewDevice = PreviewDeviceSelectionViewController.PreviewDevice.tablet

// then
XCTAssertEqual(siteDesignVC.selectedPreviewDevice, expectedDevice)
}
}

0 comments on commit 2830846

Please sign in to comment.