-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Jetpack badge to Activity log detail #19007
Changes from 23 commits
c0be422
3847614
9e654b7
4af379f
e715af8
c423fc0
3f1c302
13f6a38
2066afd
2ae5be1
a6a0925
def3f4c
fafcfd9
308278a
667aca5
38b9298
69717d1
bd1132f
3b5fd91
59e3296
3700b6e
afa605c
cdfff49
7bc522d
725dfec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import UIKit | ||
|
||
class JetpackBannerView: UIView { | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
setup() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Micro, optional nit: Extra spacing. |
||
} | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
super.init(coder: aDecoder) | ||
setup() | ||
} | ||
|
||
override var intrinsicContentSize: CGSize { | ||
return isHidden ? CGSize.zero : super.intrinsicContentSize | ||
} | ||
|
||
func setup() { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Micro, optional nit: Extra spacing. |
||
backgroundColor = Self.jetpackBannerBackgroundColor | ||
|
||
let jetpackButton = JetpackButton(style: .banner) | ||
jetpackButton.translatesAutoresizingMaskIntoConstraints = false | ||
addSubview(jetpackButton) | ||
|
||
pinSubviewToAllEdges(jetpackButton) | ||
} | ||
|
||
private static let jetpackBannerBackgroundColor = UIColor(light: .muriel(color: .jetpackGreen, .shade0), | ||
dark: .muriel(color: .jetpackGreen, .shade90)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import UIKit | ||
import SwiftUI | ||
|
||
/// A "Jetpack powered" button with two different styles (`badge` or `banner`) | ||
class JetpackButton: UIButton { | ||
|
||
enum ButtonStyle { | ||
case badge | ||
case banner | ||
} | ||
|
||
private let style: ButtonStyle | ||
|
||
private lazy var imageBackgroundView: UIView = { | ||
let view = UIView() | ||
view.backgroundColor = imageBackgroundColor | ||
view.translatesAutoresizingMaskIntoConstraints = false | ||
return view | ||
}() | ||
|
||
init(style: ButtonStyle) { | ||
self.style = style | ||
super.init(frame: .zero) | ||
configureButton() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("Storyboard instantiation not supported.") | ||
} | ||
|
||
private var buttonBackgroundColor: UIColor { | ||
switch style { | ||
case .badge: | ||
return UIColor(light: .muriel(color: .jetpackGreen, .shade40), | ||
dark: .muriel(color: .jetpackGreen, .shade90)) | ||
case .banner: | ||
return .clear | ||
} | ||
} | ||
|
||
private var buttonTintColor: UIColor { | ||
switch style { | ||
case .badge: | ||
return UIColor(light: .white, | ||
dark: .muriel(color: .jetpackGreen, .shade40)) | ||
case .banner: | ||
return .muriel(color: .jetpackGreen, .shade40) | ||
} | ||
} | ||
|
||
private var buttonTitleColor: UIColor { | ||
switch style { | ||
case .badge: | ||
return .white | ||
case .banner: | ||
return UIColor(light: .black, dark: .white) | ||
} | ||
} | ||
|
||
private var imageBackgroundColor: UIColor { | ||
switch style { | ||
case .badge: | ||
return UIColor(light: .muriel(color: .jetpackGreen, .shade40), | ||
dark: .white) | ||
case .banner: | ||
return .white | ||
} | ||
} | ||
|
||
private func configureButton() { | ||
// TODO: Remove this when the modal presentation is added | ||
isUserInteractionEnabled = false | ||
setTitle(Appearance.title, for: .normal) | ||
tintColor = buttonTintColor | ||
backgroundColor = buttonBackgroundColor | ||
setTitleColor(buttonTitleColor, for: .normal) | ||
titleLabel?.font = Appearance.titleFont | ||
titleLabel?.adjustsFontForContentSizeCategory = true | ||
titleLabel?.minimumScaleFactor = Appearance.minimumScaleFactor | ||
titleLabel?.adjustsFontSizeToFitWidth = true | ||
setImage(.gridicon(.plans), for: .normal) | ||
contentVerticalAlignment = .fill | ||
contentHorizontalAlignment = .center | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this may be a default? |
||
contentMode = .scaleAspectFit | ||
imageEdgeInsets = Appearance.iconInsets | ||
contentEdgeInsets = Appearance.contentInsets | ||
imageView?.contentMode = .scaleAspectFit | ||
// banners are tipycally constrained in height, so we don't want the image to grow freely | ||
if style == .badge { | ||
adjustsImageSizeForAccessibilityContentSizeCategory = true | ||
} | ||
|
||
// sets the background of the jp logo to white | ||
if let imageView = imageView { | ||
insertSubview(imageBackgroundView, belowSubview: imageView) | ||
imageBackgroundView.clipsToBounds = true | ||
NSLayoutConstraint.activate([ | ||
imageBackgroundView.centerXAnchor.constraint(equalTo: imageView.centerXAnchor), | ||
imageBackgroundView.centerYAnchor.constraint(equalTo: imageView.centerYAnchor), | ||
imageBackgroundView.heightAnchor.constraint(equalTo: imageView.widthAnchor, multiplier: Appearance.imageBackgroundViewMultiplier), | ||
imageBackgroundView.widthAnchor.constraint(equalTo: imageView.widthAnchor, multiplier: Appearance.imageBackgroundViewMultiplier), | ||
]) | ||
} | ||
} | ||
|
||
private enum Appearance { | ||
static let title = NSLocalizedString("jetpack.branding.badge_banner.title", value: "Jetpack powered", | ||
comment: "Title of the Jetpack powered badge.") | ||
static let minimumScaleFactor: CGFloat = 0.6 | ||
static let iconInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 10) | ||
static let contentInsets = UIEdgeInsets(top: 6, left: 6, bottom: 6, right: 10) | ||
static let maximumFontPointSize: CGFloat = 30 | ||
static let imageBackgroundViewMultiplier: CGFloat = 0.75 | ||
static var titleFont: UIFont { | ||
let fontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .body) | ||
return UIFont(descriptor: fontDescriptor, size: min(fontDescriptor.pointSize, maximumFontPointSize)) | ||
} | ||
} | ||
|
||
override func layoutSubviews() { | ||
super.layoutSubviews() | ||
imageBackgroundView.layer.cornerRadius = imageBackgroundView.frame.height / 2 | ||
twstokes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if style == .badge { | ||
layer.cornerRadius = frame.height / 2 | ||
layer.cornerCurve = .continuous | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Micro, optional nite: Not sure if this extra space was intentional.