Skip to content

Commit de37b1d

Browse files
Merge branch 'mlin/PR/SafetyNumberSheetStyle' into release/5.0.0
2 parents 1bad6da + e89e6b1 commit de37b1d

File tree

10 files changed

+228
-102
lines changed

10 files changed

+228
-102
lines changed

Signal/src/ViewControllers/SafetyNumberConfirmationSheet.swift

Lines changed: 141 additions & 77 deletions
Large diffs are not rendered by default.

SignalMessaging/ViewControllers/ActionSheetController.swift

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,16 @@ open class ActionSheetController: OWSViewController {
9494
}
9595
action.button.applyActionSheetTheme(theme)
9696

97-
let hairline = UIView()
98-
hairline.backgroundColor = theme.hairlineColor
99-
hairline.autoSetDimension(.height, toSize: 1)
100-
10197
// If we've already added a cancel action, any non-cancel actions should come before it
10298
// This matches how UIAlertController handles cancel actions.
10399
if action.style != .cancel,
104100
let firstCancelAction = firstCancelAction,
105101
let index = stackView.arrangedSubviews.firstIndex(of: firstCancelAction.button) {
106102
// The hairline we're inserting is the divider between the new button and the cancel button
107-
stackView.insertArrangedSubview(hairline, at: index)
103+
stackView.insertHairline(with: theme.hairlineColor, at: index)
108104
stackView.insertArrangedSubview(action.button, at: index)
109105
} else {
110-
stackView.addArrangedSubview(hairline)
106+
stackView.addHairline(with: theme.hairlineColor)
111107
stackView.addArrangedSubview(action.button)
112108
}
113109
action.button.contentAlignment = contentAlignment
@@ -172,11 +168,11 @@ open class ActionSheetController: OWSViewController {
172168
//
173169
// This means that the backdrop view will extend outside of the bounds of the content view as the user
174170
// scrolls the content out of the safe area
175-
let backdropView = theme.createBackdropView()
176-
contentView.addSubview(backdropView)
177-
backdropView.autoPinWidthToSuperview()
178-
backdropView.autoPinEdge(.top, to: .top, of: contentView)
179-
scrollView.frameLayoutGuide.bottomAnchor.constraint(equalTo: backdropView.bottomAnchor).isActive = true
171+
let backgroundView = theme.createBackgroundView()
172+
contentView.addSubview(backgroundView)
173+
backgroundView.autoPinWidthToSuperview()
174+
backgroundView.autoPinEdge(.top, to: .top, of: contentView)
175+
scrollView.frameLayoutGuide.bottomAnchor.constraint(equalTo: backgroundView.bottomAnchor).isActive = true
180176

181177
// Stack views don't support corner masking pre-iOS 14
182178
// Instead we add our stack view to a wrapper view with masksToBounds: true
@@ -192,7 +188,7 @@ open class ActionSheetController: OWSViewController {
192188
// view's bounds. But its two subviews are pinned at same top edge. We can just apply corner
193189
// radii to each layer individually to get a similar effect.
194190
let cornerRadius: CGFloat = 16
195-
[backdropView, stackViewContainer].forEach { subview in
191+
[backgroundView, stackViewContainer].forEach { subview in
196192
subview.layer.cornerRadius = cornerRadius
197193
subview.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
198194
subview.layer.masksToBounds = true
@@ -465,7 +461,7 @@ public class ActionSheetAction: NSObject {
465461
fatalError("init(coder:) has not been implemented")
466462
}
467463

468-
func applyActionSheetTheme(_ theme: Theme.ActionSheet) {
464+
public func applyActionSheetTheme(_ theme: Theme.ActionSheet) {
469465
// Recolor everything based on the requested theme
470466
setBackgroundImage(UIImage(color: theme.buttonHighlightColor), for: .highlighted)
471467

SignalMessaging/Views/ContactCellView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ extern const CGFloat kContactCellAvatarTextMargin;
1212

1313
@interface ContactCellView : UIStackView
1414

15+
@property (assign, nonatomic) BOOL forceDarkAppearance;
16+
1517
@property (nonatomic, nullable) NSString *accessoryMessage;
1618

1719
@property (nonatomic, nullable) NSAttributedString *customName;

SignalMessaging/Views/ContactCellView.m

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,17 @@ - (void)configureFontsAndColors
117117
self.subtitleLabel.font = [UIFont ows_regularFontWithSize:11.f];
118118
self.accessoryLabel.font = [UIFont ows_semiboldFontWithSize:12.f];
119119

120-
self.nameLabel.textColor = Theme.primaryTextColor;
121-
self.subtitleLabel.textColor = Theme.secondaryTextAndIconColor;
120+
self.nameLabel.textColor = self.forceDarkAppearance ? Theme.darkThemePrimaryColor : Theme.primaryTextColor;
121+
self.subtitleLabel.textColor
122+
= self.forceDarkAppearance ? Theme.darkThemeSecondaryTextAndIconColor : Theme.secondaryTextAndIconColor;
122123
self.accessoryLabel.textColor = Theme.middleGrayColor;
124+
125+
if (self.nameLabel.attributedText.string.length > 0) {
126+
NSString *nameLabelText = self.nameLabel.attributedText.string;
127+
NSDictionary *updatedAttributes = @{ NSForegroundColorAttributeName : self.nameLabel.textColor };
128+
self.nameLabel.attributedText = [[NSAttributedString alloc] initWithString:nameLabelText
129+
attributes:updatedAttributes];
130+
}
123131
}
124132

125133
- (void)configureWithRecipientAddress:(SignalServiceAddress *)address
@@ -178,7 +186,7 @@ - (void)configureWithThread:(TSThread *)thread transaction:(SDSAnyReadTransactio
178186
NSAttributedString *attributedText =
179187
[[NSAttributedString alloc] initWithString:threadName
180188
attributes:@{
181-
NSForegroundColorAttributeName : Theme.primaryTextColor,
189+
NSForegroundColorAttributeName : self.nameLabel.textColor,
182190
}];
183191
self.nameLabel.attributedText = attributedText;
184192
}
@@ -231,6 +239,14 @@ - (NSUInteger)avatarSize
231239
return self.useSmallAvatars ? kSmallAvatarSize : kStandardAvatarSize;
232240
}
233241

242+
- (void)setForceDarkAppearance:(BOOL)forceDarkAppearance
243+
{
244+
if (_forceDarkAppearance != forceDarkAppearance) {
245+
_forceDarkAppearance = forceDarkAppearance;
246+
[self configureFontsAndColors];
247+
}
248+
}
249+
234250
- (void)updateNameLabels
235251
{
236252
BOOL hasCustomName = self.customName.length > 0;
@@ -250,6 +266,7 @@ - (void)prepareForReuse
250266
{
251267
[[NSNotificationCenter defaultCenter] removeObserver:self];
252268

269+
self.forceDarkAppearance = NO;
253270
self.thread = nil;
254271
self.accessoryMessage = nil;
255272
self.nameLabel.text = nil;

SignalMessaging/Views/ContactTableViewCell.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ NS_ASSUME_NONNULL_BEGIN
1010

1111
@interface ContactTableViewCell : UITableViewCell
1212

13+
@property (assign, nonatomic) BOOL forceDarkAppearance;
14+
1315
+ (NSString *)reuseIdentifier;
1416

1517
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_UNAVAILABLE;

SignalMessaging/Views/ContactTableViewCell.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ - (void)setUseSmallAvatars
129129
self.cellView.useSmallAvatars = YES;
130130
}
131131

132+
- (BOOL)forceDarkAppearance
133+
{
134+
return self.cellView.forceDarkAppearance;
135+
}
136+
137+
- (void)setForceDarkAppearance:(BOOL)forceDarkAppearance
138+
{
139+
self.cellView.forceDarkAppearance = forceDarkAppearance;
140+
}
141+
132142
- (void)prepareForReuse
133143
{
134144
[super prepareForReuse];

SignalMessaging/Views/OWSFlatButton.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,17 @@ public class OWSFlatButton: UIView {
142142

143143
// MARK: Methods
144144

145+
@objc
146+
public func setTitleColor(_ color: UIColor) {
147+
button.setTitleColor(color, for: .normal)
148+
}
149+
145150
@objc
146151
public func setTitle(title: String, font: UIFont,
147152
titleColor: UIColor ) {
148153
button.setTitle(title, for: .normal)
149-
button.setTitleColor(titleColor, for: .normal)
150154
button.titleLabel!.font = font
155+
setTitleColor(titleColor)
151156
}
152157

153158
@objc

SignalMessaging/appearance/Theme+OWS.swift

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ extension Theme {
340340
public var hairlineColor: UIColor {
341341
switch self {
342342
case .default: return isDarkThemeEnabled ? .ows_gray65 : .ows_gray05
343-
case .translucentDark: return .ows_gray65
343+
case .translucentDark: return .ows_whiteAlpha20
344344
}
345345
}
346346

@@ -365,6 +365,20 @@ extension Theme {
365365
}
366366
}
367367

368+
public var safetyNumberChangeButtonBackgroundColor: UIColor {
369+
switch self {
370+
case .default: return Theme.conversationButtonBackgroundColor
371+
case .translucentDark: return .ows_gray75
372+
}
373+
}
374+
375+
public var safetyNumberChangeButtonTextColor: UIColor {
376+
switch self {
377+
case .default: return Theme.conversationButtonTextColor
378+
case .translucentDark: return .ows_accentBlueDark
379+
}
380+
}
381+
368382
public var destructiveButtonTextColor: UIColor {
369383
return .ows_accentRed
370384
}
@@ -383,15 +397,15 @@ extension Theme {
383397
}
384398
}
385399

386-
public func createBackdropView() -> UIView {
400+
public func createBackgroundView() -> UIView {
387401
switch self {
388402
case .default:
389-
let backdrop = UIView()
390-
backdrop.backgroundColor = backgroundColor
391-
return backdrop
403+
let background = UIView()
404+
background.backgroundColor = backgroundColor
405+
return background
392406
case .translucentDark:
393-
let backdrop = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
394-
return backdrop
407+
let background = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
408+
return background
395409
}
396410
}
397411
}

SignalMessaging/categories/UIView+OWS.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,10 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value);
150150

151151
@interface UIStackView (OWS)
152152

153-
- (UIView *)addBackgroundViewWithBackgroundColor:(UIColor *)backgroundColor;
153+
- (void)addHairlineWithColor:(UIColor *)color;
154+
- (void)insertHairlineWithColor:(UIColor *)color atIndex:(NSInteger)index;
154155

156+
- (UIView *)addBackgroundViewWithBackgroundColor:(UIColor *)backgroundColor;
155157
- (UIView *)addBackgroundViewWithBackgroundColor:(UIColor *)backgroundColor cornerRadius:(CGFloat)cornerRadius;
156158

157159
- (UIView *)addBorderViewWithColor:(UIColor *)color strokeWidth:(CGFloat)strokeWidth cornerRadius:(CGFloat)cornerRadius;

SignalMessaging/categories/UIView+OWS.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,20 @@ - (BOOL)applyScrollViewInsetsFix
566566

567567
@implementation UIStackView (OWS)
568568

569+
- (void)addHairlineWithColor:(UIColor *)color
570+
{
571+
[self insertHairlineWithColor:color atIndex:self.arrangedSubviews.count];
572+
}
573+
574+
- (void)insertHairlineWithColor:(UIColor *)color atIndex:(NSInteger)index
575+
{
576+
UIView *hairlineView = [[UIView alloc] init];
577+
hairlineView.backgroundColor = color;
578+
[hairlineView autoSetDimension:ALDimensionHeight toSize:1];
579+
580+
[self insertArrangedSubview:hairlineView atIndex:index];
581+
}
582+
569583
- (UIView *)addBackgroundViewWithBackgroundColor:(UIColor *)backgroundColor
570584
{
571585
return [self addBackgroundViewWithBackgroundColor:backgroundColor cornerRadius:0.f];

0 commit comments

Comments
 (0)