From 1b1b3e796e1a6e70251e5c73e2f6faa180500034 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Thu, 9 Jan 2020 21:11:13 -0700 Subject: [PATCH] Shoehorn the controller into the little area allowed for context previews in landscape. Issue #1569 --- .../ContextMenuPreviewViewController.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/iOS/Article/ContextMenuPreviewViewController.swift b/iOS/Article/ContextMenuPreviewViewController.swift index f3b67be0d..3b7e18219 100644 --- a/iOS/Article/ContextMenuPreviewViewController.swift +++ b/iOS/Article/ContextMenuPreviewViewController.swift @@ -42,9 +42,24 @@ class ContextMenuPreviewViewController: UIViewController { dateFormatter.timeStyle = .medium 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. + + let width: CGFloat + let heightPadding: CGFloat + if view.bounds.width > view.bounds.height { + width = 260 + heightPadding = 16 + view.widthAnchor.constraint(equalToConstant: width).isActive = true + } else { + width = view.bounds.width + heightPadding = 8 + } + view.setNeedsLayout() view.layoutIfNeeded() - preferredContentSize = CGSize(width: view.bounds.width, height: dateTimeLabel.frame.maxY + 8) + preferredContentSize = CGSize(width: width, height: dateTimeLabel.frame.maxY + heightPadding) } }