Skip to content

Commit

Permalink
Modernize menus and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Jan 3, 2025
1 parent a337327 commit 56ef3a7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,7 @@ class RevisionDiffsBrowserViewController: UIViewController {
@IBOutlet private var previousButton: UIButton!
@IBOutlet private var nextButton: UIButton!

private lazy var doneBarButtonItem: UIBarButtonItem = {
let doneItem = UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: nil)
doneItem.title = NSLocalizedString("Done", comment: "Label on button to dismiss revisions view")
doneItem.on() { [weak self] _ in
WPAnalytics.track(.postRevisionsDetailCancelled)
self?.dismiss(animated: true)
}
return doneItem
}()

private lazy var moreBarButtonItem: UIBarButtonItem = {
let image = UIImage(systemName: "ellipsis")
let button = UIButton(type: .system)
button.setImage(image, for: .normal)
button.frame = CGRect(origin: .zero, size: image?.size ?? .zero)
button.accessibilityLabel = NSLocalizedString("More", comment: "Action button to display more available options")
button.on(.touchUpInside) { [weak self] _ in
self?.moreWasPressed()
}
button.setContentHuggingPriority(.required, for: .horizontal)
return UIBarButtonItem(customView: button)
}()
private lazy var moreBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "ellipsis"), menu: makeMoreMenu())

private lazy var loadBarButtonItem: UIBarButtonItem = {
let title = NSLocalizedString("Load", comment: "Title of the screen that load selected the revisions.")
Expand Down Expand Up @@ -111,6 +90,13 @@ class RevisionDiffsBrowserViewController: UIViewController {
}
}
}

// MARK: - Actions

@objc private func buttonCloseTapped() {
WPAnalytics.track(.postRevisionsDetailCancelled)
dismiss(animated: true)
}
}

