Skip to content

Commit

Permalink
Codemod CKAnalyticsListener to CKSystraceListener
Browse files Browse the repository at this point in the history
Summary: Pass the correct protocol to the relevant life cycle calls.

Reviewed By: cuva

Differential Revision: D13956457

fbshipit-source-id: b9ea5f170513204343fb40312a31e2a2a1c76867
  • Loading branch information
kfirapps authored and facebook-github-bot committed Feb 5, 2019
1 parent f1bcc1b commit 4ccc5a7
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
12 changes: 6 additions & 6 deletions ComponentKit/Core/CKComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ - (void)buildComponentTree:(id<CKTreeNodeWithChildrenProtocol>)parent
size:(const CGSize)size
children:(std::shared_ptr<const std::vector<CKComponentLayoutChild>>)children
supercomponent:(CKComponent *)supercomponent
analyticsListener:(id<CKAnalyticsListener>)analyticsListener
systraceListener:(id<CKSystraceListener>)systraceListener
{
CKCAssertWithCategory([NSThread isMainThread], [self class], @"This method must be called on the main thread");
if (analyticsListener) {
[analyticsListener willMountComponent:self];
}

[systraceListener willMountComponent:self];

// Taking a const ref to a temporary extends the lifetime of the temporary to the lifetime of the const ref
const CKComponentViewConfiguration &viewConfiguration = CK::Component::Accessibility::IsAccessibilityEnabled() ? CK::Component::Accessibility::AccessibleViewConfiguration(_viewConfiguration) : _viewConfiguration;

Expand Down Expand Up @@ -252,10 +252,10 @@ - (void)_relinquishMountedView
}
}

- (void)childrenDidMount:(id<CKAnalyticsListener>)analyticsListener
- (void)childrenDidMount:(id<CKSystraceListener>)systraceListener
{
[_scopeHandle.controller componentDidMount:self];
[analyticsListener didMountComponent:self];
[systraceListener didMountComponent:self];
}

#pragma mark - Animation
Expand Down
10 changes: 5 additions & 5 deletions ComponentKit/Core/CKComponentInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#import <ComponentKit/CKComponentScopeEnumeratorProvider.h>
#import <ComponentKit/CKTreeNodeProtocol.h>

@protocol CKAnalyticsListener;
@protocol CKSystraceListener;

@interface CKComponent () <CKTreeNodeComponentProtocol>

Expand All @@ -38,15 +38,15 @@
@param size The size for this component
@param children The positioned children for this component. Normally this parameter is ignored.
@param supercomponent This component's parent component
@param analyticsListener The current analytics listener - can be nil.
@param systraceListener The current systrace listener - will be nil if systrace is not enabled.
@return An updated mount context. In most cases, this is just be the passed-in context. If a view was created, this is
used to specify that subcomponents should be mounted inside the view.
*/
- (CK::Component::MountResult)mountInContext:(const CK::Component::MountContext &)context
size:(const CGSize)size
children:(std::shared_ptr<const std::vector<CKComponentLayoutChild>>)children
supercomponent:(CKComponent *)supercomponent
analyticsListener:(id<CKAnalyticsListener>)analyticsListener NS_REQUIRES_SUPER;
systraceListener:(id<CKSystraceListener>)systraceListener NS_REQUIRES_SUPER;

/**
For internal use only; don't use this initializer.
Expand Down Expand Up @@ -75,9 +75,9 @@
/**
Called when the component and all its children have been mounted.
@param analyticsListener The current analytics listener - can be nil.
@param systraceListener The current systrace listener - will be nil if systrace is not enabled.
*/
- (void)childrenDidMount:(id<CKAnalyticsListener>)analyticsListener;
- (void)childrenDidMount:(id<CKSystraceListener>)systraceListener;

/** Used to get the root component in the responder chain; don't touch this. */
@property (nonatomic, weak) UIView *rootComponentMountedView;
Expand Down
6 changes: 3 additions & 3 deletions ComponentKit/Core/CKComponentLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ CKMountComponentLayoutResult CKMountComponentLayout(const CKComponentLayout &lay
};

