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

[Stats Refresh] Hide/show navigation bar when scrolling #10852

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
31 changes: 13 additions & 18 deletions WordPress/Classes/ViewRelated/Stats/SiteStatsDashboard.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Tqa-zb-Liz">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Tqa-zb-Liz">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -34,39 +34,29 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="R6d-mo-itW" customClass="FilterTabBar" customModule="WordPress">
<rect key="frame" x="0.0" y="64" width="375" height="46"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="46" id="u03-Cy-Pus"/>
</constraints>
</view>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="J6j-x0-sMS" userLabel="Insights Container View">
<rect key="frame" x="0.0" y="110" width="375" height="557"/>
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
<connections>
<segue destination="Hcp-7d-sgU" kind="embed" id="1nS-hf-ioa"/>
</connections>
</containerView>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="OmR-2E-jXp" userLabel="Stats Container View">
<rect key="frame" x="0.0" y="110" width="375" height="557"/>
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
<connections>
<segue destination="plb-uA-RCD" kind="embed" id="HLi-0c-1Fw"/>
</connections>
</containerView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="R6d-mo-itW" firstAttribute="trailing" secondItem="Ocg-ig-pQt" secondAttribute="trailing" id="3Vy-SZ-45b"/>
<constraint firstItem="OmR-2E-jXp" firstAttribute="leading" secondItem="Ocg-ig-pQt" secondAttribute="leading" id="4PI-hg-39d"/>
<constraint firstItem="J6j-x0-sMS" firstAttribute="bottom" secondItem="Ocg-ig-pQt" secondAttribute="bottom" id="5Dc-js-I5s"/>
<constraint firstItem="J6j-x0-sMS" firstAttribute="top" secondItem="R6d-mo-itW" secondAttribute="bottom" id="Cgj-jO-OfC"/>
<constraint firstItem="OmR-2E-jXp" firstAttribute="top" secondItem="Ocg-ig-pQt" secondAttribute="top" id="7bK-ih-Qmv"/>
<constraint firstItem="J6j-x0-sMS" firstAttribute="trailing" secondItem="Ocg-ig-pQt" secondAttribute="trailing" id="GXb-KG-d0p"/>
<constraint firstItem="OmR-2E-jXp" firstAttribute="bottom" secondItem="Ocg-ig-pQt" secondAttribute="bottom" id="aAd-fu-NMn"/>
<constraint firstItem="OmR-2E-jXp" firstAttribute="trailing" secondItem="Ocg-ig-pQt" secondAttribute="trailing" id="doC-hh-j5P"/>
<constraint firstItem="R6d-mo-itW" firstAttribute="top" secondItem="Ocg-ig-pQt" secondAttribute="top" id="gS5-1d-Huj"/>
<constraint firstItem="OmR-2E-jXp" firstAttribute="top" secondItem="R6d-mo-itW" secondAttribute="bottom" id="iEq-zu-8bV"/>
<constraint firstItem="J6j-x0-sMS" firstAttribute="leading" secondItem="Ocg-ig-pQt" secondAttribute="leading" id="iem-bg-Jp2"/>
<constraint firstItem="R6d-mo-itW" firstAttribute="leading" secondItem="Ocg-ig-pQt" secondAttribute="leading" id="irM-hU-WLy"/>
<constraint firstItem="J6j-x0-sMS" firstAttribute="top" secondItem="Ocg-ig-pQt" secondAttribute="top" id="rFN-Pq-kKP"/>
</constraints>
<viewLayoutGuide key="safeArea" id="Ocg-ig-pQt"/>
</view>
Expand All @@ -78,6 +68,11 @@
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="ixM-JR-6YX" userLabel="First Responder" sceneMemberID="firstResponder"/>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="R6d-mo-itW" customClass="FilterTabBar" customModule="WordPress">
<rect key="frame" x="0.0" y="0.0" width="375" height="46"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<viewLayoutGuide key="safeArea" id="C12-Oc-qio"/>
</view>
</objects>
<point key="canvasLocation" x="240.80000000000001" y="232.53373313343329"/>
</scene>
Expand All @@ -86,7 +81,7 @@
<objects>
<tableViewController id="Hcp-7d-sgU" userLabel="Insights Table View Controller" customClass="SiteStatsInsightsTableViewController" customModule="WordPress" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="qZC-N3-iSA">
<rect key="frame" x="0.0" y="0.0" width="375" height="557"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="603"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
Expand All @@ -108,7 +103,7 @@
<objects>
<tableViewController id="plb-uA-RCD" userLabel="Stats Table View Controller" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="zaS-th-YDU">
<rect key="frame" x="0.0" y="0.0" width="375" height="557"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="603"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class SiteStatsDashboardViewController: UIViewController {
@IBOutlet weak var insightsContainerView: UIView!
@IBOutlet weak var statsContainerView: UIView!

var insightsTableViewController: SiteStatsInsightsTableViewController?
private var currentTableDisplayed: UITableView?
private var insightsTableViewController: SiteStatsInsightsTableViewController?

// TODO: replace UITableViewController with real controller names that
// corresponds to Stats.

var statsTableViewController: UITableViewController?
// corresponds to DWMY Stats.
private var statsTableViewController: UITableViewController?

// MARK: - View

Expand Down Expand Up @@ -70,26 +70,17 @@ private extension SiteStatsDashboardViewController {
set {
filterTabBar?.setSelectedIndex(newValue.rawValue)
setContainerViewVisibility()
setupTableHeaderView()
saveSelectedPeriodToUserDefaults()
}
}

func setContainerViewVisibility() {
statsContainerView.isHidden = currentSelectedPeriod == .insights
insightsContainerView.isHidden = !statsContainerView.isHidden
}

func shouldShowProgressView(viewController: UIViewController) -> Bool {

var shouldShow = false

if viewController == insightsTableViewController {
shouldShow = !insightsContainerView.isHidden
} else if viewController == statsTableViewController {
shouldShow = !statsContainerView.isHidden
}

return shouldShow
currentTableDisplayed = statsContainerView.isHidden ?
insightsTableViewController?.tableView :
statsTableViewController?.tableView
}

}
Expand All @@ -104,6 +95,23 @@ private extension SiteStatsDashboardViewController {
filterTabBar.addTarget(self, action: #selector(selectedFilterDidChange(_:)), for: .valueChanged)
}

func setupTableHeaderView() {

guard let currentTableDisplayed = currentTableDisplayed else {
return
}

filterTabBar.translatesAutoresizingMaskIntoConstraints = false

currentTableDisplayed.tableHeaderView = filterTabBar

NSLayoutConstraint.activate([
filterTabBar.centerXAnchor.constraint(equalTo: currentTableDisplayed.centerXAnchor),
filterTabBar.topAnchor.constraint(equalTo: currentTableDisplayed.topAnchor),
filterTabBar.widthAnchor.constraint(equalTo: currentTableDisplayed.widthAnchor),
])
}

@objc func selectedFilterDidChange(_ filterBar: FilterTabBar) {
currentSelectedPeriod = StatsPeriodType(rawValue: filterBar.selectedIndex) ?? StatsPeriodType.insights

Expand All @@ -121,6 +129,14 @@ private extension SiteStatsDashboardViewController {
}

func getSelectedPeriodFromUserDefaults() {

// TODO: remove this when DWMY is added.
// Since the filterTabBar is added to tableHeaderView, if DWMY is selected
// the filterTabBar disappears and you're stuck on an empty view.
if statsTableViewController == nil {
currentSelectedPeriod = .insights
}

currentSelectedPeriod = StatsPeriodType(rawValue: UserDefaults.standard.integer(forKey: Constants.userDefaultsKey)) ?? .insights
}
}