private extension RevisionDiffsBrowserViewController {
Expand Down Expand Up @@ -141,7 +127,7 @@ private extension RevisionDiffsBrowserViewController {
}

private func setupNavbarItems() {
navigationItem.leftBarButtonItems = [doneBarButtonItem]
navigationItem.leftBarButtonItem = UIBarButtonItem(title: SharedStrings.Button.close, style: .plain, target: self, action: #selector(buttonCloseTapped))
navigationItem.rightBarButtonItems = [moreBarButtonItem, loadBarButtonItem]
navigationItem.title = NSLocalizedString("Revision", comment: "Title of the screen that shows the revisions.")
strokeView.backgroundColor = .separator
Expand Down Expand Up @@ -234,14 +220,19 @@ private extension RevisionDiffsBrowserViewController {
})
}

private func moreWasPressed() {
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
alert.addDefaultActionWithTitle(contentPreviewState.toggle().title) { [unowned self] _ in
self.triggerPreviewState()
private func makeMoreMenu() -> UIMenu {
UIMenu(options: .displayInline, children: [
UIDeferredMenuElement.uncached { [weak self] in
$0(self?.makeMoreMenuActions() ?? [])
}
])
}

private func makeMoreMenuActions() -> [UIAction] {
let toggleMode = UIAction(title: contentPreviewState.toggle().title) { [weak self] _ in
self?.triggerPreviewState()
}
alert.addCancelActionWithTitle(NSLocalizedString("Not Now", comment: "Nicer dialog answer for \"No\"."))
alert.popoverPresentationController?.barButtonItem = moreBarButtonItem
present(alert, animated: true)
return [toggleMode]
}

private func trackRevisionsDetailViewed(with source: ShowRevisionSource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<containerView opaque="NO" contentMode="scaleToFill" layoutMarginsFollowReadableWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uhq-mq-TeO">
<rect key="frame" x="0.0" y="0.0" width="375" height="559"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="539"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
<segue destination="1re-Hq-Vps" kind="embed" id="UdL-Ti-ban"/>
</connections>
</containerView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="5Tr-wY-fAM" userLabel="Toolbar">
<rect key="frame" x="0.0" y="559" width="375" height="64"/>
<rect key="frame" x="0.0" y="539" width="375" height="84"/>
<subviews>
<view contentMode="scaleToFill" layoutMarginsFollowReadableWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rsS-xc-ge8">
<rect key="frame" x="0.0" y="0.0" width="375" height="64"/>
Expand All @@ -53,13 +53,15 @@
<constraint firstAttribute="height" constant="50" id="kHo-9b-a0K"/>
<constraint firstAttribute="width" constant="50" id="xyN-oS-DyY"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Und-hy-I90">
<rect key="frame" x="325" y="7" width="50" height="50"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="MHQ-95-69R"/>
<constraint firstAttribute="width" constant="50" id="gYY-PG-gPN"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="7EM-Lu-3t1" userLabel="Stroke">
<rect key="frame" x="0.0" y="0.0" width="375" height="1"/>
Expand All @@ -69,7 +71,7 @@
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="0zh-of-VUW">
<rect key="frame" x="107.5" y="11" width="160" height="42"/>
<rect key="frame" x="107.5" y="12" width="160" height="40"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Revision Description" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1Hg-z8-YVh">
<rect key="frame" x="0.0" y="0.0" width="160" height="20"/>
Expand All @@ -81,7 +83,7 @@
<nil key="highlightedColor"/>
</label>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="T2k-GK-3TX">
<rect key="frame" x="0.0" y="24" width="160" height="18"/>
<rect key="frame" x="0.0" y="22" width="160" height="18"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="Mzl-br-Npx"/>
</constraints>
Expand All @@ -92,7 +94,7 @@
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="T2k-GK-3TX" firstAttribute="top" secondItem="1Hg-z8-YVh" secondAttribute="bottom" constant="4" id="C5J-9t-sd9"/>
<constraint firstItem="T2k-GK-3TX" firstAttribute="top" secondItem="1Hg-z8-YVh" secondAttribute="bottom" constant="2" id="C5J-9t-sd9"/>
<constraint firstItem="1Hg-z8-YVh" firstAttribute="top" secondItem="0zh-of-VUW" secondAttribute="top" id="Isk-s9-MoC"/>
<constraint firstItem="T2k-GK-3TX" firstAttribute="leading" secondItem="0zh-of-VUW" secondAttribute="leading" id="OVE-Zq-Uop"/>
<constraint firstAttribute="trailing" secondItem="1Hg-z8-YVh" secondAttribute="trailing" id="SbP-Xp-OCn"/>
Expand Down Expand Up @@ -132,7 +134,7 @@
<constraint firstItem="5Tr-wY-fAM" firstAttribute="top" secondItem="uhq-mq-TeO" secondAttribute="bottom" id="AVa-uM-bsF"/>
<constraint firstItem="lB6-fr-eSA" firstAttribute="leading" secondItem="5Tr-wY-fAM" secondAttribute="leading" id="DfJ-vx-yjq"/>
<constraint firstItem="uhq-mq-TeO" firstAttribute="trailing" secondItem="lB6-fr-eSA" secondAttribute="trailing" id="N9d-9c-2sc"/>
<constraint firstItem="rsS-xc-ge8" firstAttribute="bottom" secondItem="lB6-fr-eSA" secondAttribute="bottom" constant="20" id="bSo-EE-cLw"/>
<constraint firstItem="rsS-xc-ge8" firstAttribute="bottom" secondItem="lB6-fr-eSA" secondAttribute="bottom" id="bSo-EE-cLw"/>
<constraint firstItem="uhq-mq-TeO" firstAttribute="top" secondItem="lB6-fr-eSA" secondAttribute="top" id="fNe-Eg-VBR"/>
<constraint firstItem="5Tr-wY-fAM" firstAttribute="trailing" secondItem="lB6-fr-eSA" secondAttribute="trailing" id="gmP-ii-spL"/>
<constraint firstItem="5Tr-wY-fAM" firstAttribute="bottom" secondItem="lB6-fr-eSA" secondAttribute="bottom" constant="20" id="iyl-3G-clj"/>
Expand Down

0 comments on commit 56ef3a7

Please sign in to comment.