-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Foundation | ||
|
||
/// This struct represents an analytics event. | ||
/// Declaring this class as final is a design choice to promote a simpler usage and implement events | ||
/// through parametrization of the `name` and `properties` properties. | ||
/// | ||
/// An example of a static event definition (in the client App or Pod): | ||
/// | ||
/// ~~~ | ||
/// extension AnalyticsEvent { | ||
/// static let loginStart = AnalyticsEvent(name: "login", properties: ["step": "start"]) | ||
/// } | ||
/// ~~~ | ||
/// | ||
/// An example of a dynamic / parametrized event definition (in the client App or Pod): | ||
/// | ||
/// ~~~ | ||
/// extension AnalyticsEvent { | ||
/// enum LoginStep: String { | ||
/// case start | ||
/// case success | ||
/// } | ||
/// | ||
/// static func login(step: LoginStep) -> AnalyticsEvent { | ||
/// let properties = [ | ||
/// "step": step.rawValue | ||
/// ] | ||
/// | ||
/// return AnalyticsEvent(name: "login", properties: properties) | ||
/// } | ||
/// } | ||
/// ~~~ | ||
/// | ||
/// Examples of tracking calls (in the client App or Pod): | ||
/// | ||
/// ~~~ | ||
/// WPAnalytics.track(.login(step: .start)) | ||
/// WPAnalytics.track(.loginStart) | ||
/// ~~~ | ||
/// | ||
public final class AnalyticsEvent { | ||
public let name: String | ||
public let properties: [String: String] | ||
|
||
public init(name: String, properties: [String: String]) { | ||
self.name = name | ||
self.properties = properties | ||
} | ||
} | ||
|
||
extension WPAnalytics { | ||
public static func track(_ event: AnalyticsEvent) { | ||
WPAnalytics.trackString(event.name, withProperties: event.properties) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Foundation | ||
|
||
/// WPStyleGuide Extension to use serif fonts. | ||
/// | ||
extension WPStyleGuide { | ||
/// Returns the system serif font (New York) for iOS 13+ but defaults to noto for older os's | ||
@objc public class func serifFontForTextStyle(_ style: UIFont.TextStyle, | ||
fontWeight weight: UIFont.Weight = .regular) -> UIFont { | ||
guard #available(iOS 13, *), | ||
let fontDescriptor = WPStyleGuide.fontForTextStyle(style, fontWeight: weight).fontDescriptor.withDesign(.serif) | ||
else { | ||
return WPStyleGuide.notoFontForTextStyle(style, fontWeight: weight) | ||
} | ||
|
||
return UIFontMetrics.default.scaledFont(for: UIFont(descriptor: fontDescriptor, size: 0.0)) | ||
} | ||
|
||
|
||
private class func notoFontForTextStyle(_ style: UIFont.TextStyle, | ||
fontWeight weight: UIFont.Weight = .regular) -> UIFont { | ||
var font: UIFont | ||
|
||
switch weight { | ||
// Map all the bold weights to the bold font | ||
case .bold, .semibold, .heavy, .black: | ||
font = WPStyleGuide.notoBoldFontForTextStyle(style) | ||
default: | ||
font = WPStyleGuide.notoFontForTextStyle(style) | ||
} | ||
|
||
return font | ||
} | ||
} |