Move ContextMenuPreviewViewController out of storyboard and into xib.

This commit is contained in:
Brent Simmons 2025-01-14 19:44:32 -08:00
parent 3f8b5195ba
commit 7322301be3
4 changed files with 125 additions and 105 deletions

View File

@ -9,24 +9,34 @@
import UIKit
import Articles
class ContextMenuPreviewViewController: UIViewController {
/// Used in the WebView when in full screen mode.
final class ContextMenuPreviewViewController: UIViewController {
@IBOutlet weak var blogNameLabel: UILabel!
@IBOutlet weak var blogAuthorLabel: UILabel!
@IBOutlet weak var articleTitleLabel: UILabel!
@IBOutlet weak var dateTimeLabel: UILabel!
var article: Article!
var article: Article?
init(article: Article?) {
self.article = article
super.init(nibName: "ContextMenuPreviewViewController", bundle: nil)
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override func viewDidLoad() {
super.viewDidLoad()
blogNameLabel.text = article.feed?.nameForDisplay ?? ""
blogAuthorLabel.text = article.byline()
articleTitleLabel.text = article.title ?? ""
blogNameLabel.text = article?.feed?.nameForDisplay ?? ""
blogAuthorLabel.text = article?.byline()
articleTitleLabel.text = article?.title ?? ""
let icon = IconView()
icon.iconImage = article.iconImage()
icon.iconImage = article?.iconImage()
icon.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(icon)
@ -40,8 +50,10 @@ class ContextMenuPreviewViewController: UIViewController {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .long
dateFormatter.timeStyle = .medium
dateTimeLabel.text = dateFormatter.string(from: article.logicalDatePublished)
if let article {
dateTimeLabel.text = dateFormatter.string(from: article.logicalDatePublished)
}
// When in landscape the context menu preview will force this controller into a tiny
// view space. If it is documented anywhere what that is, I haven't found it. This
// set of magic numbers is what I worked out by testing a variety of phones.

View File

@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="23504" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23506"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ContextMenuPreviewViewController" customModule="NetNewsWire" customModuleProvider="target">
<connections>
<outlet property="articleTitleLabel" destination="euU-Ij-5LS" id="SaE-2x-Lmt"/>
<outlet property="blogAuthorLabel" destination="yxD-bn-7rJ" id="e6N-4a-9gZ"/>
<outlet property="blogNameLabel" destination="VwJ-Ji-WmN" id="rvk-Ef-eXK"/>
<outlet property="dateTimeLabel" destination="tZE-CV-RS5" id="hvo-tH-m4w"/>
<outlet property="view" destination="reY-47-9dn" id="Uul-on-hM9"/>
</connections>
</placeholder>
<view contentMode="scaleToFill" id="reY-47-9dn">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Blog Name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VwJ-Ji-WmN">
<rect key="frame" x="20" y="8.0000000000000018" width="87" height="20.666666666666671"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<color key="textColor" name="primaryAccentColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Blog Author" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="yxD-bn-7rJ">
<rect key="frame" x="20" y="36.666666666666664" width="90" height="21"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Article Title" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="euU-Ij-5LS">
<rect key="frame" x="20" y="74.666666666666671" width="136" height="33.666666666666671"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle1"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tZE-CV-RS5">
<rect key="frame" x="20" y="116.33333333333333" width="44" height="20.333333333333329"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Xxd-ws-vsN">
<rect key="frame" x="325" y="8" width="48" height="48"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="width" constant="48" id="3zG-fk-K1j"/>
<constraint firstAttribute="height" constant="48" id="LUF-bb-x6X"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="PEP-UU-rG9">
<rect key="frame" x="20" y="65.666666666666671" width="353" height="1"/>
<color key="backgroundColor" systemColor="separatorColor"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="K9J-bi-mdi"/>
</constraints>
</view>
</subviews>
<viewLayoutGuide key="safeArea" id="Hb5-Na-kgr"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="tZE-CV-RS5" secondAttribute="bottom" constant="8" id="3rq-hS-dk8"/>
<constraint firstItem="yxD-bn-7rJ" firstAttribute="top" secondItem="VwJ-Ji-WmN" secondAttribute="bottom" constant="8" id="5xH-dU-ncD"/>
<constraint firstItem="PEP-UU-rG9" firstAttribute="top" secondItem="yxD-bn-7rJ" secondAttribute="bottom" constant="8" id="HaH-jK-jid"/>
<constraint firstItem="euU-Ij-5LS" firstAttribute="leading" secondItem="Hb5-Na-kgr" secondAttribute="leading" constant="20" id="OHK-XM-nZh"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="euU-Ij-5LS" secondAttribute="trailing" constant="20" id="ShD-8C-ek1"/>
<constraint firstItem="Xxd-ws-vsN" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="yxD-bn-7rJ" secondAttribute="trailing" constant="8" id="U9x-ti-Tu2"/>
<constraint firstItem="VwJ-Ji-WmN" firstAttribute="leading" secondItem="Hb5-Na-kgr" secondAttribute="leading" constant="20" id="VWZ-aZ-O9Q"/>
<constraint firstItem="tZE-CV-RS5" firstAttribute="top" secondItem="euU-Ij-5LS" secondAttribute="bottom" constant="8" id="YKK-UR-dnH"/>
<constraint firstItem="Xxd-ws-vsN" firstAttribute="top" secondItem="reY-47-9dn" secondAttribute="top" constant="8" id="ZyL-ai-qvZ"/>
<constraint firstAttribute="trailing" secondItem="PEP-UU-rG9" secondAttribute="trailing" constant="20" id="eKG-67-YFm"/>
<constraint firstItem="PEP-UU-rG9" firstAttribute="leading" secondItem="reY-47-9dn" secondAttribute="leading" constant="20" id="ebf-0Y-flG"/>
<constraint firstItem="VwJ-Ji-WmN" firstAttribute="top" secondItem="reY-47-9dn" secondAttribute="top" constant="8" id="ecl-RK-Ffb"/>
<constraint firstItem="Hb5-Na-kgr" firstAttribute="trailing" secondItem="Xxd-ws-vsN" secondAttribute="trailing" constant="20" id="kT7-Pv-6je"/>
<constraint firstItem="yxD-bn-7rJ" firstAttribute="leading" secondItem="Hb5-Na-kgr" secondAttribute="leading" constant="20" id="sqt-wW-SeY"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="tZE-CV-RS5" secondAttribute="trailing" constant="20" id="xac-fb-QAh"/>
<constraint firstItem="Xxd-ws-vsN" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="VwJ-Ji-WmN" secondAttribute="trailing" constant="8" id="xgp-8f-SqT"/>
<constraint firstItem="PEP-UU-rG9" firstAttribute="top" relation="greaterThanOrEqual" secondItem="Xxd-ws-vsN" secondAttribute="bottom" constant="8" id="yzA-bn-qZ1"/>
<constraint firstItem="euU-Ij-5LS" firstAttribute="top" secondItem="PEP-UU-rG9" secondAttribute="bottom" constant="8" id="zq0-Jn-mdy"/>
<constraint firstItem="tZE-CV-RS5" firstAttribute="leading" secondItem="Hb5-Na-kgr" secondAttribute="leading" constant="20" id="zs5-jN-xgs"/>
</constraints>
<point key="canvasLocation" x="3292" y="-1399"/>
</view>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
</objects>
<resources>
<namedColor name="primaryAccentColor">
<color red="0.031372549019607843" green="0.41568627450980394" blue="0.93333333333333335" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<systemColor name="separatorColor">
<color red="0.23529411764705882" green="0.23529411764705882" blue="0.2627450980392157" alpha="0.28999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>

View File

@ -720,9 +720,7 @@ private extension WebViewController {
}
func contextMenuPreviewProvider() -> UIViewController {
let previewProvider = UIStoryboard.main.instantiateController(ofType: ContextMenuPreviewViewController.self)
previewProvider.article = article
return previewProvider
ContextMenuPreviewViewController(article: article)
}
func prevArticleAction() -> UIAction? {

View File

@ -232,93 +232,6 @@
</objects>
<point key="canvasLocation" x="452" y="-1794"/>
</scene>
<!--Context Menu Preview View Controller-->
<scene sceneID="Tc4-Ma-XSa">
<objects>
<viewController storyboardIdentifier="ContextMenuPreviewViewController" id="CoM-D3-PNS" customClass="ContextMenuPreviewViewController" customModule="NetNewsWire" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="eH6-Fa-Tfi">
<rect key="frame" x="0.0" y="0.0" width="414" height="200"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Blog Name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YsT-Lt-Zry">
<rect key="frame" x="20" y="8" width="87" height="20.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<color key="textColor" name="primaryAccentColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Blog Author" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7GV-PV-YVq">
<rect key="frame" x="20" y="36.5" width="90" height="21"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Article Title" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="iFp-rn-HhQ">
<rect key="frame" x="20" y="74.5" width="136" height="33.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle1"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0Hz-Dv-MhU">
<rect key="frame" x="20" y="116" width="44" height="20.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="9Ms-dt-2M8">
<rect key="frame" x="346" y="8" width="48" height="48"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="width" constant="48" id="d19-Jv-DFz"/>
<constraint firstAttribute="height" constant="48" id="vvL-LM-Qkp"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="0ko-zB-cnS">
<rect key="frame" x="20" y="65.5" width="374" height="1"/>
<color key="backgroundColor" systemColor="separatorColor"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="IVk-Gd-niT"/>
</constraints>
</view>
</subviews>
<viewLayoutGuide key="safeArea" id="d1t-hb-otl"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="9Ms-dt-2M8" firstAttribute="top" secondItem="eH6-Fa-Tfi" secondAttribute="top" constant="8" id="ECM-0Y-axL"/>
<constraint firstItem="0Hz-Dv-MhU" firstAttribute="leading" secondItem="d1t-hb-otl" secondAttribute="leading" constant="20" id="GCs-jq-FwF"/>
<constraint firstItem="iFp-rn-HhQ" firstAttribute="top" secondItem="0ko-zB-cnS" secondAttribute="bottom" constant="8" id="HCu-Fi-dC8"/>
<constraint firstItem="7GV-PV-YVq" firstAttribute="top" secondItem="YsT-Lt-Zry" secondAttribute="bottom" constant="8" id="HCw-VQ-FWp"/>
<constraint firstItem="YsT-Lt-Zry" firstAttribute="top" secondItem="eH6-Fa-Tfi" secondAttribute="top" constant="8" id="IbT-5V-iPB"/>
<constraint firstItem="iFp-rn-HhQ" firstAttribute="leading" secondItem="d1t-hb-otl" secondAttribute="leading" constant="20" id="MyB-pX-SCv"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="iFp-rn-HhQ" secondAttribute="trailing" constant="20" id="NF0-QV-MJa"/>
<constraint firstItem="7GV-PV-YVq" firstAttribute="leading" secondItem="d1t-hb-otl" secondAttribute="leading" constant="20" id="Rh6-Ug-Rkf"/>
<constraint firstAttribute="trailing" secondItem="0ko-zB-cnS" secondAttribute="trailing" constant="20" id="Sfv-FQ-fXh"/>
<constraint firstItem="0Hz-Dv-MhU" firstAttribute="top" secondItem="iFp-rn-HhQ" secondAttribute="bottom" constant="8" id="b1a-tF-MdY"/>
<constraint firstItem="YsT-Lt-Zry" firstAttribute="leading" secondItem="d1t-hb-otl" secondAttribute="leading" constant="20" id="fXj-St-fed"/>
<constraint firstItem="9Ms-dt-2M8" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="7GV-PV-YVq" secondAttribute="trailing" constant="8" id="hkE-jR-WyS"/>
<constraint firstItem="0ko-zB-cnS" firstAttribute="top" relation="greaterThanOrEqual" secondItem="9Ms-dt-2M8" secondAttribute="bottom" constant="8" id="kvc-Go-qdz"/>
<constraint firstItem="d1t-hb-otl" firstAttribute="trailing" secondItem="9Ms-dt-2M8" secondAttribute="trailing" constant="20" id="mO6-1A-xSW"/>
<constraint firstItem="9Ms-dt-2M8" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="YsT-Lt-Zry" secondAttribute="trailing" constant="8" id="pAW-iQ-2lB"/>
<constraint firstItem="0ko-zB-cnS" firstAttribute="top" secondItem="7GV-PV-YVq" secondAttribute="bottom" constant="8" id="rVh-Lq-DrY"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="0Hz-Dv-MhU" secondAttribute="trailing" constant="20" id="sg6-sh-fl5"/>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="0Hz-Dv-MhU" secondAttribute="bottom" constant="8" id="usR-Xq-BeL"/>
<constraint firstItem="0ko-zB-cnS" firstAttribute="leading" secondItem="eH6-Fa-Tfi" secondAttribute="leading" constant="20" id="wPH-RZ-ZJq"/>
</constraints>
</view>
<nil key="simulatedTopBarMetrics"/>
<nil key="simulatedBottomBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<size key="freeformSize" width="414" height="200"/>
<connections>
<outlet property="articleTitleLabel" destination="iFp-rn-HhQ" id="nxQ-GW-QP3"/>
<outlet property="blogAuthorLabel" destination="7GV-PV-YVq" id="xoY-pG-H7S"/>
<outlet property="blogNameLabel" destination="YsT-Lt-Zry" id="WVx-Mh-Fn7"/>
<outlet property="dateTimeLabel" destination="0Hz-Dv-MhU" id="QaU-do-WRo"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="vGQ-wP-i7Q" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="3763.7681159420295" y="-983.03571428571422"/>
</scene>
</scenes>
<resources>
<image name="chevron.down" catalog="system" width="128" height="70"/>
@ -333,12 +246,6 @@
<namedColor name="barBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</namedColor>
<namedColor name="primaryAccentColor">
<color red="0.031372549019607843" green="0.41568627450980394" blue="0.93333333333333335" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<systemColor name="separatorColor">
<color red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.28999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>