Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trunk' into task/ab-test-site-name
Browse files Browse the repository at this point in the history
  • Loading branch information
twstokes committed Apr 8, 2022
2 parents ad069d6 + ff18d7d commit bf40064
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ class BloggingPromptsFeatureIntroduction: FeatureIntroductionViewController {
}

init() {

let featureDescriptionView: BloggingPromptsFeatureDescriptionView = {
let featureDescriptionView = BloggingPromptsFeatureDescriptionView.loadFromNib()
featureDescriptionView.translatesAutoresizingMaskIntoConstraints = false
return featureDescriptionView
}()

let headerImage = UIImage(named: Style.headerImageName)?
.withTintColor(Style.headerImageTintColor)

super.init(headerTitle: Strings.headerTitle,
headerSubtitle: Strings.headerSubtitle,
// TODO: provide lightbulb image
headerImage: nil,
headerImage: headerImage,
featureDescriptionView: featureDescriptionView,
primaryButtonTitle: Strings.primaryButtonTitle,
secondaryButtonTitle: Strings.secondaryButtonTitle)
Expand Down Expand Up @@ -57,4 +58,9 @@ private extension BloggingPromptsFeatureIntroduction {
static let secondaryButtonTitle: String = NSLocalizedString("Remind me", comment: "Secondary button title on the feature introduction view.")
}

enum Style {
static let headerImageName = "icon-lightbulb-outline"
static let headerImageTintColor: UIColor = .orange // TODO: use gradient colors
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class FeatureIntroductionViewController: CollapsableHeaderViewController {
super.init(
scrollableView: scrollView,
mainTitle: headerTitle,
headerImage: headerImage,
prompt: headerSubtitle,
// TODO: pass headerImage
primaryActionTitle: primaryButtonTitle,
secondaryActionTitle: secondaryButtonTitle)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import WordPressUI

class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
enum SeparatorStyle {
case visibile
case visible
case automatic
case hidden
}
Expand All @@ -21,7 +21,7 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
}

open var separatorStyle: SeparatorStyle {
return self.hasAccessoryBar ? .visibile : .automatic
return self.hasAccessoryBar ? .visible : .automatic
}

private let hasDefaultAction: Bool
Expand All @@ -40,7 +40,12 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
}()

@IBOutlet weak var largeTitleTopSpacingConstraint: NSLayoutConstraint!

@IBOutlet weak var headerStackView: UIStackView!
@IBOutlet weak var headerImageView: UIImageView!
@IBOutlet weak var largeTitleView: UILabel!
private var headerImage: UIImage?

@IBOutlet weak var promptView: UILabel!
@IBOutlet weak var accessoryBar: UIView!
@IBOutlet weak var accessoryBarHeightConstraint: NSLayoutConstraint!
Expand All @@ -52,8 +57,8 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
@IBOutlet weak var selectedStateButtonsContainer: UIStackView!
@IBOutlet weak var seperator: UIView!

// Flag indicating if the action button stack view (selectedStateButtonsContainer) is vertical.
// Used when calculating the footer height.
/// Flag indicating if the action button stack view (selectedStateButtonsContainer) is vertical.
/// Used when calculating the footer height.
private var usesVerticalActionButtons: Bool = false

/// This is used as a means to adapt to different text sizes to force the desired layout and then active `headerHeightConstraint`
Expand Down Expand Up @@ -165,7 +170,9 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
///
/// - Parameters:
/// - scrollableView: Populates the scrollable area of this container. Required.
/// - title: The Large title and small title in the header. Required.
/// - mainTitle: The Large title and small title in the header. Required.
/// - navigationBarTitle: The Large title in the header. Optional.
/// - headerImage: An image displayed in the header. Optional.
/// - prompt: The subtitle/prompt in the header. Required.
/// - primaryActionTitle: The button title for the right most button when an item is selected. Required.
/// - secondaryActionTitle: The button title for the left most button when an item is selected. Optional - nil results in the left most button being hidden when an item is selected.
Expand All @@ -175,6 +182,7 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
init(scrollableView: UIScrollView,
mainTitle: String,
navigationBarTitle: String? = nil,
headerImage: UIImage? = nil,
prompt: String,
primaryActionTitle: String,
secondaryActionTitle: String? = nil,
Expand All @@ -183,6 +191,7 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
self.scrollableView = scrollableView
self.mainTitle = mainTitle
self.navigationBarTitle = navigationBarTitle
self.headerImage = headerImage
self.prompt = prompt
self.primaryActionTitle = primaryActionTitle
self.secondaryActionTitle = secondaryActionTitle
Expand All @@ -201,6 +210,7 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
super.viewDidLoad()
insertChildView()
insertAccessoryView()
configureHeaderImageView()
navigationItem.titleView = titleView
largeTitleView.font = WPStyleGuide.serifFontForTextStyle(UIFont.TextStyle.largeTitle, fontWeight: .semibold)
toggleFilterBarConstraints()
Expand Down Expand Up @@ -241,7 +251,10 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)

guard isShowingNoResults else { return }
guard isShowingNoResults else {
return
}

coordinator.animate(alongsideTransition: nil) { (_) in
self.updateHeaderDisplay()
if self.shouldHideAccessoryBar {
Expand Down Expand Up @@ -335,7 +348,10 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
}

private func insertAccessoryView() {
guard let accessoryView = accessoryView else { return }
guard let accessoryView = accessoryView else {
return
}

accessoryView.translatesAutoresizingMaskIntoConstraints = false
let top = NSLayoutConstraint(item: accessoryView, attribute: .top, relatedBy: .equal, toItem: accessoryBar, attribute: .top, multiplier: 1, constant: 0)
let bottom = NSLayoutConstraint(item: accessoryView, attribute: .bottom, relatedBy: .equal, toItem: accessoryBar, attribute: .bottom, multiplier: 1, constant: 0)
Expand All @@ -345,6 +361,11 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
accessoryBar.addConstraints([top, bottom, leading, trailing])
}

private func configureHeaderImageView() {
headerImageView.isHidden = (headerImage == nil)
headerImageView.image = headerImage
}

private func styleButtons() {
let seperator = UIColor.separator

Expand Down Expand Up @@ -390,7 +411,7 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
accessoryBarSpacing = accessoryBarHeightConstraint.constant + maxHeaderBottomSpacing.constant
}
_midHeaderHeight = titleToSubtitleSpacing.constant + promptView.frame.height + subtitleToCategoryBarSpacing.constant + accessoryBarSpacing
_maxHeaderHeight = largeTitleTopSpacingConstraint.constant + largeTitleView.frame.height + _midHeaderHeight
_maxHeaderHeight = largeTitleTopSpacingConstraint.constant + headerStackView.frame.height + _midHeaderHeight
}

private func layoutHeaderInsets() {
Expand Down Expand Up @@ -443,7 +464,10 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {

/// A public interface to notify the container that the content has loaded data or is attempting too.
public func displayNoResultsController(title: String, subtitle: String?, resultsDelegate: NoResultsViewControllerDelegate?) {
guard !isShowingNoResults else { return }
guard !isShowingNoResults else {
return
}

isShowingNoResults = true
disableInitialLayoutHelpers()
snapToHeight(scrollableView, height: minHeaderHeight)
Expand All @@ -458,7 +482,10 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
}

public func dismissNoResultsController() {
guard isShowingNoResults else { return }
guard isShowingNoResults else {
return
}

isShowingNoResults = false
snapToHeight(scrollableView, height: maxHeaderHeight)
hideNoResults()
Expand Down Expand Up @@ -506,7 +533,11 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
})
return
}
guard hasSelectedItem == selectedStateButtonsContainer.isHidden else { return }

guard hasSelectedItem == selectedStateButtonsContainer.isHidden else {
return
}

defaultActionButton.isHidden = false
selectedStateButtonsContainer.isHidden = false

Expand All @@ -531,7 +562,7 @@ class CollapsableHeaderViewController: UIViewController, NoResultsViewHost {
switch separatorStyle {
case .automatic:
shouldBeHidden = headerHeightConstraint.constant > minHeaderHeight && !shouldUseCompactLayout
case .visibile:
case .visible:
shouldBeHidden = false
case .hidden:
shouldBeHidden = true
Expand All @@ -553,7 +584,10 @@ extension CollapsableHeaderViewController: UIScrollViewDelegate {

/// Restores the stashed content offset if it appears as if it's been reset.
private func restoreContentOffsetIfNeeded(_ scrollView: UIScrollView) {
guard var stashedOffset = stashedOffset else { return }
guard var stashedOffset = stashedOffset else {
return
}

stashedOffset = resolveContentOffsetCollisions(scrollView, cachedOffset: stashedOffset)
scrollView.contentOffset = stashedOffset
}
Expand Down Expand Up @@ -624,9 +658,11 @@ extension CollapsableHeaderViewController: UIScrollViewDelegate {
}

private func snapToHeight(_ scrollView: UIScrollView) {
guard !shouldUseCompactLayout else { return }
guard !shouldUseCompactLayout else {
return
}

if largeTitleView.frame.midY > 0 {
if headerStackView.frame.midY > 0 {
snapToHeight(scrollView, height: maxHeaderHeight)
} else if promptView.frame.midY > 0 {
snapToHeight(scrollView, height: midHeaderHeight)
Expand All @@ -636,7 +672,9 @@ extension CollapsableHeaderViewController: UIScrollViewDelegate {
}

public func expandHeader() {
guard !shouldUseCompactLayout else { return }
guard !shouldUseCompactLayout else {
return
}
snapToHeight(scrollableView, height: maxHeaderHeight)
}

Expand Down
Loading

0 comments on commit bf40064

Please sign in to comment.