[analyticsListener willMountComponentTreeWithRootComponent:layout.component];
auto const analyticsListenerForMount = [analyticsListener isSystraceEnabled] ? analyticsListener : nil;
auto const systraceListener = [analyticsListener isSystraceEnabled] ? analyticsListener : nil;
// Using a stack to mount ensures that the components are mounted
// in a DFS fashion which is handy if you want to animate a subpart
// of the tree
Expand All @@ -93,7 +93,7 @@ CKMountComponentLayoutResult CKMountComponentLayout(const CKComponentLayout &lay
while (!stack.empty()) {
MountItem &item = stack.top();
if (item.visited) {
[item.layout.component childrenDidMount:analyticsListenerForMount];
[item.layout.component childrenDidMount:systraceListener];
stack.pop();
} else {
item.visited = YES;
Expand All @@ -104,7 +104,7 @@ CKMountComponentLayoutResult CKMountComponentLayout(const CKComponentLayout &lay
size:item.layout.size
children:item.layout.children
supercomponent:item.supercomponent
analyticsListener:analyticsListenerForMount];
systraceListener:systraceListener];
[mountedComponents addObject:item.layout.component];

if (mountResult.mountChildren) {
Expand Down
4 changes: 2 additions & 2 deletions ComponentKitTests/CKComponentMountContextLayoutGuideTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ @implementation CKLayoutGuideTestComponent
size:(const CGSize)size
children:(std::shared_ptr<const std::vector<CKComponentLayoutChild>>)children
supercomponent:(CKComponent *)supercomponent
analyticsListener:(id<CKAnalyticsListener>)analyticsListener
systraceListener:(id<CKSystraceListener>)systraceListener
{
const CK::Component::MountResult mountResult = [super mountInContext:context
size:size
children:children
supercomponent:supercomponent
analyticsListener:analyticsListener];
systraceListener:systraceListener];
_layoutGuideUsedAtMountTime = context.layoutGuide;
return mountResult;
}
Expand Down
4 changes: 2 additions & 2 deletions ComponentKitTests/CKComponentMountTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ - (CKComponentLayout)computeLayoutThatFits:(CKSizeRange)constrainedSize
size:(const CGSize)size
children:(std::shared_ptr<const std::vector<CKComponentLayoutChild>>)children
supercomponent:(CKComponent *)supercomponent
analyticsListener:(id<CKAnalyticsListener>)analyticsListener
systraceListener:(id<CKSystraceListener>)systraceListener
{
CK::Component::MountResult r = [super mountInContext:context size:size children:children supercomponent:supercomponent analyticsListener:analyticsListener];
CK::Component::MountResult r = [super mountInContext:context size:size children:children supercomponent:supercomponent systraceListener:systraceListener];
return {
.mountChildren = NO,
.contextForChildren = r.contextForChildren
Expand Down
4 changes: 2 additions & 2 deletions ComponentKitTests/CKComponentViewReuseTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ + (instancetype)newWithComponent:(CKComponent *)component
size:(const CGSize)size
children:(std::shared_ptr<const std::vector<CKComponentLayoutChild>>)children
supercomponent:(CKComponent *)supercomponent
analyticsListener:(id<CKAnalyticsListener>)analyticsListener
systraceListener:(id<CKSystraceListener>)systraceListener
{
const auto result = [super mountInContext:context size:size children:children supercomponent:supercomponent analyticsListener:analyticsListener];
const auto result = [super mountInContext:context size:size children:children supercomponent:supercomponent systraceListener:systraceListener];
CKInjectingView *injectingView = (CKInjectingView *)result.contextForChildren.viewManager->view;
return {
.mountChildren = YES,
Expand Down
6 changes: 3 additions & 3 deletions ComponentTextKit/CKTextComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#import "CKTextComponentView.h"

@protocol CKAnalyticsListener;
@protocol CKSystraceListener;

static CK::TextKit::Renderer::Cache *sharedRendererCache()
{
Expand Down Expand Up @@ -104,13 +104,13 @@ - (CKComponentLayout)computeLayoutThatFits:(CKSizeRange)constrainedSize
size:(const CGSize)size
children:(std::shared_ptr<const std::vector<CKComponentLayoutChild>>)children
supercomponent:(CKComponent *)supercomponent
analyticsListener:(id<CKAnalyticsListener>)analyticsListener
systraceListener:(id<CKSystraceListener>)systraceListener
{
CK::Component::MountResult result = [super mountInContext:context
size:size
children:children
supercomponent:supercomponent
analyticsListener:analyticsListener];
systraceListener:systraceListener];
CKTextComponentView *view = (CKTextComponentView *)result.contextForChildren.viewManager->view;
CKTextKitRenderer *renderer = rendererForAttributes(_attributes, size);
view.renderer = renderer;
Expand Down

0 comments on commit 4ccc5a7

Please sign in to comment.