react-native-navigation的迁移库

RNNViewLocation.m 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #import "RNNViewLocation.h"
  2. #import "RNNReactView.h"
  3. #import <React/RCTSafeAreaView.h>
  4. @implementation RNNViewLocation
  5. - (instancetype)initWithFromElement:(UIView *)fromElement toElement:(UIView *)toElement {
  6. self = [super init];
  7. self.fromFrame = [self convertViewFrame:fromElement];
  8. self.toFrame = [self convertViewFrame:toElement];
  9. return self;
  10. }
  11. - (CGRect)convertViewFrame:(UIView *)view {
  12. UIView* topMostView = [self topMostView:view];
  13. CGRect frame = [view.superview convertRect:view.frame toView:nil];
  14. CGFloat safeAreaTopOffset = [self safeAreaOffsetForView:view inView:topMostView];
  15. frame.origin.y += safeAreaTopOffset;
  16. return frame;
  17. }
  18. - (UIView *)topMostView:(UIView *)view {
  19. if ([view isKindOfClass:[RNNReactView class]]) {
  20. return view;
  21. } else {
  22. return [self topMostView:view.superview];
  23. }
  24. }
  25. - (CGFloat)safeAreaOffsetForView:(UIView *)view inView:(UIView *)inView {
  26. CGFloat safeAreaOffset = inView.layoutMarginsGuide.layoutFrame.origin.y;
  27. if ([view isKindOfClass:RCTSafeAreaView.class] && [[view valueForKey:@"_currentSafeAreaInsets"] UIEdgeInsetsValue].top != safeAreaOffset) {
  28. return safeAreaOffset;
  29. } else if (view.superview) {
  30. return [self safeAreaOffsetForView:view.superview inView:inView];
  31. }
  32. return 0;
  33. }
  34. @end