Skip to content

Commit

Permalink
Revert Text Localization Support
Browse files Browse the repository at this point in the history
  • Loading branch information
lkzhao committed Jan 26, 2023
1 parent aa6c29b commit 7e1d6ad
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Examples/UIComponentExample/Examples/BadgeExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct NumberBadge: ComponentBuilder {
let isRoundStyle: Bool
func build() -> Component {
Text(
verbatim: text,
text,
font: .systemFont(ofSize: 12)
)
.size(
Expand Down Expand Up @@ -83,7 +83,7 @@ struct NumberBadge: ComponentBuilder {
struct BannerBadge: ComponentBuilder {
let text: String
func build() -> Component {
Text(verbatim: text, font: .systemFont(ofSize: 11)).textAlignment(.center).textColor(.white).backgroundColor(.systemRed).adjustsFontSizeToFitWidth(true).size(height: .absolute(15))
Text(text, font: .systemFont(ofSize: 11)).textAlignment(.center).textColor(.white).backgroundColor(.systemRed).adjustsFontSizeToFitWidth(true).size(height: .absolute(15))
.inset(h: 2)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class CardViewController2: ComponentViewController {
for (index, card) in cards.enumerated() {
let title = card.title
VStack(spacing: 8) {
Text(verbatim: title, font: UIFont.boldSystemFont(ofSize: 22))
Text(verbatim: card.subtitle)
Text(title, font: UIFont.boldSystemFont(ofSize: 22))
Text(card.subtitle)
}
.inset(h: 20, v: 16).size(width: .fill)
.tappableView { [unowned self] in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ private struct Card: ComponentBuilder {
let onTap: () -> Void
func build() -> Component {
VStack(spacing: 8) {
Text(verbatim: card.title, font: UIFont.boldSystemFont(ofSize: 22))
Text(verbatim: card.subtitle)
Text(card.title, font: UIFont.boldSystemFont(ofSize: 22))
Text(card.subtitle)
}
.inset(h: 20, v: 16).size(width: .fill).tappableView(onTap).id(card.id)
.backgroundColor(.systemBackground)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ComplexLayoutViewController: ComponentViewController {
Text("Empty Tag")
} else {
for (index, tag) in tags.enumerated() {
Text(verbatim: tag.name, font: .systemFont(ofSize: 14, weight: .regular)).textColor(.label).inset(h: 10, v: 5).styleColor(tag.color)
Text(tag.name, font: .systemFont(ofSize: 14, weight: .regular)).textColor(.label).inset(h: 10, v: 5).styleColor(tag.color)
.tappableView { [unowned self] in
self.tags.remove(at: index)
}
Expand All @@ -120,7 +120,7 @@ class ComplexLayoutViewController: ComponentViewController {
Text("Empty Tag")
} else {
for (index, tag) in tags.enumerated() {
Text(verbatim: tag.name, font: .systemFont(ofSize: 14, weight: .regular)).textColor(.label).inset(h: 10, v: 5).styleColor(tag.color)
Text(tag.name, font: .systemFont(ofSize: 14, weight: .regular)).textColor(.label).inset(h: 10, v: 5).styleColor(tag.color)
.tappableView { [unowned self] in
self.tags.remove(at: index)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct IntroductionCard: ComponentBuilder {
VStack(spacing: 5, alignItems: .center) {
AsyncImage(URL(string: "https://unsplash.com/photos/MR2A97jFDAs/download?force=true&w=640")!).size(width: 50, height: 50).update { $0.layer.cornerRadius = 50 / 2 }
.clipsToBounds(true)
Text(verbatim: "isExpand: \(isExpanded)", font: .systemFont(ofSize: 10, weight: .light)).textAlignment(.center).id("label.state").size(width: .fill)
Text("isExpand: \(isExpanded)", font: .systemFont(ofSize: 10, weight: .light)).textAlignment(.center).id("label.state").size(width: .fill)
Spacer()
Image(systemName: isExpanded ? "rectangle.compress.vertical" : "rectangle.expand.vertical")
.tappableView {
Expand All @@ -40,7 +40,7 @@ struct IntroductionCard: ComponentBuilder {
VStack(spacing: 5) {
Text("UIComponent", font: .boldSystemFont(ofSize: 17))
Text("Powerful layout", font: .systemFont(ofSize: 14)).textColor(.link)
Text(verbatim: longText, font: .systemFont(ofSize: 13), numberOfLines: isExpanded ? 0 : 3).textColor(.secondaryLabel)
Text(longText, font: .systemFont(ofSize: 13), numberOfLines: isExpanded ? 0 : 3).textColor(.secondaryLabel)
}
.flex()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ struct UserProfile: ComponentBuilder {
.shadowAvatar()

VStack(spacing: 4) {
Text(verbatim: userName)
Text(verbatim: introduce, font: .systemFont(ofSize: 13, weight: .light)).textColor(.secondaryLabel)
Text(userName)
Text(introduce, font: .systemFont(ofSize: 13, weight: .light)).textColor(.secondaryLabel)
Text("🤔🤔🤔", font: .systemFont(ofSize: 12, weight: .light)).textColor(.secondaryLabel)
}
.flex()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class FlexLayoutViewController: ComponentViewController {
VStack(spacing: 10) {
Text("Justify Content", font: .boldSystemFont(ofSize: 20)).size(width: .fill)
for justifyContent in MainAxisAlignment.allCases {
Text(verbatim: "\(justifyContent)").size(width: .fill)
Text("\(justifyContent)").size(width: .fill)
Flow(justifyContent: justifyContent) {
for index in 0..<10 {
Box(index)
Expand All @@ -81,7 +81,7 @@ class FlexLayoutViewController: ComponentViewController {
VStack(spacing: 10) {
Text("Align Items", font: .boldSystemFont(ofSize: 20)).size(width: .fill)
for alignItems in CrossAxisAlignment.allCases {
Text(verbatim: "\(alignItems)").size(width: .fill)
Text("\(alignItems)").size(width: .fill)
Flow(alignItems: alignItems) {
for index in 0..<10 {
Box(index, height: 50 + CGFloat(index % 4) * 10)
Expand All @@ -94,7 +94,7 @@ class FlexLayoutViewController: ComponentViewController {
VStack(spacing: 10) {
Text("Align Content", font: .boldSystemFont(ofSize: 20)).size(width: .fill)
for alignContent in MainAxisAlignment.allCases {
Text(verbatim: "\(alignContent)").size(width: .fill)
Text("\(alignContent)").size(width: .fill)
Flow(alignContent: alignContent) {
for index in 0..<10 {
Box(index, height: 50)
Expand Down Expand Up @@ -144,7 +144,7 @@ class FlexLayoutViewController: ComponentViewController {
Text("Flex align-self", font: .boldSystemFont(ofSize: 20))

for align in CrossAxisAlignment.allCases {
Text(verbatim: "number 1 align-self \(align)").size(width: .fill)
Text("number 1 align-self \(align)").size(width: .fill)
Flow {
Box(1).flex(alignSelf: align)
Box(2, height: 60)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class GalleryViewController: ComponentViewController {

for layout in GalleryFrames.LayoutType.allCases {
VStack(spacing: 10) {
Text(verbatim: "\(layout)")
Text("\(layout)")
let template = GalleryFrames(layout: layout)
VerticalGallery(spacing: 5, template: [template]) {
for index in 0..<template.calculateFrames(spacing: 0, side: 0, makeFrame: { _, _ in .zero }).count {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ComponentViewController: UIViewController {

var component: Component {
VStack(justifyContent: .center, alignItems: .center) {
Text(verbatim: "Empty")
Text("Empty")
}
.size(width: .fill)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ class Box: ComponentBuilder {
self.init("", width: width, height: height)
}
func build() -> Component {
Space(width: width, height: height).styleColor(.systemBlue).overlay(Text(verbatim: text).textColor(.white).textAlignment(.center).size(width: .fill, height: .fill))
Space(width: width, height: height).styleColor(.systemBlue).overlay(Text(text).textColor(.white).textAlignment(.center).size(width: .fill, height: .fill))
}
}
2 changes: 1 addition & 1 deletion Examples/UIComponentExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct ExampleItem: ComponentBuilder {
}
func build() -> Component {
VStack {
Text(verbatim: name)
Text(name)
}
.inset(20)
.tappableView {
Expand Down
2 changes: 1 addition & 1 deletion Sources/UIComponent/Components/Layout/Other/Pager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension Pager {
guard !isUnbounded else {
let error = "Pager cannot be wrapped under an unlimited constraint component on its main axis. e.g. under a HStack or VStack"
assertionFailure(error)
return Text(verbatim: error).textColor(.red).layout(constraint)
return Text(error).textColor(.red).layout(constraint)
}
let pageMain = main(constraint.maxSize)
let childConstraint = Constraint(minSize: size(main: pageMain, cross: cross(constraint.minSize)),
Expand Down
17 changes: 2 additions & 15 deletions Sources/UIComponent/Components/View/Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ public struct Text: ViewComponent {
public let lineBreakMode: NSLineBreakMode
public let isSwiftAttributedString: Bool

@available(iOS 15, *)
public init(
_ localized: String.LocalizationValue,
_ text: String,
font: UIFont = UIFont.systemFont(ofSize: UIFont.systemFontSize),
numberOfLines: Int = 0,
lineBreakMode: NSLineBreakMode = .byWordWrapping
) {
self.attributedString = NSAttributedString(string: String(localized: localized), attributes: [.font: font])
self.attributedString = NSAttributedString(string: text, attributes: [.font: font])
self.numberOfLines = numberOfLines
self.lineBreakMode = lineBreakMode
self.isSwiftAttributedString = false
Expand All @@ -33,18 +32,6 @@ public struct Text: ViewComponent {
self.isSwiftAttributedString = true
}

public init(
verbatim text: String,
font: UIFont = UIFont.systemFont(ofSize: UIFont.systemFontSize),
numberOfLines: Int = 0,
lineBreakMode: NSLineBreakMode = .byWordWrapping
) {
self.attributedString = NSAttributedString(string: text, attributes: [.font: font])
self.numberOfLines = numberOfLines
self.lineBreakMode = lineBreakMode
self.isSwiftAttributedString = false
}

public init(
attributedString: NSAttributedString,
numberOfLines: Int = 0,
Expand Down

0 comments on commit 7e1d6ad

Please sign in to comment.