Skip to content

Commit 2c616f2

Browse files
cuvafacebook-github-bot
authored andcommitted
Expose LabelComponent to Swift
Summary: Adds an initialiser with default values for `LabelComponent` in `CKTextSwift`. Reviewed By: kevin0571 Differential Revision: D23807463 fbshipit-source-id: 80207549e55bf2fd011dfa286f1f9436ca59109a
1 parent 46796e0 commit 2c616f2

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

CKSwift/ComponentSize.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import ComponentKit
1313
/// Represents a component desired size relative to the size of its parent.
1414
public struct ComponentSize: Hashable {
1515
/// The Objective-C bridgeable type.
16-
let componentSize: ComponentSizeSwiftBridge
16+
public let componentSize: ComponentSizeSwiftBridge
1717

1818
/// Creates a new component size.
1919
/// - Parameter size: The CKSize to derive the size from.

CKSwift/Dimension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import ComponentKit
1313
/// A dimension relative to constraints to be provided in the future.
1414
public struct Dimension: Hashable {
1515
/// The Objective-C bridgeable type.
16-
let dimension: DimensionSwiftBridge
16+
public let dimension: DimensionSwiftBridge
1717

1818
/// Creates a default dimension.
1919
public init() {

CKTextSwift/LabelComponent.swift

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2014-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
*/
10+
11+
import ComponentKit
12+
import CKSwift
13+
import UIKit
14+
15+
public extension LabelComponent {
16+
17+
#if swift(>=5.1)
18+
convenience init(
19+
text: String,
20+
truncationString: String? = nil,
21+
font: UIFont? = nil,
22+
color: UIColor? = nil,
23+
lineBreakMode: NSLineBreakMode = .byWordWrapping,
24+
maximumNumberOfLines: UInt = 0,
25+
shadowOffset: CGSize = .zero,
26+
shadowColor: UIColor? = nil,
27+
shadowOpacity: CGFloat = 0,
28+
shadowRadius: CGFloat = 0,
29+
alignment: NSTextAlignment = .natural,
30+
firstLineHeadIndent: CGFloat = 0,
31+
headIndent: CGFloat = 0,
32+
tailIndent: CGFloat = 0,
33+
lineHeightMultiple: CGFloat = 0,
34+
maximumLineHeight: CGFloat = 0,
35+
minimumLineHeight: CGFloat = 0,
36+
lineSpacing: CGFloat = 0,
37+
paragraphSpacing: CGFloat = 0,
38+
paragraphSpacingBefore: CGFloat = 0,
39+
size: ComponentSize? = nil,
40+
@ViewConfigurationAttributeBuilder<UIView> attributes: () -> [ComponentViewAttributeSwiftBridge] = {[]}) {
41+
self.init(__text: text,
42+
truncationString: truncationString,
43+
font: font,
44+
color: color,
45+
lineBreakMode: lineBreakMode,
46+
maximumNumberOfLines: maximumNumberOfLines,
47+
shadowOffset: shadowOffset,
48+
shadowColor: shadowColor,
49+
shadowOpacity: shadowOpacity,
50+
shadowRadius: shadowRadius,
51+
alignment: alignment,
52+
firstLineHeadIndent: firstLineHeadIndent,
53+
headIndent: headIndent,
54+
tailIndent: tailIndent,
55+
lineHeightMultiple: lineHeightMultiple,
56+
maximumLineHeight: maximumLineHeight,
57+
minimumLineHeight: minimumLineHeight,
58+
lineSpacing: lineSpacing,
59+
paragraphSpacing: paragraphSpacing,
60+
paragraphSpacingBefore: paragraphSpacingBefore,
61+
swiftSize: size?.componentSize,
62+
swiftAttributes: attributes())
63+
}
64+
#endif
65+
}

ComponentKit.xcodeproj/project.pbxproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@
726726
D427E81A2314A888004F22BD /* CKStatelessComponentContext.h in Headers */ = {isa = PBXBuildFile; fileRef = D427E8182314A888004F22BD /* CKStatelessComponentContext.h */; settings = {ATTRIBUTES = (Public, ); }; };
727727
D427E81B2314A890004F22BD /* CKStatelessComponentContext.h in Headers */ = {isa = PBXBuildFile; fileRef = D427E8182314A888004F22BD /* CKStatelessComponentContext.h */; settings = {ATTRIBUTES = (Public, ); }; };
728728
D427E81C2314A893004F22BD /* CKStatelessComponentContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = D427E8172314A887004F22BD /* CKStatelessComponentContext.mm */; };
729+
D42B76292516858200DAC4D5 /* LabelComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = D42B76282516858200DAC4D5 /* LabelComponent.swift */; };
729730
D42B77322517675100DAC4D5 /* CKLabelComponent.mm in Sources */ = {isa = PBXBuildFile; fileRef = D0B47C411CBD92C200BB33CE /* CKLabelComponent.mm */; };
730731
D42B773F2517675100DAC4D5 /* CKTextComponentLayerHighlighter.mm in Sources */ = {isa = PBXBuildFile; fileRef = D0B47C471CBD92C200BB33CE /* CKTextComponentLayerHighlighter.mm */; };
731732
D42B77412517675100DAC4D5 /* CKTextComponentView.mm in Sources */ = {isa = PBXBuildFile; fileRef = D0B47C491CBD92C200BB33CE /* CKTextComponentView.mm */; };
@@ -920,6 +921,7 @@
920921
D461755925177E00004FC1A4 /* ComponentTextKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D42B787A2517675100DAC4D5 /* ComponentTextKit.framework */; };
921922
D46328BB2415486600E5B7DA /* CKLinkable.h in Headers */ = {isa = PBXBuildFile; fileRef = D46328BA2415486600E5B7DA /* CKLinkable.h */; settings = {ATTRIBUTES = (Public, ); }; };
922923
D46328BC2415486600E5B7DA /* CKLinkable.h in Headers */ = {isa = PBXBuildFile; fileRef = D46328BA2415486600E5B7DA /* CKLinkable.h */; settings = {ATTRIBUTES = (Public, ); }; };
924+
D486BB6E2517A04A00D167E7 /* LabelComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = D486BAB8251796B100D167E7 /* LabelComponent.swift */; };
923925
D48D24E324B88B6600E3BFC4 /* CKWritingDirection.h in Headers */ = {isa = PBXBuildFile; fileRef = D48D24D724B88B6500E3BFC4 /* CKWritingDirection.h */; settings = {ATTRIBUTES = (Public, ); }; };
924926
D48D24E424B88B6600E3BFC4 /* CKWritingDirection.h in Headers */ = {isa = PBXBuildFile; fileRef = D48D24D724B88B6500E3BFC4 /* CKWritingDirection.h */; settings = {ATTRIBUTES = (Public, ); }; };
925927
D48D24E524B88B6600E3BFC4 /* CKWritingDirection.mm in Sources */ = {isa = PBXBuildFile; fileRef = D48D24E224B88B6600E3BFC4 /* CKWritingDirection.mm */; };
@@ -1971,6 +1973,7 @@
19711973
D44B215024B73DFE0019E851 /* CKIdValueWrapperInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CKIdValueWrapperInternal.h; sourceTree = "<group>"; };
19721974
D4548D49251772C30038B9A4 /* ComponentTextKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ComponentTextKit.h; sourceTree = "<group>"; };
19731975
D46328BA2415486600E5B7DA /* CKLinkable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CKLinkable.h; sourceTree = "<group>"; };
1976+
D486BAB8251796B100D167E7 /* LabelComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LabelComponent.swift; sourceTree = "<group>"; };
19741977
D48D24D724B88B6500E3BFC4 /* CKWritingDirection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CKWritingDirection.h; sourceTree = "<group>"; };
19751978
D48D24E224B88B6600E3BFC4 /* CKWritingDirection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CKWritingDirection.mm; sourceTree = "<group>"; };
19761979
D48D9D3A23424C75003DDC41 /* CKAnimationComponent+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CKAnimationComponent+Internal.h"; sourceTree = "<group>"; };
@@ -3285,6 +3288,7 @@
32853288
isa = PBXGroup;
32863289
children = (
32873290
D42B78D425176C9400DAC4D5 /* CKTextSwift.swift */,
3291+
D486BAB8251796B100D167E7 /* LabelComponent.swift */,
32883292
D42B78D525176C9400DAC4D5 /* CKTextSwift.h */,
32893293
D42B78D625176C9400DAC4D5 /* CKTextSwift.xcconfig */,
32903294
D42B78D825176C9400DAC4D5 /* Info.plist */,
@@ -5156,6 +5160,7 @@
51565160
isa = PBXSourcesBuildPhase;
51575161
buildActionMask = 2147483647;
51585162
files = (
5163+
D486BB6E2517A04A00D167E7 /* LabelComponent.swift in Sources */,
51595164
D42B78D925176C9400DAC4D5 /* CKTextSwift.swift in Sources */,
51605165
);
51615166
runOnlyForDeploymentPostprocessing = 0;

0 commit comments

Comments
 (0)