ARTSurfaceView.m 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import <React/ARTSurfaceView.h>
  8. #import <React/RCTLog.h>
  9. #import <React/ARTNode.h>
  10. @implementation ARTSurfaceView
  11. - (instancetype)initWithFrame:(CGRect)frame
  12. {
  13. if (self = [super initWithFrame:frame]) {
  14. self.opaque = NO;
  15. }
  16. return self;
  17. }
  18. - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex
  19. {
  20. [super insertReactSubview:subview atIndex:atIndex];
  21. [self insertSubview:subview atIndex:atIndex];
  22. [self invalidate];
  23. }
  24. - (void)removeReactSubview:(UIView *)subview
  25. {
  26. [super removeReactSubview:subview];
  27. [self invalidate];
  28. }
  29. - (void)didUpdateReactSubviews
  30. {
  31. // Do nothing, as subviews are inserted by insertReactSubview:
  32. }
  33. - (void)invalidate
  34. {
  35. [self setNeedsDisplay];
  36. }
  37. - (void)drawRect:(CGRect)rect
  38. {
  39. [super drawRect:rect];
  40. CGContextRef context = UIGraphicsGetCurrentContext();
  41. for (ARTNode *node in self.subviews) {
  42. [node renderTo:context];
  43. }
  44. }
  45. @end