From 1412998b4af6105b3f369a2cf930ad667f4a0d5a Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 29 Jun 2018 17:00:22 -0400 Subject: [PATCH] Rework isRTL. --- .../SlideOffAnimatedTransition.swift | 6 +-- .../AppSettings/AppSettingsViewController.m | 2 +- .../ViewControllers/CallViewController.swift | 2 +- .../ContactViewController.swift | 2 +- .../Cells/OWSContactShareView.m | 3 +- .../ConversationView/Cells/OWSMessageCell.m | 12 ++--- .../Cells/OWSMessageFooterView.m | 5 +- .../ConversationInputToolbar.m | 4 +- .../ConversationViewController.m | 8 ++- .../HomeView/HomeViewController.m | 4 +- .../MessageDetailViewController.swift | 8 ++- .../OWS2FAReminderViewController.swift | 2 +- .../Utils/MessageRecipientStatusUtils.swift | 49 +++++++------------ Signal/src/util/DateUtil.h | 2 +- Signal/src/util/DateUtil.m | 5 +- Signal/src/util/MainAppContext.m | 9 +++- Signal/src/views/ReminderView.swift | 2 +- .../categories/NSAttributedString+OWS.h | 8 ++- .../categories/NSAttributedString+OWS.m | 12 ++--- SignalMessaging/categories/NSString+OWS.h | 3 +- SignalMessaging/categories/NSString+OWS.m | 13 ++--- SignalMessaging/categories/UIView+OWS.h | 3 -- SignalMessaging/categories/UIView+OWS.m | 8 +-- .../categories/UIViewController+OWS.m | 5 +- .../contacts/SelectRecipientViewController.m | 3 +- SignalMessaging/utils/ConversationStyle.swift | 3 -- SignalServiceKit/src/Util/AppContext.h | 2 +- .../utils/ShareAppExtensionContext.m | 15 ++++-- 28 files changed, 84 insertions(+), 116 deletions(-) diff --git a/Signal/src/UserInterface/SlideOffAnimatedTransition.swift b/Signal/src/UserInterface/SlideOffAnimatedTransition.swift index c1fe66966..c3651d5e6 100644 --- a/Signal/src/UserInterface/SlideOffAnimatedTransition.swift +++ b/Signal/src/UserInterface/SlideOffAnimatedTransition.swift @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // import UIKit @@ -21,7 +21,7 @@ class SlideOffAnimatedTransition: NSObject, UIViewControllerAnimatedTransitionin } let width = containerView.frame.width - let offsetFrame = fromView.frame.offsetBy(dx: (containerView.isRTL() ? +width : -width), dy: 0) + let offsetFrame = fromView.frame.offsetBy(dx: (CurrentAppContext().isRTL ? +width : -width), dy: 0) toView.frame = fromView.frame fromView.layer.shadowRadius = 15.0 @@ -29,7 +29,7 @@ class SlideOffAnimatedTransition: NSObject, UIViewControllerAnimatedTransitionin toView.layer.opacity = 0.9 containerView.insertSubview(toView, belowSubview: fromView) - UIView.animate(withDuration: transitionDuration(using: transitionContext), delay:0, options: .curveLinear, animations: { + UIView.animate(withDuration: transitionDuration(using: transitionContext), delay: 0, options: .curveLinear, animations: { fromView.frame = offsetFrame toView.layer.opacity = 1.0 diff --git a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m index 59da6c037..2ed47ddf8 100644 --- a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m +++ b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m @@ -342,7 +342,7 @@ [subtitleLabel autoPinLeadingToSuperviewMargin]; [subtitleLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom]; - UIImage *disclosureImage = [UIImage imageNamed:(self.view.isRTL ? @"NavBarBack" : @"NavBarBackRTL")]; + UIImage *disclosureImage = [UIImage imageNamed:(CurrentAppContext().isRTL ? @"NavBarBack" : @"NavBarBackRTL")]; OWSAssert(disclosureImage); UIImageView *disclosureButton = [[UIImageView alloc] initWithImage:[disclosureImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]]; diff --git a/Signal/src/ViewControllers/CallViewController.swift b/Signal/src/ViewControllers/CallViewController.swift index 617d6012e..7c4b70a45 100644 --- a/Signal/src/ViewControllers/CallViewController.swift +++ b/Signal/src/ViewControllers/CallViewController.swift @@ -255,7 +255,7 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver, func createContactViews() { leaveCallViewButton = UIButton() - let backButtonImage = self.view.isRTL() ? #imageLiteral(resourceName: "NavBarBackRTL") : #imageLiteral(resourceName: "NavBarBack") + let backButtonImage = CurrentAppContext().isRTL ? #imageLiteral(resourceName: "NavBarBackRTL") : #imageLiteral(resourceName: "NavBarBack") leaveCallViewButton.setImage(backButtonImage, for: .normal) leaveCallViewButton.autoSetDimensions(to: CGSize(width: 40, height: 40)) leaveCallViewButton.addTarget(self, action: #selector(didTapLeaveCall(sender:)), for: .touchUpInside) diff --git a/Signal/src/ViewControllers/ContactViewController.swift b/Signal/src/ViewControllers/ContactViewController.swift index 945a9628b..0b02147af 100644 --- a/Signal/src/ViewControllers/ContactViewController.swift +++ b/Signal/src/ViewControllers/ContactViewController.swift @@ -219,7 +219,7 @@ class ContactViewController: OWSViewController, ContactShareViewHelperDelegate { backButton.autoPinEdge(toSuperviewEdge: .top) backButton.autoPinLeadingToSuperviewMargin() - let backIconName = (self.view.isRTL() ? "system_disclosure_indicator" : "system_disclosure_indicator_rtl") + let backIconName = (CurrentAppContext().isRTL ? "system_disclosure_indicator" : "system_disclosure_indicator_rtl") guard let backIconImage = UIImage(named: backIconName) else { owsFail("\(logTag) missing icon.") return topView diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSContactShareView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSContactShareView.m index da2972c48..1d1e20749 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSContactShareView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSContactShareView.m @@ -203,7 +203,8 @@ NS_ASSUME_NONNULL_BEGIN [labelsView addArrangedSubview:bottomLabel]; } - UIImage *disclosureImage = [UIImage imageNamed:(self.isRTL ? @"small_chevron_left" : @"small_chevron_right")]; + UIImage *disclosureImage = + [UIImage imageNamed:(CurrentAppContext().isRTL ? @"small_chevron_left" : @"small_chevron_right")]; OWSAssert(disclosureImage); UIImageView *disclosureImageView = [UIImageView new]; disclosureImageView.image = [disclosureImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m index 8569900bc..b6e43c341 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m @@ -84,7 +84,8 @@ NS_ASSUME_NONNULL_BEGIN [self.contentView addGestureRecognizer:longPress]; PanDirectionGestureRecognizer *panGesture = [[PanDirectionGestureRecognizer alloc] - initWithDirection:(self.isRTL ? PanDirectionLeft : PanDirectionRight)target:self + initWithDirection:(CurrentAppContext().isRTL ? PanDirectionLeft : PanDirectionRight) + target:self action:@selector(handlePanGesture:)]; [self addGestureRecognizer:panGesture]; } @@ -227,19 +228,16 @@ NS_ASSUME_NONNULL_BEGIN attributes:@{ NSFontAttributeName : self.dateHeaderFont, NSForegroundColorAttributeName : [UIColor lightGrayColor], - } - referenceView:self]; + }]; attributedText = [attributedText rtlSafeAppend:@" " attributes:@{ NSFontAttributeName : self.dateHeaderFont, - } - referenceView:self]; + }]; attributedText = [attributedText rtlSafeAppend:timeString attributes:@{ NSFontAttributeName : self.dateHeaderFont, NSForegroundColorAttributeName : [UIColor lightGrayColor], - } - referenceView:self]; + }]; self.dateHeaderLabel.attributedText = attributedText; diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageFooterView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageFooterView.m index 8bb4be310..2625e36ca 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageFooterView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageFooterView.m @@ -91,7 +91,7 @@ NS_ASSUME_NONNULL_BEGIN UIImage *_Nullable statusIndicatorImage = nil; MessageReceiptStatus messageStatus = - [MessageRecipientStatusUtils recipientStatusWithOutgoingMessage:outgoingMessage referenceView:self]; + [MessageRecipientStatusUtils recipientStatusWithOutgoingMessage:outgoingMessage]; switch (messageStatus) { case MessageReceiptStatusUploading: case MessageReceiptStatusSending: @@ -175,8 +175,7 @@ NS_ASSUME_NONNULL_BEGIN } TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)viewItem.interaction; - NSString *statusMessage = - [MessageRecipientStatusUtils receiptMessageWithOutgoingMessage:outgoingMessage referenceView:self]; + NSString *statusMessage = [MessageRecipientStatusUtils receiptMessageWithOutgoingMessage:outgoingMessage]; return statusMessage; } diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m index 42e6bb423..7a7fc7824 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m @@ -515,7 +515,7 @@ static const CGFloat ConversationInputToolbarBorderViewHeight = 0.5; NSMutableAttributedString *cancelString = [NSMutableAttributedString new]; const CGFloat cancelArrowFontSize = ScaleFromIPhone5To7Plus(18.4, 20.f); const CGFloat cancelFontSize = ScaleFromIPhone5To7Plus(14.f, 16.f); - NSString *arrowHead = (self.isRTL ? @"\uf105" : @"\uf104"); + NSString *arrowHead = (CurrentAppContext().isRTL ? @"\uf105" : @"\uf104"); [cancelString appendAttributedString:[[NSAttributedString alloc] initWithString:arrowHead @@ -589,7 +589,7 @@ static const CGFloat ConversationInputToolbarBorderViewHeight = 0.5; CGRect cancelLabelStartFrame = cancelLabel.frame; CGRect cancelLabelEndFrame = cancelLabel.frame; cancelLabelStartFrame.origin.x - = (self.isRTL ? -self.voiceMemoUI.bounds.size.width : self.voiceMemoUI.bounds.size.width); + = (CurrentAppContext().isRTL ? -self.voiceMemoUI.bounds.size.width : self.voiceMemoUI.bounds.size.width); cancelLabel.frame = cancelLabelStartFrame; [UIView animateWithDuration:0.35f delay:0.f diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index b4ae37c5e..839506bcc 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -4864,14 +4864,12 @@ typedef enum : NSUInteger { if (interactionType == OWSInteractionType_OutgoingMessage) { TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)viewItem.interaction; MessageReceiptStatus receiptStatus = - [MessageRecipientStatusUtils recipientStatusWithOutgoingMessage:outgoingMessage - referenceView:self.view]; + [MessageRecipientStatusUtils recipientStatusWithOutgoingMessage:outgoingMessage]; if (nextViewItem && nextViewItem.interaction.interactionType == interactionType) { TSOutgoingMessage *nextOutgoingMessage = (TSOutgoingMessage *)nextViewItem.interaction; MessageReceiptStatus nextReceiptStatus = - [MessageRecipientStatusUtils recipientStatusWithOutgoingMessage:nextOutgoingMessage - referenceView:self.view]; + [MessageRecipientStatusUtils recipientStatusWithOutgoingMessage:nextOutgoingMessage]; NSString *nextTimestampText = [DateUtil formatTimestampShort:nextViewItem.interaction.timestamp]; // We can skip the "outgoing message status" footer if the next message @@ -5013,7 +5011,7 @@ typedef enum : NSUInteger { self.currentShowMessageDetailsPanGesture = gestureRecognizer; const CGFloat swipeTranslation - = ([gestureRecognizer translationInView:self.view].x * (self.view.isRTL ? +1.f : -1.f)); + = ([gestureRecognizer translationInView:self.view].x * (CurrentAppContext().isRTL ? +1.f : -1.f)); const CGFloat ratioComplete = CGFloatClamp(swipeTranslation / self.view.frame.size.width, 0, 1); switch (gestureRecognizer.state) { diff --git a/Signal/src/ViewControllers/HomeView/HomeViewController.m b/Signal/src/ViewControllers/HomeView/HomeViewController.m index 9b22b1a56..df3595799 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewController.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewController.m @@ -424,7 +424,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations // too far apart and too far from the edge of the screen. So we use a smaller // leading inset tighten up the layout. CGFloat hInset = round((kBarButtonSize - image.size.width) * 0.5f); - if (self.view.isRTL) { + if (CurrentAppContext().isRTL) { imageEdgeInsets.right = hInset; imageEdgeInsets.left = round((kBarButtonSize - (image.size.width + hInset)) * 0.5f); } else { @@ -803,7 +803,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations cell.backgroundColor = [UIColor whiteColor]; - UIImage *disclosureImage = [UIImage imageNamed:(cell.isRTL ? @"NavBarBack" : @"NavBarBackRTL")]; + UIImage *disclosureImage = [UIImage imageNamed:(CurrentAppContext().isRTL ? @"NavBarBack" : @"NavBarBackRTL")]; OWSAssert(disclosureImage); UIImageView *disclosureImageView = [UIImageView new]; disclosureImageView.image = [disclosureImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; diff --git a/Signal/src/ViewControllers/MessageDetailViewController.swift b/Signal/src/ViewControllers/MessageDetailViewController.swift index 34eb91613..d32c10745 100644 --- a/Signal/src/ViewControllers/MessageDetailViewController.swift +++ b/Signal/src/ViewControllers/MessageDetailViewController.swift @@ -235,7 +235,7 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele continue } - let (recipientStatus, shortStatusMessage, _) = MessageRecipientStatusUtils.recipientStatusAndStatusMessage(outgoingMessage: outgoingMessage, recipientState: recipientState, referenceView: self.view) + let (recipientStatus, shortStatusMessage, _) = MessageRecipientStatusUtils.recipientStatusAndStatusMessage(outgoingMessage: outgoingMessage, recipientState: recipientState) guard recipientStatus == recipientStatusGroup else { continue @@ -279,14 +279,12 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele rows.append(valueRow(name: NSLocalizedString("MESSAGE_METADATA_VIEW_SENT_DATE_TIME", comment: "Label for the 'sent date & time' field of the 'message metadata' view."), - value: DateUtil.formatPastTimestampRelativeToNow(message.timestamp, - isRTL: self.view.isRTL()))) + value: DateUtil.formatPastTimestampRelativeToNow(message.timestamp))) if message as? TSIncomingMessage != nil { rows.append(valueRow(name: NSLocalizedString("MESSAGE_METADATA_VIEW_RECEIVED_DATE_TIME", comment: "Label for the 'received date & time' field of the 'message metadata' view."), - value: DateUtil.formatPastTimestampRelativeToNow(message.timestampForSorting(), - isRTL: self.view.isRTL()))) + value: DateUtil.formatPastTimestampRelativeToNow(message.timestampForSorting()))) } rows += addAttachmentMetadataRows() diff --git a/Signal/src/ViewControllers/OWS2FAReminderViewController.swift b/Signal/src/ViewControllers/OWS2FAReminderViewController.swift index 593b37773..6a5b6c33a 100644 --- a/Signal/src/ViewControllers/OWS2FAReminderViewController.swift +++ b/Signal/src/ViewControllers/OWS2FAReminderViewController.swift @@ -46,7 +46,7 @@ public class OWS2FAReminderViewController: UIViewController, PinEntryViewDelegat let attributes = [NSAttributedStringKey.font: pinEntryView.boldLabelFont] - let attributedInstructionsText = NSAttributedString(string: instructionsTextHeader, attributes: attributes).rtlSafeAppend(" ", referenceView: pinEntryView).rtlSafeAppend(instructionsTextBody, referenceView: pinEntryView) + let attributedInstructionsText = NSAttributedString(string: instructionsTextHeader, attributes: attributes).rtlSafeAppend(" ").rtlSafeAppend(instructionsTextBody) pinEntryView.attributedInstructionsText = attributedInstructionsText diff --git a/Signal/src/ViewControllers/Utils/MessageRecipientStatusUtils.swift b/Signal/src/ViewControllers/Utils/MessageRecipientStatusUtils.swift index df0ebfa44..f465c1747 100644 --- a/Signal/src/ViewControllers/Utils/MessageRecipientStatusUtils.swift +++ b/Signal/src/ViewControllers/Utils/MessageRecipientStatusUtils.swift @@ -27,40 +27,33 @@ public class MessageRecipientStatusUtils: NSObject { // This method is per-recipient. @objc public class func recipientStatus(outgoingMessage: TSOutgoingMessage, - recipientState: TSOutgoingMessageRecipientState, - referenceView: UIView) -> MessageReceiptStatus { + recipientState: TSOutgoingMessageRecipientState) -> MessageReceiptStatus { let (messageReceiptStatus, _, _) = recipientStatusAndStatusMessage(outgoingMessage: outgoingMessage, - recipientState: recipientState, - referenceView: referenceView) + recipientState: recipientState) return messageReceiptStatus } // This method is per-recipient. @objc public class func shortStatusMessage(outgoingMessage: TSOutgoingMessage, - recipientState: TSOutgoingMessageRecipientState, - referenceView: UIView) -> String { + recipientState: TSOutgoingMessageRecipientState) -> String { let (_, shortStatusMessage, _) = recipientStatusAndStatusMessage(outgoingMessage: outgoingMessage, - recipientState: recipientState, - referenceView: referenceView) + recipientState: recipientState) return shortStatusMessage } // This method is per-recipient. @objc public class func longStatusMessage(outgoingMessage: TSOutgoingMessage, - recipientState: TSOutgoingMessageRecipientState, - referenceView: UIView) -> String { + recipientState: TSOutgoingMessageRecipientState) -> String { let (_, _, longStatusMessage) = recipientStatusAndStatusMessage(outgoingMessage: outgoingMessage, - recipientState: recipientState, - referenceView: referenceView) + recipientState: recipientState) return longStatusMessage } // This method is per-recipient. class func recipientStatusAndStatusMessage(outgoingMessage: TSOutgoingMessage, - recipientState: TSOutgoingMessageRecipientState, - referenceView: UIView) -> (status: MessageReceiptStatus, shortStatusMessage: String, longStatusMessage: String) { + recipientState: TSOutgoingMessageRecipientState) -> (status: MessageReceiptStatus, shortStatusMessage: String, longStatusMessage: String) { switch recipientState.state { case .failed: @@ -83,20 +76,18 @@ public class MessageRecipientStatusUtils: NSObject { } case .sent: if let readTimestamp = recipientState.readTimestamp { - let timestampString = DateUtil.formatPastTimestampRelativeToNow(readTimestamp.uint64Value, - isRTL: referenceView.isRTL()) + let timestampString = DateUtil.formatPastTimestampRelativeToNow(readTimestamp.uint64Value) let shortStatusMessage = timestampString - let longStatusMessage = NSLocalizedString("MESSAGE_STATUS_READ", comment: "message footer for read messages").rtlSafeAppend(" ", referenceView: referenceView) - .rtlSafeAppend(timestampString, referenceView: referenceView) + let longStatusMessage = NSLocalizedString("MESSAGE_STATUS_READ", comment: "message footer for read messages").rtlSafeAppend(" ") + .rtlSafeAppend(timestampString) return (status:.read, shortStatusMessage:shortStatusMessage, longStatusMessage:longStatusMessage) } if let deliveryTimestamp = recipientState.deliveryTimestamp { - let timestampString = DateUtil.formatPastTimestampRelativeToNow(deliveryTimestamp.uint64Value, - isRTL: referenceView.isRTL()) + let timestampString = DateUtil.formatPastTimestampRelativeToNow(deliveryTimestamp.uint64Value) let shortStatusMessage = timestampString let longStatusMessage = NSLocalizedString("MESSAGE_STATUS_DELIVERED", - comment: "message status for message delivered to their recipient.").rtlSafeAppend(" ", referenceView: referenceView) - .rtlSafeAppend(timestampString, referenceView: referenceView) + comment: "message status for message delivered to their recipient.").rtlSafeAppend(" ") + .rtlSafeAppend(timestampString) return (status:.delivered, shortStatusMessage:shortStatusMessage, longStatusMessage:longStatusMessage) } let statusMessage = @@ -111,8 +102,7 @@ public class MessageRecipientStatusUtils: NSObject { } // This method is per-message. - internal class func receiptStatusAndMessage(outgoingMessage: TSOutgoingMessage, - referenceView: UIView) -> (status: MessageReceiptStatus, message: String) { + internal class func receiptStatusAndMessage(outgoingMessage: TSOutgoingMessage) -> (status: MessageReceiptStatus, message: String) { switch outgoingMessage.messageState { case .failed: @@ -145,18 +135,15 @@ public class MessageRecipientStatusUtils: NSObject { // This method is per-message. @objc - public class func receiptMessage(outgoingMessage: TSOutgoingMessage, - referenceView: UIView) -> String { - let (_, message ) = receiptStatusAndMessage(outgoingMessage: outgoingMessage, - referenceView: referenceView) + public class func receiptMessage(outgoingMessage: TSOutgoingMessage) -> String { + let (_, message ) = receiptStatusAndMessage(outgoingMessage: outgoingMessage) return message } // This method is per-message. @objc - public class func recipientStatus(outgoingMessage: TSOutgoingMessage, referenceView: UIView) -> MessageReceiptStatus { - let (status, _ ) = receiptStatusAndMessage(outgoingMessage: outgoingMessage, - referenceView: referenceView) + public class func recipientStatus(outgoingMessage: TSOutgoingMessage) -> MessageReceiptStatus { + let (status, _ ) = receiptStatusAndMessage(outgoingMessage: outgoingMessage) return status } diff --git a/Signal/src/util/DateUtil.h b/Signal/src/util/DateUtil.h index 913808b2e..b431ab5fd 100644 --- a/Signal/src/util/DateUtil.h +++ b/Signal/src/util/DateUtil.h @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN + (BOOL)dateIsYesterday:(NSDate *)date; + (NSString *)formatPastTimestampRelativeToNow:(uint64_t)pastTimestamp - isRTL:(BOOL)isRTL NS_SWIFT_NAME(formatPastTimestampRelativeToNow(_:isRTL:)); + NS_SWIFT_NAME(formatPastTimestampRelativeToNow(_:)); + (NSString *)formatTimestampShort:(uint64_t)timestamp; + (NSString *)formatDateShort:(NSDate *)date; diff --git a/Signal/src/util/DateUtil.m b/Signal/src/util/DateUtil.m index 3152b6e92..53a43d739 100644 --- a/Signal/src/util/DateUtil.m +++ b/Signal/src/util/DateUtil.m @@ -145,7 +145,7 @@ static NSString *const DATE_FORMAT_WEEKDAY = @"EEEE"; return [[calendar components:NSCalendarUnitDay fromDate:date1 toDate:date2 options:0] day]; } -+ (NSString *)formatPastTimestampRelativeToNow:(uint64_t)pastTimestamp isRTL:(BOOL)isRTL ++ (NSString *)formatPastTimestampRelativeToNow:(uint64_t)pastTimestamp { OWSCAssert(pastTimestamp > 0); @@ -161,8 +161,7 @@ static NSString *const DATE_FORMAT_WEEKDAY = @"EEEE"; } else { dateString = [[self dateFormatter] stringFromDate:pastDate]; } - return [[dateString rtlSafeAppend:@" " isRTL:isRTL] rtlSafeAppend:[[self timeFormatter] stringFromDate:pastDate] - isRTL:isRTL]; + return [[dateString rtlSafeAppend:@" "] rtlSafeAppend:[[self timeFormatter] stringFromDate:pastDate]]; } + (NSString *)formatTimestampShort:(uint64_t)timestamp diff --git a/Signal/src/util/MainAppContext.m b/Signal/src/util/MainAppContext.m index 7fed2dc6b..8efd8f70f 100644 --- a/Signal/src/util/MainAppContext.m +++ b/Signal/src/util/MainAppContext.m @@ -132,8 +132,13 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)isRTL { - return - [[UIApplication sharedApplication] userInterfaceLayoutDirection] == UIUserInterfaceLayoutDirectionRightToLeft; + static BOOL isRTL = NO; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + isRTL = [[UIApplication sharedApplication] userInterfaceLayoutDirection] + == UIUserInterfaceLayoutDirectionRightToLeft; + }); + return isRTL; } - (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle diff --git a/Signal/src/views/ReminderView.swift b/Signal/src/views/ReminderView.swift index adb5ec6e7..c84c3bb44 100644 --- a/Signal/src/views/ReminderView.swift +++ b/Signal/src/views/ReminderView.swift @@ -92,7 +92,7 @@ class ReminderView: UIView { // Show the disclosure indicator if this reminder has a tap action. if tapAction != nil { // Icon - let iconName = (self.isRTL() ? "system_disclosure_indicator_rtl" : "system_disclosure_indicator") + let iconName = (CurrentAppContext().isRTL ? "system_disclosure_indicator_rtl" : "system_disclosure_indicator") guard let iconImage = UIImage(named: iconName) else { owsFail("\(logTag) missing icon.") return diff --git a/SignalMessaging/categories/NSAttributedString+OWS.h b/SignalMessaging/categories/NSAttributedString+OWS.h index 4079d7a47..601d4b35d 100644 --- a/SignalMessaging/categories/NSAttributedString+OWS.h +++ b/SignalMessaging/categories/NSAttributedString+OWS.h @@ -1,15 +1,13 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // NS_ASSUME_NONNULL_BEGIN @interface NSAttributedString (OWS) -- (NSAttributedString *)rtlSafeAppend:(NSString *)text - attributes:(NSDictionary *)attributes - referenceView:(UIView *)referenceView; -- (NSAttributedString *)rtlSafeAppend:(NSAttributedString *)string referenceView:(UIView *)referenceView; +- (NSAttributedString *)rtlSafeAppend:(NSString *)text attributes:(NSDictionary *)attributes; +- (NSAttributedString *)rtlSafeAppend:(NSAttributedString *)string; @end diff --git a/SignalMessaging/categories/NSAttributedString+OWS.m b/SignalMessaging/categories/NSAttributedString+OWS.m index 107c2ee0f..203ddb308 100644 --- a/SignalMessaging/categories/NSAttributedString+OWS.m +++ b/SignalMessaging/categories/NSAttributedString+OWS.m @@ -1,9 +1,10 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "NSAttributedString+OWS.h" #import "UIView+OWS.h" +#import NS_ASSUME_NONNULL_BEGIN @@ -11,23 +12,20 @@ NS_ASSUME_NONNULL_BEGIN - (NSAttributedString *)rtlSafeAppend:(NSString *)text attributes:(NSDictionary *)attributes - referenceView:(UIView *)referenceView { OWSAssert(text); OWSAssert(attributes); - OWSAssert(referenceView); NSAttributedString *substring = [[NSAttributedString alloc] initWithString:text attributes:attributes]; - return [self rtlSafeAppend:substring referenceView:referenceView]; + return [self rtlSafeAppend:substring]; } -- (NSAttributedString *)rtlSafeAppend:(NSAttributedString *)string referenceView:(UIView *)referenceView +- (NSAttributedString *)rtlSafeAppend:(NSAttributedString *)string { OWSAssert(string); - OWSAssert(referenceView); NSMutableAttributedString *result = [NSMutableAttributedString new]; - if ([referenceView isRTL]) { + if (CurrentAppContext().isRTL) { [result appendAttributedString:string]; [result appendAttributedString:self]; } else { diff --git a/SignalMessaging/categories/NSString+OWS.h b/SignalMessaging/categories/NSString+OWS.h index e5f919c14..bcf120479 100644 --- a/SignalMessaging/categories/NSString+OWS.h +++ b/SignalMessaging/categories/NSString+OWS.h @@ -8,8 +8,7 @@ NS_ASSUME_NONNULL_BEGIN @interface NSString (OWS) -- (NSString *)rtlSafeAppend:(NSString *)string referenceView:(UIView *)referenceView; -- (NSString *)rtlSafeAppend:(NSString *)string isRTL:(BOOL)isRTL; +- (NSString *)rtlSafeAppend:(NSString *)string; - (NSString *)digitsOnly; diff --git a/SignalMessaging/categories/NSString+OWS.m b/SignalMessaging/categories/NSString+OWS.m index 130a76581..0cc97b1f6 100644 --- a/SignalMessaging/categories/NSString+OWS.m +++ b/SignalMessaging/categories/NSString+OWS.m @@ -4,6 +4,7 @@ #import "NSString+OWS.h" #import "UIView+OWS.h" +#import NS_ASSUME_NONNULL_BEGIN @@ -14,19 +15,11 @@ NS_ASSUME_NONNULL_BEGIN return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; } -- (NSString *)rtlSafeAppend:(NSString *)string referenceView:(UIView *)referenceView +- (NSString *)rtlSafeAppend:(NSString *)string { OWSAssert(string); - OWSAssert(referenceView); - return [self rtlSafeAppend:string isRTL:referenceView.isRTL]; -} - -- (NSString *)rtlSafeAppend:(NSString *)string isRTL:(BOOL)isRTL -{ - OWSAssert(string); - - if (isRTL) { + if (CurrentAppContext().isRTL) { return [string stringByAppendingString:self]; } else { return [self stringByAppendingString:string]; diff --git a/SignalMessaging/categories/UIView+OWS.h b/SignalMessaging/categories/UIView+OWS.h index 2cf35217f..e6998635d 100644 --- a/SignalMessaging/categories/UIView+OWS.h +++ b/SignalMessaging/categories/UIView+OWS.h @@ -77,9 +77,6 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value); // contents. // // NOTE: the margin values are inverted in RTL layouts. -// -// TODO: Remove this in favor of AppContext.isRTL() -- (BOOL)isRTL; - (NSArray *)autoPinLeadingAndTrailingToSuperviewMargin; - (NSLayoutConstraint *)autoPinLeadingToSuperviewMargin; diff --git a/SignalMessaging/categories/UIView+OWS.m b/SignalMessaging/categories/UIView+OWS.m index b82f7dff7..df4323ce6 100644 --- a/SignalMessaging/categories/UIView+OWS.m +++ b/SignalMessaging/categories/UIView+OWS.m @@ -251,12 +251,6 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value) #pragma mark - RTL -- (BOOL)isRTL -{ - return ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:self.semanticContentAttribute] - == UIUserInterfaceLayoutDirectionRightToLeft); -} - - (NSLayoutConstraint *)autoPinLeadingToSuperviewMargin { return [self autoPinLeadingToSuperviewMarginWithInset:0]; @@ -391,7 +385,7 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value) - (NSTextAlignment)textAlignmentUnnatural { - return (self.isRTL ? NSTextAlignmentLeft : NSTextAlignmentRight); + return (CurrentAppContext().isRTL ? NSTextAlignmentLeft : NSTextAlignmentRight); } - (void)setHLayoutMargins:(CGFloat)value diff --git a/SignalMessaging/categories/UIViewController+OWS.m b/SignalMessaging/categories/UIViewController+OWS.m index 143eb51ee..208a0cad6 100644 --- a/SignalMessaging/categories/UIViewController+OWS.m +++ b/SignalMessaging/categories/UIViewController+OWS.m @@ -2,9 +2,10 @@ // Copyright (c) 2018 Open Whisper Systems. All rights reserved. // -#import "UIViewController+OWS.h" #import "UIColor+OWS.h" #import "UIView+OWS.h" +#import "UIViewController+OWS.h" +#import NS_ASSUME_NONNULL_BEGIN @@ -53,7 +54,7 @@ NS_ASSUME_NONNULL_BEGIN OWSAssert(selector); UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom]; - BOOL isRTL = [backButton isRTL]; + BOOL isRTL = CurrentAppContext().isRTL; // Nudge closer to the left edge to match default back button item. const CGFloat kExtraLeftPadding = isRTL ? +0 : -8; diff --git a/SignalMessaging/contacts/SelectRecipientViewController.m b/SignalMessaging/contacts/SelectRecipientViewController.m index 9992043ad..bcb494a70 100644 --- a/SignalMessaging/contacts/SelectRecipientViewController.m +++ b/SignalMessaging/contacts/SelectRecipientViewController.m @@ -15,6 +15,7 @@ #import #import #import +#import #import #import #import @@ -241,7 +242,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien { _callingCode = callingCode; - NSString *titleFormat = ([UIView new].isRTL ? @"(%2$@) %1$@" : @"%1$@ (%2$@)"); + NSString *titleFormat = (CurrentAppContext().isRTL ? @"(%2$@) %1$@" : @"%1$@ (%2$@)"); NSString *title = [NSString stringWithFormat:titleFormat, callingCode, countryCode.uppercaseString]; [self.countryCodeButton setTitle:title forState:UIControlStateNormal]; [self.countryCodeButton layoutSubviews]; diff --git a/SignalMessaging/utils/ConversationStyle.swift b/SignalMessaging/utils/ConversationStyle.swift index ea54e89e7..4ad89fa46 100644 --- a/SignalMessaging/utils/ConversationStyle.swift +++ b/SignalMessaging/utils/ConversationStyle.swift @@ -9,8 +9,6 @@ public class ConversationStyle: NSObject { private let thread: TSThread - private let isRTL: Bool - // The width of the collection view. @objc public var viewWidth: CGFloat = 0 { didSet { @@ -54,7 +52,6 @@ public class ConversationStyle: NSObject { public required init(thread: TSThread) { self.thread = thread - self.isRTL = CurrentAppContext().isRTL self.primaryColor = ConversationStyle.primaryColor(thread: thread) super.init() diff --git a/SignalServiceKit/src/Util/AppContext.h b/SignalServiceKit/src/Util/AppContext.h index c6c665d95..1df5cb8ec 100755 --- a/SignalServiceKit/src/Util/AppContext.h +++ b/SignalServiceKit/src/Util/AppContext.h @@ -26,7 +26,7 @@ NSString *NSStringForUIApplicationState(UIApplicationState value); @property (nonatomic, readonly) BOOL isMainApp; @property (nonatomic, readonly) BOOL isMainAppAndActive; -// Whether the user is using a right-to-left language like Arabic +// Whether the user is using a right-to-left language like Arabic. @property (nonatomic, readonly) BOOL isRTL; @property (nonatomic, readonly) BOOL isRunningTests; diff --git a/SignalShareExtension/utils/ShareAppExtensionContext.m b/SignalShareExtension/utils/ShareAppExtensionContext.m index a35a2d8dd..1a24cec78 100644 --- a/SignalShareExtension/utils/ShareAppExtensionContext.m +++ b/SignalShareExtension/utils/ShareAppExtensionContext.m @@ -123,11 +123,16 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)isRTL { - // Borrowed from PureLayout's AppExtension compatible RTL support. - // App Extensions may not access -[UIApplication sharedApplication]; fall back to checking the bundle's preferred - // localization character direction - return [NSLocale characterDirectionForLanguage:[[NSBundle mainBundle] preferredLocalizations][0]] - == NSLocaleLanguageDirectionRightToLeft; + static BOOL isRTL = NO; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + // Borrowed from PureLayout's AppExtension compatible RTL support. + // App Extensions may not access -[UIApplication sharedApplication]; fall back to checking the bundle's + // preferred localization character direction + isRTL = [NSLocale characterDirectionForLanguage:[[NSBundle mainBundle] preferredLocalizations][0]] + == NSLocaleLanguageDirectionRightToLeft; + }); + return isRTL; } - (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle