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 @@ -144,7 +144,6 @@ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

- (BOOL)prefersStatusBarHidden
{
[self.headerView setNeedsTopConstraintsUpdateForStatusBarAppearence:self.headerView.hidden];
return self.headerView.hidden;
}

Expand Down Expand Up @@ -229,7 +228,6 @@ - (void)updateLayoutIfNeeded

[self.stackView layoutIfNeeded];
[self setNeedsStatusBarAppearanceUpdate];
[self.headerView setNeedsTopConstraintsUpdateForStatusBarAppearence:self.headerView.hidden];
}

- (void)updateLayoutIfNeededAnimated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, strong, readonly) UITextField *textField;

/**
Helper method for updating the layout based on statusBar changes.
*/
- (void)setNeedsTopConstraintsUpdateForStatusBarAppearence:(BOOL)hidden;

@end

@protocol MenuItemEditingHeaderViewDelegate <NSObject>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
@interface MenuItemEditingHeaderView () <UITextFieldDelegate>

@property (nonatomic, strong, readonly) UIStackView *stackView;
@property (nonatomic, strong, readonly) NSLayoutConstraint *stackViewTopConstraint;
@property (nonatomic, strong, readonly) UIImageView *iconView;

@end
Expand Down Expand Up @@ -131,18 +130,6 @@ - (CGFloat)defaultStackDesignMargin
return ceilf(MenusDesignDefaultContentSpacing / 2.0);
}

- (void)setNeedsTopConstraintsUpdateForStatusBarAppearence:(BOOL)hidden
{
if (hidden) {

self.stackViewTopConstraint.constant = [self defaultStackDesignMargin];

} else {

self.stackViewTopConstraint.constant = [self defaultStackDesignMargin] + [[UIApplication sharedApplication] currentStatusBarFrame].size.height;
}
}

- (void)setItemType:(NSString *)itemType
{
if (_itemType != itemType) {
Expand Down
Loading