Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Jetpack powered banner to Reader Search #19059

Merged
merged 12 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions WordPress/Classes/ViewRelated/Reader/Reader.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -16,7 +16,7 @@
<viewControllerLayoutGuide type="bottom" id="icf-FG-h6u"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="nFH-eq-cvg">
<rect key="frame" x="0.0" y="0.0" width="375" height="477"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="482"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
Expand All @@ -43,14 +43,14 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<searchBar contentMode="redraw" translatesAutoresizingMaskIntoConstraints="NO" id="B6J-Lg-PdX">
<rect key="frame" x="0.0" y="0.0" width="375" height="56"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="51"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" returnKeyType="done" enablesReturnKeyAutomatically="YES"/>
<connections>
<outlet property="delegate" destination="e0f-8T-Sz8" id="8aD-d4-C9q"/>
</connections>
</searchBar>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="49S-3J-OMN">
<rect key="frame" x="0.0" y="56" width="375" height="611"/>
<rect key="frame" x="0.0" y="51" width="375" height="616"/>
<connections>
<segue destination="FBk-BW-Oyk" kind="embed" id="BIm-m7-JCp"/>
</connections>
Expand Down Expand Up @@ -89,45 +89,36 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<searchBar contentMode="redraw" translatesAutoresizingMaskIntoConstraints="NO" id="UQY-Uf-csX">
<rect key="frame" x="0.0" y="0.0" width="375" height="56"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="51"/>
<textInputTraits key="textInputTraits" returnKeyType="search" enablesReturnKeyAutomatically="YES"/>
<connections>
<outlet property="delegate" destination="sKI-JH-RAG" id="fsR-5r-2Md"/>
</connections>
</searchBar>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="KJP-Gn-VWy" customClass="FilterTabBar" customModule="WordPress" customModuleProvider="target">
<rect key="frame" x="0.0" y="56" width="375" height="46"/>
<rect key="frame" x="0.0" y="51" width="375" height="46"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="46" id="8Zx-Ii-BAp"/>
</constraints>
</view>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="PuG-YC-OIC">
<rect key="frame" x="0.0" y="102" width="375" height="521"/>
<rect key="frame" x="0.0" y="97" width="375" height="526"/>
<connections>
<segue destination="His-O5-Cy6" kind="embed" id="xfh-l2-pdU"/>
</connections>
</containerView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="What would you like to find?" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="afc-5c-5tF">
<rect key="frame" x="16" y="349" width="343" height="27"/>
<fontDescription key="fontDescription" type="system" pointSize="22"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="4Hq-9j-ssQ" firstAttribute="top" secondItem="PuG-YC-OIC" secondAttribute="bottom" id="00R-Fx-nqw"/>
<constraint firstItem="KJP-Gn-VWy" firstAttribute="leading" secondItem="3Jv-hf-pib" secondAttribute="leading" id="3hK-Yk-mzY"/>
<constraint firstItem="afc-5c-5tF" firstAttribute="width" secondItem="UQY-Uf-csX" secondAttribute="width" constant="-32" id="7H0-0r-9sW"/>
<constraint firstItem="KJP-Gn-VWy" firstAttribute="top" secondItem="UQY-Uf-csX" secondAttribute="bottom" id="HHm-eE-R1Z"/>
<constraint firstItem="UQY-Uf-csX" firstAttribute="leading" secondItem="3Jv-hf-pib" secondAttribute="leading" id="OVh-zU-bdz"/>
<constraint firstItem="PuG-YC-OIC" firstAttribute="top" secondItem="KJP-Gn-VWy" secondAttribute="bottom" id="SLO-Jy-5QA"/>
<constraint firstItem="UQY-Uf-csX" firstAttribute="top" secondItem="KDf-ab-yd0" secondAttribute="bottom" id="Vjr-r9-9fI"/>
<constraint firstItem="afc-5c-5tF" firstAttribute="centerY" secondItem="PuG-YC-OIC" secondAttribute="centerY" id="WFt-Iz-74I"/>
<constraint firstAttribute="trailing" secondItem="PuG-YC-OIC" secondAttribute="trailing" id="Xy7-kf-4Zi"/>
<constraint firstAttribute="trailing" secondItem="UQY-Uf-csX" secondAttribute="trailing" id="ack-5h-tUx"/>
<constraint firstItem="afc-5c-5tF" firstAttribute="centerX" secondItem="PuG-YC-OIC" secondAttribute="centerX" id="e4c-Hf-6s0"/>
<constraint firstAttribute="trailing" secondItem="KJP-Gn-VWy" secondAttribute="trailing" id="oCm-Ws-bQM"/>
<constraint firstItem="PuG-YC-OIC" firstAttribute="leading" secondItem="3Jv-hf-pib" secondAttribute="leading" id="u5y-Zc-kp9"/>
</constraints>
Expand All @@ -136,7 +127,6 @@
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" translucent="NO" prompted="NO"/>
<connections>
<outlet property="filterBar" destination="KJP-Gn-VWy" id="P35-se-cGl"/>
<outlet property="label" destination="afc-5c-5tF" id="Ytv-PP-Zf4"/>
<outlet property="searchBar" destination="UQY-Uf-csX" id="df9-mO-cAe"/>
</connections>
</viewController>
Expand Down Expand Up @@ -167,7 +157,7 @@
<outlet property="delegate" destination="ZNR-Yp-I4L" id="VQ7-Kg-Swl"/>
</connections>
</tableView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="oQ8-sg-BBr">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="oQ8-sg-BBr">
<rect key="frame" x="0.0" y="269" width="600" height="30"/>
<constraints>
<constraint firstAttribute="height" priority="750" constant="44" id="QH2-kg-tnA"/>
Expand Down Expand Up @@ -219,7 +209,7 @@
<objects>
<tableViewController id="FBk-BW-Oyk" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" layoutMarginsFollowReadableWidth="YES" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="54" sectionHeaderHeight="18" sectionFooterHeight="18" id="q5P-P8-r6d">
<rect key="frame" x="0.0" y="0.0" width="375" height="611"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="616"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,26 @@ class ReaderSearchSuggestionsViewController: UIViewController {
var delegate: ReaderSearchSuggestionsDelegate?
@objc let cellIdentifier = "CellIdentifier"
@objc let rowAndButtonHeight = CGFloat(44.0)

private var height: CGFloat {
UIApplication.shared.mainWindow?.frame.size.height ?? 0
}

private var isLargeAccessibilitySize: Bool {
[
UIContentSizeCategory.accessibilityExtraLarge,
UIContentSizeCategory.accessibilityExtraExtraLarge,
UIContentSizeCategory.accessibilityExtraExtraExtraLarge
].contains(traitCollection.preferredContentSizeCategory)
}

@objc var maxTableViewRows: Int {
let height = UIApplication.shared.mainWindow?.frame.size.height ?? 0
if height == 320 {
// iPhone 4s, 5, 5s, in landscape orientation
if height <= 428 {
// Any iPhone landscape
return 1
} else if height <= 480 {
// iPhone 4s in portrait orientation
return 2
} else if height <= 568 {
// iPhone 5, 5s in portrait orientation
return 4
} else if height <= 834 {
// iPhone 6s/SE2nd/7/8 in portrait orientation, iPad landscape
return isLargeAccessibilitySize ? 3 : 4
}
// Everything else
return 5
Expand Down Expand Up @@ -86,6 +95,7 @@ class ReaderSearchSuggestionsViewController: UIViewController {


override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
super.willTransition(to: newCollection, with: coordinator)
coordinator.animate(alongsideTransition: { (_) in
self.updateHeightConstraint()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import Gridicons

@IBOutlet fileprivate weak var searchBar: UISearchBar!
@IBOutlet fileprivate weak var filterBar: FilterTabBar!
@IBOutlet fileprivate weak var label: UILabel!

fileprivate var backgroundTapRecognizer: UITapGestureRecognizer!
fileprivate var streamController: ReaderStreamViewController?
Expand All @@ -48,6 +47,12 @@ import Gridicons
fileprivate var restoredSearchTopic: ReaderSearchTopic?
fileprivate var didBumpStats = false

private lazy var bannerView: JetpackBannerView = {
let bannerView = JetpackBannerView()
bannerView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: 50)
return bannerView
}()


fileprivate let sections: [Section] = [ .posts, .sites ]

Expand Down Expand Up @@ -116,7 +121,6 @@ import Gridicons
WPStyleGuide.configureColors(view: view, tableView: nil)
setupSearchBar()
configureFilterBar()
configureLabel()
configureBackgroundTapRecognizer()
configureForRestoredTopic()
configureSiteSearchViewController()
Expand Down Expand Up @@ -169,13 +173,35 @@ import Gridicons
// MARK: - Configuration


@objc func setupSearchBar() {
private func setupSearchBar() {
// Appearance must be set before the search bar is added to the view hierarchy.
let placeholderText = NSLocalizedString("Search WordPress", comment: "Placeholder text for the Reader search feature.")
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self, ReaderSearchViewController.self]).placeholder = placeholderText

searchBar.becomeFirstResponder()
WPStyleGuide.configureSearchBar(searchBar)
guard AppConfiguration.isWordPress, FeatureFlag.jetpackPowered.enabled else {
return
}
searchBar.inputAccessoryView = bannerView
hideBannerViewIfNeeded()
}

/// hides the Jetpack powered banner on iPhone landscape
private func hideBannerViewIfNeeded() {
guard AppConfiguration.isWordPress, FeatureFlag.jetpackPowered.enabled else {
return
}
let height = UIApplication.shared.mainWindow?.frame.size.height ?? 0
// maximum height of any iPhone in landscape. iPads and portrait orientations
// all have heights greater than this one.
let maximumLandscapeHeight: CGFloat = 428
bannerView.isHidden = height <= maximumLandscapeHeight
sla8c marked this conversation as resolved.
Show resolved Hide resolved
}

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

func configureFilterBar() {
Expand All @@ -187,15 +213,6 @@ import Gridicons
filterBar.addTarget(self, action: #selector(selectedFilterDidChange(_:)), for: .valueChanged)
}

@objc func configureLabel() {
let text = NSLocalizedString("Search WordPress\nfor a site or post", comment: "A short message that is a call to action for the Reader's Search feature.")
let rawAttributes = WPNUXUtility.titleAttributes(with: .neutral(.shade50)) as! [String: Any]
let swiftedAttributes = NSAttributedString.Key.convertFromRaw(attributes: rawAttributes)
label.numberOfLines = 2
label.attributedText = NSAttributedString(string: text, attributes: swiftedAttributes)
}


@objc func configureBackgroundTapRecognizer() {
backgroundTapRecognizer = UITapGestureRecognizer(target: self, action: #selector(ReaderSearchViewController.handleBackgroundTap(_:)))
backgroundTapRecognizer.cancelsTouchesInView = true
Expand All @@ -209,7 +226,6 @@ import Gridicons
guard let topic = restoredSearchTopic else {
return
}
label.isHidden = true
searchBar.text = topic.title
streamController?.readerTopic = topic
}
Expand Down Expand Up @@ -280,8 +296,6 @@ import Gridicons
let topic = service.searchTopic(forSearchPhrase: phrase)
streamController.readerTopic = topic

// Hide the starting label now that a topic has been set.
label.isHidden = true
endSearch()

if let previousTopic = previousTopic {
Expand Down