Skip to content

Commit

Permalink
Merge pull request #277 from wordpress-mobile/release/1.12.0
Browse files Browse the repository at this point in the history
Release/1.12.0
  • Loading branch information
loremattei authored Sep 7, 2020
2 parents 93e7c66 + a357b0a commit 8a53966
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 5 deletions.
2 changes: 1 addition & 1 deletion WordPressShared.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "WordPressShared"
s.version = "1.10.0-beta.2"
s.version = "1.12.0"
s.summary = "Shared components used in building the WordPress iOS apps and other library components."

s.description = <<-DESC
Expand Down
8 changes: 6 additions & 2 deletions WordPressShared.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
B5A7881F202B3A92007874FB /* WPTextFieldTableViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = B5A7881B202B3A92007874FB /* WPTextFieldTableViewCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
B5A78820202B3A92007874FB /* WPTextFieldTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = B5A7881C202B3A92007874FB /* WPTextFieldTableViewCell.m */; };
B5A78821202B3A92007874FB /* WPTableViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = B5A7881D202B3A92007874FB /* WPTableViewCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
CE1CB30424DCAFCB00DBAD9C /* CollectionType+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE1CB30324DCAFCB00DBAD9C /* CollectionType+Helpers.swift */; };
E157E126239527700051AE41 /* Secret.swift in Sources */ = {isa = PBXBuildFile; fileRef = E157E125239527700051AE41 /* Secret.swift */; };
E157E128239527AD0051AE41 /* SecretTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E157E127239527AD0051AE41 /* SecretTests.swift */; };
E18EABEA1F0E2C6800BFCB0B /* TestAnalyticsTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = E18EABE81F0E2C6800BFCB0B /* TestAnalyticsTracker.m */; };
Expand Down Expand Up @@ -202,6 +203,7 @@
B5A7881D202B3A92007874FB /* WPTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WPTableViewCell.h; sourceTree = "<group>"; };
B5A78823202B3B3C007874FB /* WordPressUIKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = WordPressUIKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
BAD47F9FCABF8C12D6352A20 /* Pods-WordPressSharedTests.release-internal.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WordPressSharedTests.release-internal.xcconfig"; path = "Pods/Target Support Files/Pods-WordPressSharedTests/Pods-WordPressSharedTests.release-internal.xcconfig"; sourceTree = "<group>"; };
CE1CB30324DCAFCB00DBAD9C /* CollectionType+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CollectionType+Helpers.swift"; sourceTree = "<group>"; };
D62D565031D4683172615BAC /* Pods-WordPressSharedTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WordPressSharedTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-WordPressSharedTests/Pods-WordPressSharedTests.release.xcconfig"; sourceTree = "<group>"; };
E157E125239527700051AE41 /* Secret.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Secret.swift; sourceTree = "<group>"; };
E157E127239527AD0051AE41 /* SecretTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecretTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -297,6 +299,7 @@
82706FE01ECA32D400155CBF /* Utility */ = {
isa = PBXGroup;
children = (
CE1CB30324DCAFCB00DBAD9C /* CollectionType+Helpers.swift */,
74FA25F21F1FD9640044BC54 /* DateUtils.h */,
74FA25F31F1FD9640044BC54 /* DateUtils.m */,
F1134A262270C15E00B8F75F /* Debouncer.swift */,
Expand Down Expand Up @@ -571,11 +574,11 @@
};
buildConfigurationList = 829DD1381EC9EED200AB8C12 /* Build configuration list for PBXProject "WordPressShared" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
mainGroup = 829DD1341EC9EED200AB8C12;
productRefGroup = 829DD13F1EC9EED200AB8C12 /* Products */;
Expand Down Expand Up @@ -712,6 +715,7 @@
F193585624CA3F4E00942507 /* AnalyticsEvent.swift in Sources */,
F1134A272270C15E00B8F75F /* Debouncer.swift in Sources */,
B5393FD8206D608F007BF9D4 /* EmailFormatValidator.swift in Sources */,
CE1CB30424DCAFCB00DBAD9C /* CollectionType+Helpers.swift in Sources */,
F106FA62226FA82E00706DE4 /* String+URLValidation.swift in Sources */,
F10A569023E1FC1300B184F4 /* String+StripShortcodes.swift in Sources */,
32E1BFD524A63DE6007A08F0 /* WPStyleGuide+SerifFonts.swift in Sources */,
Expand Down
21 changes: 21 additions & 0 deletions WordPressShared/Core/Utility/CollectionType+Helpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Foundation


// MARK: - Collection Type Helpers
//
extension BidirectionalCollection {
public func lastIndex(where predicate: (Self.Iterator.Element) throws -> Bool) rethrows -> Self.Index? {
if let idx = try reversed().firstIndex(where: predicate) {
return self.index(before: idx.base)
}
return nil
}
}

extension Collection {
/// Returns the element at the specified index if it is within bounds, otherwise nil.
///
public subscript (safe index: Index) -> Element? {
return indices.contains(index) ? self[index] : nil
}
}
45 changes: 44 additions & 1 deletion WordPressShared/Core/Views/WPStyleGuide+DynamicType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@ extension WPStyleGuide {
return UIFont(descriptor: descriptorWithTraits, size: size)
}

/// Creates a NotoSerif UIFont at the specified size.
///
/// - Parameters:
/// - size: The desired size.
///
/// - Returns: The created font.
///
@objc public class func fixedNotoFontWithSize(_ size: CGFloat) -> UIFont {
return fixedCustomNotoFontNamed("NotoSerif", withSize: size)
}

/// Creates a bold NotoSerif UIFont at the specified size.
///
/// - Parameters:
/// - size: The desired size.
///
/// - Returns: The created font.
///
@objc public class func fixedBoldNotoFontWithSize(_ size: CGFloat) -> UIFont {
return fixedCustomNotoFontNamed("NotoSerif-Bold", withSize: size)
}

/// Creates a NotoSerif UIFont for the user current text size settings.
///
/// - Parameters:
Expand Down Expand Up @@ -239,7 +261,7 @@ extension WPStyleGuide {
/// - fontName: the Noto font name (NotoSerif, NotoSerif-Bold, NotoSerif-Italic, NotoSerif-BoldItalic)
/// - style: The desired UIFontTextStyle.
///
/// - Returns: The created font point size.
/// - Returns: The created font.
///
private class func customNotoFontNamed(_ fontName: String, forTextStyle style: UIFont.TextStyle, maximumPointSize: CGFloat = maxFontSize) -> UIFont {
WPFontManager.loadNotoFontFamily()
Expand All @@ -251,4 +273,25 @@ extension WPStyleGuide {
}
return font
}

/// Creates a Noto UIFont at the specified size.
///
/// - Parameters:
/// - fontName: the Noto font name (NotoSerif, NotoSerif-Bold, NotoSerif-Italic, NotoSerif-BoldItalic)
/// - size: The desired point size.
///
/// - Returns: The created font.
///
private class func fixedCustomNotoFontNamed(_ fontName: String, withSize size: CGFloat) -> UIFont {
WPFontManager.loadNotoFontFamily()
guard let font = UIFont(name: fontName, size: size) else {
// If we can't get the Noto font for some reason we will default to the system font
if fontName.contains("Bold") {
return UIFont.systemFont(ofSize: size, weight: .bold)
} else {
return UIFont.systemFont(ofSize: size)
}
}
return font
}
}
22 changes: 21 additions & 1 deletion WordPressShared/Core/Views/WPStyleGuide+SerifFonts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,27 @@ extension WPStyleGuide {
return UIFontMetrics.default.scaledFont(for: UIFont(descriptor: fontDescriptor, size: 0.0))
}


// Returns the system serif font (New York) for iOS 13+ but defaults to noto for older os's, at the default size for the specified style
@objc public class func fixedSerifFontForTextStyle(_ style: UIFont.TextStyle,
fontWeight weight: UIFont.Weight = .regular) -> UIFont {

let defaultContentSizeCategory = UITraitCollection(preferredContentSizeCategory: .large) // .large is the default
let fontSize = UIFontDescriptor.preferredFontDescriptor(withTextStyle: style, compatibleWith: defaultContentSizeCategory).pointSize

guard #available(iOS 13, *),
let fontDescriptor = UIFont.systemFont(ofSize: fontSize, weight: weight).fontDescriptor.withDesign(.serif) else {
switch weight {
case .bold, .semibold, .heavy, .black:
return WPStyleGuide.fixedBoldNotoFontWithSize(fontSize)
default:
return WPStyleGuide.fixedNotoFontWithSize(fontSize)
}
}

// Uses size from original font, so we don't want to override it here.
return UIFont(descriptor: fontDescriptor, size: 0.0)
}

private class func notoFontForTextStyle(_ style: UIFont.TextStyle,
fontWeight weight: UIFont.Weight = .regular) -> UIFont {
var font: UIFont
Expand Down

0 comments on commit 8a53966

Please sign in to comment.