ARTNode.m 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/ARTNode.h>
  8. #import <React/ARTContainer.h>
  9. @implementation ARTNode
  10. - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex
  11. {
  12. [super insertReactSubview:subview atIndex:atIndex];
  13. [self insertSubview:subview atIndex:atIndex];
  14. [self invalidate];
  15. }
  16. - (void)removeReactSubview:(UIView *)subview
  17. {
  18. [super removeReactSubview:subview];
  19. [self invalidate];
  20. }
  21. - (void)didUpdateReactSubviews
  22. {
  23. // Do nothing, as subviews are inserted by insertReactSubview:
  24. }
  25. - (void)setOpacity:(CGFloat)opacity
  26. {
  27. [self invalidate];
  28. _opacity = opacity;
  29. }
  30. - (void)setTransform:(CGAffineTransform)transform
  31. {
  32. [self invalidate];
  33. super.transform = transform;
  34. }
  35. - (void)invalidate
  36. {
  37. id<ARTContainer> container = (id<ARTContainer>)self.superview;
  38. [container invalidate];
  39. }
  40. - (void)renderTo:(CGContextRef)context
  41. {
  42. if (self.opacity <= 0) {
  43. // Nothing to paint
  44. return;
  45. }
  46. if (self.opacity >= 1) {
  47. // Just paint at full opacity
  48. CGContextSaveGState(context);
  49. CGContextConcatCTM(context, self.transform);
  50. CGContextSetAlpha(context, 1);
  51. [self renderLayerTo:context];
  52. CGContextRestoreGState(context);
  53. return;
  54. }
  55. // This needs to be painted on a layer before being composited.
  56. CGContextSaveGState(context);
  57. CGContextConcatCTM(context, self.transform);
  58. CGContextSetAlpha(context, self.opacity);
  59. CGContextBeginTransparencyLayer(context, NULL);
  60. [self renderLayerTo:context];
  61. CGContextEndTransparencyLayer(context);
  62. CGContextRestoreGState(context);
  63. }
  64. - (void)renderLayerTo:(CGContextRef)context
  65. {
  66. // abstract
  67. }
  68. @end