-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[TraceUpdateOverlay]: add iOS native component (#41563)
Summary: Pull Request resolved: #41563 Changelog: [iOS][Added] - support "highlighting updates when components render" feature from React DevTools Reviewed By: javache Differential Revision: D51470012 fbshipit-source-id: ba4094ae24d14f58ad08acbb90333bbe49e043c9
- Loading branch information
1 parent
fd35c1d
commit 758e59f
Showing
9 changed files
with
210 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ct/Fabric/Mounting/ComponentViews/TraceUpdateOverlay/RCTTraceUpdateOverlayComponentView.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#import <React/RCTViewComponentView.h> | ||
|
||
#import <react/renderer/components/rncore/RCTComponentViewHelpers.h> | ||
|
||
@interface RCTTraceUpdateOverlayComponentView : RCTViewComponentView <RCTTraceUpdateOverlayViewProtocol> | ||
|
||
@end |
65 changes: 65 additions & 0 deletions
65
...t/Fabric/Mounting/ComponentViews/TraceUpdateOverlay/RCTTraceUpdateOverlayComponentView.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import "RCTTraceUpdateOverlayComponentView.h" | ||
|
||
#import <React/RCTDefines.h> | ||
#import <React/RCTLog.h> | ||
#import <React/RCTTraceUpdateOverlay.h> | ||
|
||
#import <react/renderer/components/rncore/ComponentDescriptors.h> | ||
#import <react/renderer/components/rncore/EventEmitters.h> | ||
#import <react/renderer/components/rncore/Props.h> | ||
#import <react/renderer/components/rncore/RCTComponentViewHelpers.h> | ||
|
||
#import "RCTFabricComponentsPlugins.h" | ||
|
||
using namespace facebook::react; | ||
|
||
@implementation RCTTraceUpdateOverlayComponentView { | ||
RCTTraceUpdateOverlay *_overlay; | ||
} | ||
|
||
- (instancetype)initWithFrame:(CGRect)frame | ||
{ | ||
if (self = [super initWithFrame:frame]) { | ||
static const auto defaultProps = std::make_shared<const TraceUpdateOverlayProps>(); | ||
_props = defaultProps; | ||
|
||
_overlay = [[RCTTraceUpdateOverlay alloc] initWithFrame:self.bounds]; | ||
|
||
self.contentView = _overlay; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
#pragma mark - RCTComponentViewProtocol | ||
|
||
+ (ComponentDescriptorProvider)componentDescriptorProvider | ||
{ | ||
return concreteComponentDescriptorProvider<TraceUpdateOverlayComponentDescriptor>(); | ||
} | ||
|
||
#pragma mark - Native commands | ||
|
||
- (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args | ||
{ | ||
RCTTraceUpdateOverlayHandleCommand(self, commandName, args); | ||
} | ||
|
||
- (void)draw:(NSString *)overlays | ||
{ | ||
[_overlay draw:overlays]; | ||
} | ||
|
||
@end | ||
|
||
Class<RCTComponentViewProtocol> RCTTraceUpdateOverlayCls(void) | ||
{ | ||
return RCTTraceUpdateOverlayComponentView.class; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#import <React/RCTView.h> | ||
|
||
@interface RCTTraceUpdateOverlay : RCTView | ||
|
||
- (void)draw:(NSString *)serializedNodes; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import "RCTTraceUpdateOverlay.h" | ||
|
||
#import <React/RCTConvert.h> | ||
#import <React/RCTLog.h> | ||
#import <React/RCTUtils.h> | ||
|
||
@implementation RCTTraceUpdateOverlay | ||
|
||
- (void)draw:(NSString *)serializedNodes | ||
{ | ||
NSArray *subViewsToRemove = [self subviews]; | ||
for (UIView *v in subViewsToRemove) { | ||
[v removeFromSuperview]; | ||
} | ||
|
||
NSError *error = nil; | ||
id deserializedNodes = RCTJSONParse(serializedNodes, &error); | ||
|
||
if (error) { | ||
RCTLogError(@"Failed to parse serialized nodes passed to RCTTraceUpdatesOverlay"); | ||
return; | ||
} | ||
|
||
if (![deserializedNodes isKindOfClass:[NSArray class]]) { | ||
RCTLogError(@"Expected to receive nodes as an array, got %@", NSStringFromClass([deserializedNodes class])); | ||
return; | ||
} | ||
|
||
for (NSDictionary *node in deserializedNodes) { | ||
NSDictionary *nodeRectangle = node[@"rect"]; | ||
NSNumber *nodeColor = node[@"color"]; | ||
|
||
NSNumber *x = nodeRectangle[@"left"]; | ||
NSNumber *y = nodeRectangle[@"top"]; | ||
NSNumber *width = nodeRectangle[@"width"]; | ||
NSNumber *height = nodeRectangle[@"height"]; | ||
|
||
CGRect rect = CGRectMake(x.doubleValue, y.doubleValue, width.doubleValue, height.doubleValue); | ||
|
||
UIView *box = [[UIView alloc] initWithFrame:rect]; | ||
box.backgroundColor = [UIColor clearColor]; | ||
|
||
box.layer.borderWidth = 2.0f; | ||
box.layer.borderColor = [RCTConvert UIColor:nodeColor].CGColor; | ||
|
||
[self addSubview:box]; | ||
} | ||
} | ||
|
||
@end |
12 changes: 12 additions & 0 deletions
12
packages/react-native/React/Views/RCTTraceUpdateOverlayManager.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import <React/RCTViewManager.h> | ||
|
||
@interface RCTTraceUpdateOverlayManager : RCTViewManager | ||
|
||
@end |
38 changes: 38 additions & 0 deletions
38
packages/react-native/React/Views/RCTTraceUpdateOverlayManager.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import "RCTTraceUpdateOverlayManager.h" | ||
#import "RCTTraceUpdateOverlay.h" | ||
|
||
#import <React/RCTLog.h> | ||
#import <React/RCTUIManager.h> | ||
|
||
#import "RCTBridge.h" | ||
|
||
@implementation RCTTraceUpdateOverlayManager | ||
|
||
RCT_EXPORT_MODULE(TraceUpdateOverlay) | ||
|
||
- (UIView *)view | ||
{ | ||
return [RCTTraceUpdateOverlay new]; | ||
} | ||
|
||
RCT_EXPORT_METHOD(draw : (nonnull NSNumber *)viewTag nodes : (NSString *)serializedNodes) | ||
{ | ||
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) { | ||
UIView *view = viewRegistry[viewTag]; | ||
|
||
if ([view isKindOfClass:[RCTTraceUpdateOverlay class]]) { | ||
[(RCTTraceUpdateOverlay *)view draw:serializedNodes]; | ||
} else { | ||
RCTLogError(@"Expected view to be RCTTraceUpdateOverlay, got %@", NSStringFromClass([view class])); | ||
} | ||
}]; | ||
} | ||
|
||
@end |