From 7e1d6ad7f4f69e8dc60b62147e42937c8790dbe9 Mon Sep 17 00:00:00 2001 From: Luke Zhao Date: Wed, 25 Jan 2023 16:49:23 -0800 Subject: [PATCH] Revert Text Localization Support --- .../Examples/BadgeExample.swift | 4 ++-- .../Examples/Card/CardViewController2.swift | 4 ++-- .../Examples/Card/CardViewController3.swift | 4 ++-- .../ComplexLayoutViewController.swift | 4 ++-- .../Components/IntroductionCard.swift | 4 ++-- .../Complex layout/Components/UserProfile.swift | 4 ++-- .../Flex Layout/FlexLayoutViewController.swift | 8 ++++---- .../Gallery Example/GalleryViewController.swift | 2 +- .../ComponentViewController.swift | 2 +- .../Supporting Files/Components.swift | 2 +- .../UIComponentExample/ViewController.swift | 2 +- .../Components/Layout/Other/Pager.swift | 2 +- Sources/UIComponent/Components/View/Text.swift | 17 ++--------------- 13 files changed, 23 insertions(+), 36 deletions(-) diff --git a/Examples/UIComponentExample/Examples/BadgeExample.swift b/Examples/UIComponentExample/Examples/BadgeExample.swift index 53cc3941..2bde18b2 100644 --- a/Examples/UIComponentExample/Examples/BadgeExample.swift +++ b/Examples/UIComponentExample/Examples/BadgeExample.swift @@ -41,7 +41,7 @@ struct NumberBadge: ComponentBuilder { let isRoundStyle: Bool func build() -> Component { Text( - verbatim: text, + text, font: .systemFont(ofSize: 12) ) .size( @@ -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) } diff --git a/Examples/UIComponentExample/Examples/Card/CardViewController2.swift b/Examples/UIComponentExample/Examples/Card/CardViewController2.swift index 83f114d8..87fc0058 100644 --- a/Examples/UIComponentExample/Examples/Card/CardViewController2.swift +++ b/Examples/UIComponentExample/Examples/Card/CardViewController2.swift @@ -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 diff --git a/Examples/UIComponentExample/Examples/Card/CardViewController3.swift b/Examples/UIComponentExample/Examples/Card/CardViewController3.swift index 12348035..737f773a 100644 --- a/Examples/UIComponentExample/Examples/Card/CardViewController3.swift +++ b/Examples/UIComponentExample/Examples/Card/CardViewController3.swift @@ -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) diff --git a/Examples/UIComponentExample/Examples/Complex layout/ComplexLayoutViewController.swift b/Examples/UIComponentExample/Examples/Complex layout/ComplexLayoutViewController.swift index ad3e37aa..2665fbbc 100644 --- a/Examples/UIComponentExample/Examples/Complex layout/ComplexLayoutViewController.swift +++ b/Examples/UIComponentExample/Examples/Complex layout/ComplexLayoutViewController.swift @@ -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) } @@ -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) } diff --git a/Examples/UIComponentExample/Examples/Complex layout/Components/IntroductionCard.swift b/Examples/UIComponentExample/Examples/Complex layout/Components/IntroductionCard.swift index 3541b0a8..092cf855 100644 --- a/Examples/UIComponentExample/Examples/Complex layout/Components/IntroductionCard.swift +++ b/Examples/UIComponentExample/Examples/Complex layout/Components/IntroductionCard.swift @@ -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 { @@ -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() } diff --git a/Examples/UIComponentExample/Examples/Complex layout/Components/UserProfile.swift b/Examples/UIComponentExample/Examples/Complex layout/Components/UserProfile.swift index cc88a102..5c349466 100644 --- a/Examples/UIComponentExample/Examples/Complex layout/Components/UserProfile.swift +++ b/Examples/UIComponentExample/Examples/Complex layout/Components/UserProfile.swift @@ -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() diff --git a/Examples/UIComponentExample/Examples/Flex Layout/FlexLayoutViewController.swift b/Examples/UIComponentExample/Examples/Flex Layout/FlexLayoutViewController.swift index 6c8070ed..96bc3327 100644 --- a/Examples/UIComponentExample/Examples/Flex Layout/FlexLayoutViewController.swift +++ b/Examples/UIComponentExample/Examples/Flex Layout/FlexLayoutViewController.swift @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/Examples/UIComponentExample/Examples/Gallery Example/GalleryViewController.swift b/Examples/UIComponentExample/Examples/Gallery Example/GalleryViewController.swift index 502aab55..8857e808 100644 --- a/Examples/UIComponentExample/Examples/Gallery Example/GalleryViewController.swift +++ b/Examples/UIComponentExample/Examples/Gallery Example/GalleryViewController.swift @@ -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.. 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)) } } diff --git a/Examples/UIComponentExample/ViewController.swift b/Examples/UIComponentExample/ViewController.swift index e176a46d..c8bb7f99 100644 --- a/Examples/UIComponentExample/ViewController.swift +++ b/Examples/UIComponentExample/ViewController.swift @@ -33,7 +33,7 @@ struct ExampleItem: ComponentBuilder { } func build() -> Component { VStack { - Text(verbatim: name) + Text(name) } .inset(20) .tappableView { diff --git a/Sources/UIComponent/Components/Layout/Other/Pager.swift b/Sources/UIComponent/Components/Layout/Other/Pager.swift index 232760f6..102b7cfd 100644 --- a/Sources/UIComponent/Components/Layout/Other/Pager.swift +++ b/Sources/UIComponent/Components/Layout/Other/Pager.swift @@ -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)), diff --git a/Sources/UIComponent/Components/View/Text.swift b/Sources/UIComponent/Components/View/Text.swift index 7eac5919..917ce408 100644 --- a/Sources/UIComponent/Components/View/Text.swift +++ b/Sources/UIComponent/Components/View/Text.swift @@ -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 @@ -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,