Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ extension JetpackPrologueViewController: InfiniteScrollViewDelegate {
///
/// - Returns: Points per second.
private func rateForAngle(angle: Double) -> CGFloat {
return -angle * Self.Constants.angleRateMultiplier
-angle * Self.Constants.angleRateMultiplier
}

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

let angleRad: Double

switch UIApplication.shared.currentStatusBarOrientation {
switch view.window?.windowScene?.interfaceOrientation ?? .unknown {
case .portrait:
angleRad = attitude.pitch
case .portraitUpsideDown:
Expand Down
111 changes: 73 additions & 38 deletions WordPress/Classes/System/3D Touch/WP3DTouchShortcutCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ public protocol ApplicationShortcutsProvider {

extension UIApplication: ApplicationShortcutsProvider {
@objc public var is3DTouchAvailable: Bool {
return mainWindow?.traitCollection.forceTouchCapability == .available
connectedScenes.compactMap { ($0 as? UIWindowScene)?.keyWindow }.first?.traitCollection.forceTouchCapability
== .available
}
}

open class WP3DTouchShortcutCreator: NSObject {
enum LoggedIn3DTouchShortcutIndex: Int {
case notifications = 0,
stats,
newPost
stats,
newPost
}

var shortcutsProvider: ApplicationShortcutsProvider
Expand Down Expand Up @@ -50,18 +51,43 @@ open class WP3DTouchShortcutCreator: NSObject {

fileprivate func registerForNotifications() {
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(WP3DTouchShortcutCreator.createLoggedInShortcuts), name: NSNotification.Name(rawValue: WordPressAuthenticationManager.WPSigninDidFinishNotification), object: nil)
notificationCenter.addObserver(self, selector: #selector(WP3DTouchShortcutCreator.createLoggedInShortcuts), name: .WPRecentSitesChanged, object: nil)
notificationCenter.addObserver(self, selector: #selector(WP3DTouchShortcutCreator.createLoggedInShortcuts), name: .WPBlogUpdated, object: nil)
notificationCenter.addObserver(self, selector: #selector(WP3DTouchShortcutCreator.createLoggedInShortcuts), name: .wpAccountDefaultWordPressComAccountChanged, object: nil)
notificationCenter.addObserver(
self,
selector: #selector(WP3DTouchShortcutCreator.createLoggedInShortcuts),
name: NSNotification.Name(rawValue: WordPressAuthenticationManager.WPSigninDidFinishNotification),
object: nil
)
notificationCenter.addObserver(
self,
selector: #selector(WP3DTouchShortcutCreator.createLoggedInShortcuts),
name: .WPRecentSitesChanged,
object: nil
)
notificationCenter.addObserver(
self,
selector: #selector(WP3DTouchShortcutCreator.createLoggedInShortcuts),
name: .WPBlogUpdated,
object: nil
)
notificationCenter.addObserver(
self,
selector: #selector(WP3DTouchShortcutCreator.createLoggedInShortcuts),
name: .wpAccountDefaultWordPressComAccountChanged,
object: nil
)
}

fileprivate func loggedOutShortcutArray() -> [UIApplicationShortcutItem] {
let logInShortcut = UIMutableApplicationShortcutItem(type: WP3DTouchShortcutHandler.ShortcutIdentifier.LogIn.type,
localizedTitle: NSLocalizedString("Log In", comment: "Log In 3D Touch Shortcut"),
localizedSubtitle: nil,
icon: UIApplicationShortcutIcon(systemImageName: "arrow.right.square"),
userInfo: [WP3DTouchShortcutHandler.applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler.ShortcutIdentifier.LogIn.rawValue as NSSecureCoding])
let logInShortcut = UIMutableApplicationShortcutItem(
type: WP3DTouchShortcutHandler.ShortcutIdentifier.LogIn.type,
localizedTitle: NSLocalizedString("Log In", comment: "Log In 3D Touch Shortcut"),
localizedSubtitle: nil,
icon: UIApplicationShortcutIcon(systemImageName: "arrow.right.square"),
userInfo: [
WP3DTouchShortcutHandler.applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler.ShortcutIdentifier
.LogIn.rawValue as NSSecureCoding
]
)

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

let notificationsShortcut = UIMutableApplicationShortcutItem(type: WP3DTouchShortcutHandler.ShortcutIdentifier.Notifications.type,
localizedTitle: NSLocalizedString("Notifications", comment: "Notifications 3D Touch Shortcut"),
localizedSubtitle: nil,
icon: UIApplicationShortcutIcon(systemImageName: "bell"),
userInfo: [WP3DTouchShortcutHandler.applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler.ShortcutIdentifier.Notifications.rawValue as NSSecureCoding])

let statsShortcut = UIMutableApplicationShortcutItem(type: WP3DTouchShortcutHandler.ShortcutIdentifier.Stats.type,
localizedTitle: NSLocalizedString("Stats", comment: "Stats 3D Touch Shortcut"),
localizedSubtitle: defaultBlogName,
icon: UIApplicationShortcutIcon(systemImageName: "chart.bar"),
userInfo: [WP3DTouchShortcutHandler.applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler.ShortcutIdentifier.Stats.rawValue as NSSecureCoding])

let newPostShortcut = UIMutableApplicationShortcutItem(type: WP3DTouchShortcutHandler.ShortcutIdentifier.NewPost.type,
localizedTitle: NSLocalizedString("New Post", comment: "New Post 3D Touch Shortcut"),
localizedSubtitle: defaultBlogName,
icon: UIApplicationShortcutIcon(systemImageName: "square.and.pencil"),
userInfo: [WP3DTouchShortcutHandler.applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler.ShortcutIdentifier.NewPost.rawValue as NSSecureCoding])
let notificationsShortcut = UIMutableApplicationShortcutItem(
type: WP3DTouchShortcutHandler.ShortcutIdentifier.Notifications.type,
localizedTitle: NSLocalizedString("Notifications", comment: "Notifications 3D Touch Shortcut"),
localizedSubtitle: nil,
icon: UIApplicationShortcutIcon(systemImageName: "bell"),
userInfo: [
WP3DTouchShortcutHandler.applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler.ShortcutIdentifier
.Notifications.rawValue as NSSecureCoding
]
)

let statsShortcut = UIMutableApplicationShortcutItem(
type: WP3DTouchShortcutHandler.ShortcutIdentifier.Stats.type,
localizedTitle: NSLocalizedString("Stats", comment: "Stats 3D Touch Shortcut"),
localizedSubtitle: defaultBlogName,
icon: UIApplicationShortcutIcon(systemImageName: "chart.bar"),
userInfo: [
WP3DTouchShortcutHandler.applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler.ShortcutIdentifier
.Stats.rawValue as NSSecureCoding
]
)

let newPostShortcut = UIMutableApplicationShortcutItem(
type: WP3DTouchShortcutHandler.ShortcutIdentifier.NewPost.type,
localizedTitle: NSLocalizedString("New Post", comment: "New Post 3D Touch Shortcut"),
localizedSubtitle: defaultBlogName,
icon: UIApplicationShortcutIcon(systemImageName: "square.and.pencil"),
userInfo: [
WP3DTouchShortcutHandler.applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler.ShortcutIdentifier
.NewPost.rawValue as NSSecureCoding
]
)

return [notificationsShortcut, statsShortcut, newPostShortcut]
}

@objc fileprivate func createLoggedInShortcuts() {

DispatchQueue.main.async {[weak self]() in
DispatchQueue.main.async { [weak self] () in
guard let strongSelf = self else {
return
}
Expand Down Expand Up @@ -125,14 +166,8 @@ open class WP3DTouchShortcutCreator: NSObject {
shortcutsProvider.shortcutItems = loggedOutShortcutArray()
}

fileprivate func is3DTouchAvailable() -> Bool {
let window = UIApplication.shared.mainWindow

return window?.traitCollection.forceTouchCapability == .available
}

fileprivate func hasWordPressComAccount() -> Bool {
return AccountHelper.isDotcomAvailable()
AccountHelper.isDotcomAvailable()
}

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

fileprivate func hasBlog() -> Bool {
return Blog.count(in: mainContext) > 0
Blog.count(in: mainContext) > 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2312,7 +2312,7 @@ extension AztecPostViewController {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ - (void)setNeedsTopConstraintsUpdateForStatusBarAppearence:(BOOL)hidden

} else {

self.stackViewTopConstraint.constant = [self defaultStackDesignMargin] + [[UIApplication sharedApplication] currentStatusBarFrame].size.height;
self.stackViewTopConstraint.constant = [self defaultStackDesignMargin] + self.window.windowScene.statusBarManager.statusBarFrame.size.height;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude thinks that stackViewTopConstraint is actually unused entirely and can be removed 🤷

}
}

Expand Down
Loading