react-native-navigation的迁移库

AnimatedReactView.m 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #import "AnimatedReactView.h"
  2. #import <React/UIView+React.h>
  3. @implementation AnimatedReactView {
  4. UIView* _originalParent;
  5. CGRect _originalFrame;
  6. UIView* _toElement;
  7. UIColor* _fromColor;
  8. NSInteger _zIndex;
  9. SharedElementTransitionOptions* _transitionOptions;
  10. }
  11. - (instancetype)initElement:(UIView *)element toElement:(UIView *)toElement transitionOptions:(SharedElementTransitionOptions *)transitionOptions {
  12. self.location = [[RNNViewLocation alloc] initWithFromElement:element toElement:toElement];
  13. self = [super initWithFrame:self.location.fromFrame];
  14. _transitionOptions = transitionOptions;
  15. _toElement = toElement;
  16. _toElement.hidden = YES;
  17. _fromColor = element.backgroundColor;
  18. _zIndex = toElement.reactZIndex;
  19. [self hijackReactElement:element];
  20. return self;
  21. }
  22. - (void)setBackgroundColor:(UIColor *)backgroundColor {
  23. [super setBackgroundColor:backgroundColor];
  24. _reactView.backgroundColor = backgroundColor;
  25. }
  26. - (NSNumber *)reactZIndex {
  27. return @(_zIndex);
  28. }
  29. - (void)hijackReactElement:(UIView *)element {
  30. _reactView = element;
  31. _originalFrame = _reactView.frame;
  32. self.frame = self.location.fromFrame;
  33. _originalParent = _reactView.superview;
  34. _reactView.frame = self.bounds;
  35. [self addSubview:_reactView];
  36. }
  37. - (void)reset {
  38. _reactView.frame = _originalFrame;
  39. [_originalParent addSubview:_reactView];
  40. _toElement.hidden = NO;
  41. _reactView.backgroundColor = _fromColor;
  42. [self removeFromSuperview];
  43. }
  44. - (void)layoutSubviews {
  45. [super layoutSubviews];
  46. _reactView.frame = self.bounds;
  47. }
  48. @end