Skip to content

Commit 65e87cd

Browse files
cuvafacebook-github-bot
authored andcommitted
Expose CKComponent to Swift.
Summary: Swift name is now `Component`. Note that IRL it's `ComponentKit.Component` - so that leaves some space for `CKSwift.Component`. Alternatively we can keep the `CKCompoent` but I couldn't think of a reason to do so. I've currently excluded `viewContext` and `+newWithView:size:` since we've got no symbols for these yet. Reviewed By: kfirapps Differential Revision: D19744076 fbshipit-source-id: 03468eed000cb19468dc98e4d73165cd342757d9
1 parent 339dc12 commit 65e87cd

File tree

7 files changed

+35
-35
lines changed

7 files changed

+35
-35
lines changed

ComponentKit/Analytics/CKSystraceListener.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import <Foundation/Foundation.h>
1818
#import <ComponentKit/CKComponent.h>
1919
#import <ComponentKit/CKMountable.h>
20+
#import <ComponentKit/CKLayout.h>
2021

2122
@protocol CKMountable;
2223
@protocol CKRenderComponentProtocol;

ComponentKit/Core/CKComponent.h

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,13 @@
88
*
99
*/
1010

11+
#import <UIKit/UIKit.h>
1112
#import <ComponentKit/CKDefines.h>
1213

13-
#if CK_NOT_SWIFT
14-
1514
#if !defined(__cplusplus) && CK_NOT_SWIFT
1615
#error This file must be compiled Obj-C++ or imported from Swift. Objective-C files should have their extension changed to .mm.
1716
#endif
1817

19-
#import <UIKit/UIKit.h>
20-
21-
#import <ComponentKit/CKComponentLayout.h>
2218
#import <ComponentKit/CKComponentProtocol.h>
2319
#import <ComponentKit/CKComponentSize.h>
2420
#import <ComponentKit/CKComponentViewConfiguration.h>
@@ -27,8 +23,16 @@
2723
NS_ASSUME_NONNULL_BEGIN
2824

2925
/** A component is an immutable object that specifies how to configure a view, loosely inspired by React. */
26+
NS_SWIFT_NAME(Component)
3027
@interface CKComponent : NSObject <CKMountable, CKComponentProtocol>
3128

29+
- (instancetype)init CK_SWIFT_DESIGNATED_INITIALIZER;
30+
31+
#if CK_NOT_SWIFT
32+
33+
- (instancetype)initWithView:(const CKComponentViewConfiguration &)view
34+
size:(const CKComponentSize &)size;
35+
3236
/**
3337
@param view A struct describing the view for this component. Pass {} to specify that no view should be created.
3438
@param size A size constraint that should apply to this component. Pass {} to specify no size constraint.
@@ -39,16 +43,9 @@ NS_ASSUME_NONNULL_BEGIN
3943
+ (instancetype)newWithView:(const CKComponentViewConfiguration &)view
4044
size:(const CKComponentSize &)size;
4145

42-
/**
43-
While the component is mounted, returns information about the component's manifestation in the view hierarchy.
44-
45-
If this component creates a view, this method returns the view it created (or recycled) and a frame with origin 0,0
46-
and size equal to the view's bounds, since the component's size is the view's size.
46+
+ (instancetype)new;
4747

48-
If this component does not create a view, returns the view this component is mounted within and the logical frame
49-
of the component's content. In this case, you should **not** make any assumptions about what class the view is.
50-
*/
51-
- (CKComponentViewContext)viewContext;
48+
#endif
5249

5350
/**
5451
While the component is mounted, returns its next responder. This is the first of:
@@ -61,11 +58,10 @@ NS_ASSUME_NONNULL_BEGIN
6158
@end
6259

6360
#define CK_COMPONENT_INIT_UNAVAILABLE \
61+
+ (instancetype)new NS_UNAVAILABLE; \
6462
+ (instancetype)newWithView:(const CKComponentViewConfiguration &)view \
6563
size:(const CKComponentSize &)size NS_UNAVAILABLE
6664

6765
NS_ASSUME_NONNULL_END
6866

6967
#import <ComponentKit/ComponentBuilder.h>
70-
71-
#endif

ComponentKit/Core/CKComponent.mm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ + (instancetype)new
9494

9595
- (instancetype)init
9696
{
97-
CK_NOT_DESIGNATED_INITIALIZER();
97+
return [self initWithView:{} size:{}];
9898
}
9999

100100
- (instancetype)initWithView:(const CKComponentViewConfiguration &)view
@@ -148,6 +148,11 @@ - (void)setViewConfiguration:(const CKComponentViewConfiguration &)viewConfigura
148148
_viewConfiguration = viewConfiguration;
149149
}
150150

151+
- (CKComponentScopeHandle *)scopeHandle
152+
{
153+
return _scopeHandle;
154+
}
155+
151156
- (CKComponentViewContext)viewContext
152157
{
153158
CKAssertMainThread();

ComponentKit/Core/CKComponentInternal.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,14 @@
8282
/** Used to get the scope root enumerator; during component creation only */
8383
@property (nonatomic, strong, readonly) id<CKComponentScopeEnumeratorProvider> scopeEnumeratorProvider;
8484

