PHP 7.4.33
Preview: RCTDebuggingOverlay.m Size: 3.52 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/react-native/React/Views/RCTDebuggingOverlay.m
/*
 * 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 "RCTDebuggingOverlay.h"

#import <React/RCTConvert.h>
#import <React/RCTLog.h>
#import <React/RCTUtils.h>

@implementation TraceUpdateTuple

- (instancetype)initWithView:(UIView *)view cleanupBlock:(dispatch_block_t)cleanupBlock
{
  if (self = [super init]) {
    _view = view;
    _cleanupBlock = cleanupBlock;
  }

  return self;
}

@end

@implementation RCTDebuggingOverlay {
  NSMutableArray<UIView *> *_highlightedElements;
  NSMutableDictionary<NSNumber *, TraceUpdateTuple *> *_idToTraceUpdateMap;
}

- (instancetype)initWithFrame:(CGRect)frame
{
  self = [super initWithFrame:frame];
  if (self) {
    _idToTraceUpdateMap = [NSMutableDictionary new];
  }
  return self;
}

- (void)highlightTraceUpdates:(NSArray *)updates
{
  for (NSDictionary *update in updates) {
    NSNumber *identifier = [RCTConvert NSNumber:update[@"id"]];
    NSDictionary *nodeRectangle = update[@"rectangle"];
    UIColor *nodeColor = [RCTConvert UIColor:update[@"color"]];

    CGRect rect = [RCTConvert CGRect:nodeRectangle];

    TraceUpdateTuple *possiblyRegisteredTraceUpdateTuple = [_idToTraceUpdateMap objectForKey:identifier];
    if (possiblyRegisteredTraceUpdateTuple != nil) {
      dispatch_block_t cleanupBlock = [possiblyRegisteredTraceUpdateTuple cleanupBlock];
      UIView *view = [possiblyRegisteredTraceUpdateTuple view];

      dispatch_block_cancel(cleanupBlock);

      view.frame = rect;
      view.layer.borderColor = nodeColor.CGColor;

      dispatch_block_t newCleanupBlock = dispatch_block_create(0, ^{
        [self->_idToTraceUpdateMap removeObjectForKey:identifier];
        [view removeFromSuperview];
      });

      [_idToTraceUpdateMap setObject:[[TraceUpdateTuple alloc] initWithView:view cleanupBlock:newCleanupBlock]
                              forKey:identifier];

      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), newCleanupBlock);

      continue;
    }

    UIView *box = [[UIView alloc] initWithFrame:rect];
    box.backgroundColor = [UIColor clearColor];

    box.layer.borderWidth = 2.0f;
    box.layer.borderColor = nodeColor.CGColor;

    dispatch_block_t unmountViewAndPerformCleanup = dispatch_block_create(0, ^{
      [self->_idToTraceUpdateMap removeObjectForKey:identifier];
      [box removeFromSuperview];
    });

    TraceUpdateTuple *traceUpdateTuple = [[TraceUpdateTuple alloc] initWithView:box
                                                                   cleanupBlock:unmountViewAndPerformCleanup];

    [_idToTraceUpdateMap setObject:traceUpdateTuple forKey:identifier];
    [self addSubview:box];

    dispatch_after(
        dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), unmountViewAndPerformCleanup);
  }
}

- (void)highlightElements:(NSArray *)rectangles
{
  if (_highlightedElements == nil) {
    _highlightedElements = [NSMutableArray new];
  }

  for (NSDictionary *rectangle in rectangles) {
    UIView *view = [[UIView alloc] initWithFrame:[RCTConvert CGRect:rectangle]];
    view.backgroundColor = [UIColor colorWithRed:200 / 255.0 green:230 / 255.0 blue:255 / 255.0 alpha:0.8];

    [self addSubview:view];
    [_highlightedElements addObject:view];
  }
}

- (void)clearElementsHighlights
{
  if (_highlightedElements != nil) {
    for (UIView *v in _highlightedElements) {
      [v removeFromSuperview];
    }
  }

  _highlightedElements = nil;
}

@end

Directory Contents

Dirs: 3 × Files: 59
Name Size Perms Modified Actions
- drwxr-xr-x 2025-03-28 11:04:43
Edit Download
- drwxr-xr-x 2025-03-28 11:04:43
Edit Download
- drwxr-xr-x 2025-03-28 11:04:43
Edit Download
283 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
444 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
418 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.51 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
446 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
880 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
332 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.01 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
20.67 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
372 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.74 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.80 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
20.24 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
463 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
640 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
380 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
5.49 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
306 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
683 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
3.52 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
286 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.96 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.70 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
18.54 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
2.29 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
4.57 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.78 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
6.86 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
446 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.85 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
997 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
3.87 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
399 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
670 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
400 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
880 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.09 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
387 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
429 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.06 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.92 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
8.82 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
26.60 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
389 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
377 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
276 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.75 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
453 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
5.11 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
37.36 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
4.64 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
28.90 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
376 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
500 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
397 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.09 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
459 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
4.44 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
13.40 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).