Skip to content

Commit 053471d

Browse files
authored
Read the window from the view hierarchy across the app (#25716)
* Format view-local-window-reads files before migration * Read the window from the view hierarchy across the app * Remove unused stackViewTopConstraint from MenuItemEditingHeaderView The constraint was removed in 2019 but the readonly property was left behind, so it has been nil ever since. The status bar appearance update method that mutated it was a no-op, so it is removed along with its call sites. * Pass the Reader cover image size to cells instead of a window
1 parent 9956bcc commit 053471d

9 files changed

Lines changed: 762 additions & 344 deletions

File tree

WordPress/Classes/Jetpack/NUX/JetpackPrologueViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ extension JetpackPrologueViewController: InfiniteScrollViewDelegate {
152152
///
153153
/// - Returns: Points per second.
154154
private func rateForAngle(angle: Double) -> CGFloat {
155-
return -angle * Self.Constants.angleRateMultiplier
155+
-angle * Self.Constants.angleRateMultiplier
156156
}
157157

158158
/// Returns the angle in degrees of the device independently of the view's orientation.
@@ -170,7 +170,7 @@ extension JetpackPrologueViewController: InfiniteScrollViewDelegate {
170170

171171
let angleRad: Double
172172

173-
switch UIApplication.shared.currentStatusBarOrientation {
173+
switch view.window?.windowScene?.interfaceOrientation ?? .unknown {
174174
case .portrait:
175175
angleRad = attitude.pitch
176176
case .portraitUpsideDown:

WordPress/Classes/System/3D Touch/WP3DTouchShortcutCreator.swift

Lines changed: 73 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ public protocol ApplicationShortcutsProvider {
88

99
extension UIApplication: ApplicationShortcutsProvider {
1010
@objc public var is3DTouchAvailable: Bool {
11-
return mainWindow?.traitCollection.forceTouchCapability == .available
11+
connectedScenes.compactMap { ($0 as? UIWindowScene)?.keyWindow }.first?.traitCollection.forceTouchCapability
12+
== .available
1213
}
1314
}
1415

1516
open class WP3DTouchShortcutCreator: NSObject {
1617
enum LoggedIn3DTouchShortcutIndex: Int {
1718
case notifications = 0,
18-
stats,
19-
newPost
19+
stats,
20+
newPost
2021
}
2122

2223
var shortcutsProvider: ApplicationShortcutsProvider
@@ -50,18 +51,43 @@ open class WP3DTouchShortcutCreator: NSObject {
5051

5152
fileprivate func registerForNotifications() {
5253
let notificationCenter = NotificationCenter.default
53-
notificationCenter.addObserver(self, selector: #selector(WP3DTouchShortcutCreator.createLoggedInShortcuts), name: NSNotification.Name(rawValue: WordPressAuthenticationManager.WPSigninDidFinishNotification), object: nil)
54-
notificationCenter.addObserver(self, selector: #selector(WP3DTouchShortcutCreator.createLoggedInShortcuts), name: .WPRecentSitesChanged, object: nil)
55-
notificationCenter.addObserver(self, selector: #selector(WP3DTouchShortcutCreator.createLoggedInShortcuts), name: .WPBlogUpdated, object: nil)
56-
notificationCenter.addObserver(self, selector: #selector(WP3DTouchShortcutCreator.createLoggedInShortcuts), name: .wpAccountDefaultWordPressComAccountChanged, object: nil)
54+
notificationCenter.addObserver(
55+
self,
56+
selector: #selector(WP3DTouchShortcutCreator.createLoggedInShortcuts),
57+
name: NSNotification.Name(rawValue: WordPressAuthenticationManager.WPSigninDidFinishNotification),
58+
object: nil
59+
)
60+
notificationCenter.addObserver(
61+
self,
62+
selector: #selector(WP3DTouchShortcutCreator.createLoggedInShortcuts),
63+
name: .WPRecentSitesChanged,
64+
object: nil
65+
)
66+
notificationCenter.addObserver(
67+
self,
68+
selector: #selector(WP3DTouchShortcutCreator.createLoggedInShortcuts),
69+
name: .WPBlogUpdated,
70+
object: nil
71+
)
72+
notificationCenter.addObserver(
73+
self,
74+
selector: #selector(WP3DTouchShortcutCreator.createLoggedInShortcuts),
75+
name: .wpAccountDefaultWordPressComAccountChanged,
76+
object: nil
77+
)
5778
}
5879

5980
fileprivate func loggedOutShortcutArray() -> [UIApplicationShortcutItem] {
60-
let logInShortcut = UIMutableApplicationShortcutItem(type: WP3DTouchShortcutHandler.ShortcutIdentifier.LogIn.type,
61-
localizedTitle: NSLocalizedString("Log In", comment: "Log In 3D Touch Shortcut"),
62-
localizedSubtitle: nil,
63-
icon: UIApplicationShortcutIcon(systemImageName: "arrow.right.square"),
64-
userInfo: [WP3DTouchShortcutHandler.applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler.ShortcutIdentifier.LogIn.rawValue as NSSecureCoding])
81+
let logInShortcut = UIMutableApplicationShortcutItem(
82+
type: WP3DTouchShortcutHandler.ShortcutIdentifier.LogIn.type,
83+
localizedTitle: NSLocalizedString("Log In", comment: "Log In 3D Touch Shortcut"),
84+
localizedSubtitle: nil,
85+
icon: UIApplicationShortcutIcon(systemImageName: "arrow.right.square"),
86+
userInfo: [
87+
WP3DTouchShortcutHandler.applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler.ShortcutIdentifier
88+
.LogIn.rawValue as NSSecureCoding
89+
]
90+
)
6591

6692
return [logInShortcut]
6793
}
@@ -72,30 +98,45 @@ open class WP3DTouchShortcutCreator: NSObject {
7298
defaultBlogName = Blog.lastUsedOrFirst(in: mainContext)?.settings?.name
7399
}
74100

75-
let notificationsShortcut = UIMutableApplicationShortcutItem(type: WP3DTouchShortcutHandler.ShortcutIdentifier.Notifications.type,
76-
localizedTitle: NSLocalizedString("Notifications", comment: "Notifications 3D Touch Shortcut"),
77-
localizedSubtitle: nil,
78-
icon: UIApplicationShortcutIcon(systemImageName: "bell"),
79-
userInfo: [WP3DTouchShortcutHandler.applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler.ShortcutIdentifier.Notifications.rawValue as NSSecureCoding])
80-
81-
let statsShortcut = UIMutableApplicationShortcutItem(type: WP3DTouchShortcutHandler.ShortcutIdentifier.Stats.type,
82-
localizedTitle: NSLocalizedString("Stats", comment: "Stats 3D Touch Shortcut"),
83-
localizedSubtitle: defaultBlogName,
84-
icon: UIApplicationShortcutIcon(systemImageName: "chart.bar"),
85-
userInfo: [WP3DTouchShortcutHandler.applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler.ShortcutIdentifier.Stats.rawValue as NSSecureCoding])
86-
87-
let newPostShortcut = UIMutableApplicationShortcutItem(type: WP3DTouchShortcutHandler.ShortcutIdentifier.NewPost.type,
88-
localizedTitle: NSLocalizedString("New Post", comment: "New Post 3D Touch Shortcut"),
89-
localizedSubtitle: defaultBlogName,
90-
icon: UIApplicationShortcutIcon(systemImageName: "square.and.pencil"),
91-
userInfo: [WP3DTouchShortcutHandler.applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler.ShortcutIdentifier.NewPost.rawValue as NSSecureCoding])
101+
let notificationsShortcut = UIMutableApplicationShortcutItem(
102+
type: WP3DTouchShortcutHandler.ShortcutIdentifier.Notifications.type,
103+
localizedTitle: NSLocalizedString("Notifications", comment: "Notifications 3D Touch Shortcut"),
104+
localizedSubtitle: nil,
105+
icon: UIApplicationShortcutIcon(systemImageName: "bell"),
106+
userInfo: [
107+
WP3DTouchShortcutHandler.applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler.ShortcutIdentifier
108+
.Notifications.rawValue as NSSecureCoding
109+
]
110+
)
111+
112+
let statsShortcut = UIMutableApplicationShortcutItem(
113+
type: WP3DTouchShortcutHandler.ShortcutIdentifier.Stats.type,
114+
localizedTitle: NSLocalizedString("Stats", comment: "Stats 3D Touch Shortcut"),
115+
localizedSubtitle: defaultBlogName,
116+
icon: UIApplicationShortcutIcon(systemImageName: "chart.bar"),
117+
userInfo: [
118+
WP3DTouchShortcutHandler.applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler.ShortcutIdentifier
119+
.Stats.rawValue as NSSecureCoding
120+
]
121+
)
122+
123+
let newPostShortcut = UIMutableApplicationShortcutItem(
124+
type: WP3DTouchShortcutHandler.ShortcutIdentifier.NewPost.type,
125+
localizedTitle: NSLocalizedString("New Post", comment: "New Post 3D Touch Shortcut"),
126+
localizedSubtitle: defaultBlogName,
127+
icon: UIApplicationShortcutIcon(systemImageName: "square.and.pencil"),
128+
userInfo: [
129+
WP3DTouchShortcutHandler.applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler.ShortcutIdentifier
130+
.NewPost.rawValue as NSSecureCoding
131+
]
132+
)
92133

93134
return [notificationsShortcut, statsShortcut, newPostShortcut]
94135
}
95136

96137
@objc fileprivate func createLoggedInShortcuts() {
97138

98-
DispatchQueue.main.async {[weak self]() in
139+
DispatchQueue.main.async { [weak self] () in
99140
guard let strongSelf = self else {
100141
return
101142
}
@@ -125,14 +166,8 @@ open class WP3DTouchShortcutCreator: NSObject {
125166
shortcutsProvider.shortcutItems = loggedOutShortcutArray()
126167
}
127168

128-
fileprivate func is3DTouchAvailable() -> Bool {
129-
let window = UIApplication.shared.mainWindow
130-
131-
return window?.traitCollection.forceTouchCapability == .available
132-
}
133-
134169
fileprivate func hasWordPressComAccount() -> Bool {
135-
return AccountHelper.isDotcomAvailable()
170+
AccountHelper.isDotcomAvailable()
136171
}
137172

138173
fileprivate func doesCurrentBlogSupportStats() -> Bool {
@@ -144,6 +179,6 @@ open class WP3DTouchShortcutCreator: NSObject {
144179
}
145180

146181
fileprivate func hasBlog() -> Bool {
147-
return Blog.count(in: mainContext) > 0
182+
Blog.count(in: mainContext) > 0
148183
}
149184
}

WordPress/Classes/ViewRelated/Aztec/ViewControllers/AztecPostViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,7 @@ extension AztecPostViewController {
23122312

23132313
// Let's assume a sensible default for the keyboard height based on orientation
23142314
let keyboardFrameRatioDefault =
2315-
UIApplication.shared.currentStatusBarOrientation.isPortrait
2315+
view.window?.windowScene?.interfaceOrientation.isPortrait ?? true
23162316
? Constants.mediaPickerKeyboardHeightRatioPortrait : Constants.mediaPickerKeyboardHeightRatioLandscape
23172317
let keyboardHeightDefault = (keyboardFrameRatioDefault * UIScreen.main.bounds.height)
23182318

WordPress/Classes/ViewRelated/Menus/Controllers/MenuItemEditingViewController.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
144144

145145
- (BOOL)prefersStatusBarHidden
146146
{
147-
[self.headerView setNeedsTopConstraintsUpdateForStatusBarAppearence:self.headerView.hidden];
148147
return self.headerView.hidden;
149148
}
150149

@@ -229,7 +228,6 @@ - (void)updateLayoutIfNeeded
229228

230229
[self.stackView layoutIfNeeded];
231230
[self setNeedsStatusBarAppearanceUpdate];
232-
[self.headerView setNeedsTopConstraintsUpdateForStatusBarAppearence:self.headerView.hidden];
233231
}
234232

235233
- (void)updateLayoutIfNeededAnimated

WordPress/Classes/ViewRelated/Menus/Views/MenuItemEditingHeaderView.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ NS_ASSUME_NONNULL_BEGIN
2222
*/
2323
@property (nonatomic, strong, readonly) UITextField *textField;
2424

25-
/**
26-
Helper method for updating the layout based on statusBar changes.
27-
*/
28-
- (void)setNeedsTopConstraintsUpdateForStatusBarAppearence:(BOOL)hidden;
29-
3025
@end
3126

3227
@protocol MenuItemEditingHeaderViewDelegate <NSObject>

WordPress/Classes/ViewRelated/Menus/Views/MenuItemEditingHeaderView.m

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
@interface MenuItemEditingHeaderView () <UITextFieldDelegate>
1010

1111
@property (nonatomic, strong, readonly) UIStackView *stackView;
12-
@property (nonatomic, strong, readonly) NSLayoutConstraint *stackViewTopConstraint;
1312
@property (nonatomic, strong, readonly) UIImageView *iconView;
1413

1514
@end
@@ -131,18 +130,6 @@ - (CGFloat)defaultStackDesignMargin
131130
return ceilf(MenusDesignDefaultContentSpacing / 2.0);
132131
}
133132

134-
- (void)setNeedsTopConstraintsUpdateForStatusBarAppearence:(BOOL)hidden
135-
{
136-
if (hidden) {
137-
138-
self.stackViewTopConstraint.constant = [self defaultStackDesignMargin];
139-
140-
} else {
141-
142-
self.stackViewTopConstraint.constant = [self defaultStackDesignMargin] + [[UIApplication sharedApplication] currentStatusBarFrame].size.height;
143-
}
144-
}
145-
146133
- (void)setItemType:(NSString *)itemType
147134
{
148135
if (_itemType != itemType) {

0 commit comments

Comments
 (0)