85-
/** For internal use only; don't touch this. */
86-
@property (nonatomic, strong, readonly) CKComponentScopeHandle *scopeHandle;
87-
8885
/** For internal debug use only; don't touch this. */
89-
- (NSString *)backtraceStackDescription;
86+
@property (nonatomic, copy, readonly) NSString *backtraceStackDescription;
9087

9188
/**
9289
Update component in controller right after new generation is created.
9390
NOTE: This should only be used by ComponentKit infra.
9491
*/
95-
+ (BOOL)shouldUpdateComponentInController;
92+
@property (nonatomic, assign, readonly, class) BOOL shouldUpdateComponentInController;
9693

9794
@end
9895

ComponentKit/Core/CKComponentSubclass.h

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
*
99
*/
1010

11-
#import <ComponentKit/CKDefines.h>
12-
13-
#if CK_NOT_SWIFT
14-
1511
#import <Foundation/Foundation.h>
1612

13+
#import <ComponentKit/CKDefines.h>
1714
#import <ComponentKit/CKComponent.h>
1815
#import <ComponentKit/CKComponentAnimation.h>
1916
#import <ComponentKit/CKComponentBoundsAnimation.h>
@@ -33,6 +30,8 @@ extern CGSize const kCKComponentParentSizeUndefined;
3330

3431
@interface CKComponent ()
3532

33+
#if CK_NOT_SWIFT
34+
3635
/**
3736
Call this on children components to compute their layouts within your implementation of -computeLayoutThatFits:.
3837
@@ -78,11 +77,7 @@ extern CGSize const kCKComponentParentSizeUndefined;
7877
restrictedToSize:(const CKComponentSize &)size
7978
relativeToParentSize:(CGSize)parentSize;
8079

81-
/**
82-
Called to get the component's initial state; the default implementation returns nil.
83-
@see CKComponentScopeFrame
84-
*/
85-
+ (id _Nullable)initialState;
80+
#endif
8681

8782
/**
8883
Returns the component's state if available.
@@ -122,6 +117,8 @@ extern CGSize const kCKComponentParentSizeUndefined;
122117
*/
123118
- (BOOL)canPerformAction:(SEL _Nullable)action withSender:(id _Nullable)sender;
124119

120+
#if CK_NOT_SWIFT
121+
125122
/**
126123
Override to return a list of animations that will be applied to the component when it is first mounted.
127124
@@ -159,6 +156,8 @@ extern CGSize const kCKComponentParentSizeUndefined;
159156
*/
160157
- (std::vector<CKComponentFinalUnmountAnimation>)animationsOnFinalUnmount;
161158

159+
#endif
160+
162161
/**
163162
Attempts to return a view suitable for rendering an animation.
164163
@@ -172,13 +171,11 @@ extern CGSize const kCKComponentParentSizeUndefined;
172171
173172
This method may be overridden in rare situations where a more suitable view should be used for rendering animations.
174173
*/
175-
- (UIView * _Nullable)viewForAnimation;
174+
@property (nonatomic, strong, readonly, nullable) UIView *viewForAnimation;
176175

177176
/** Returns the component's controller, if any. */
178-
- (CKComponentController * _Nullable)controller;
177+
- (CKComponentController *_Nullable)controller;
179178

180179
@end
181180

182181
NS_ASSUME_NONNULL_END
183-
184-
#endif

RenderCore/Base/CKDefines.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#if CK_SWIFT
2222
#define CK_SWIFT_DESIGNATED_INITIALIZER NS_DESIGNATED_INITIALIZER
23+
#define CK_OBJC_UNAVAILABLE
2324
#else
2425
#define CK_SWIFT_DESIGNATED_INITIALIZER CK_NOT_DESIGNATED_INITIALIZER_ATTRIBUTE
26+
#define CK_OBJC_UNAVAILABLE NS_UNAVAILABLE
2527
#endif

RenderCore/CKMountable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,5 @@ NS_SWIFT_NAME(Mountable)
128128
#endif
129129

130130
NS_ASSUME_NONNULL_END
131+
132+
#import <RenderCore/CKLayout.h>

0 commit comments

Comments
 (0)