react-native-navigation的迁移库

RNNTransitionStateHolder.m 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #import "RNNTransitionStateHolder.h"
  2. #import "RNNUtils.h"
  3. @interface RNNTransitionStateHolder() {
  4. CGRect _initialFrame;
  5. }
  6. @end
  7. @implementation RNNTransitionStateHolder
  8. -(instancetype)initWithDict:(NSDictionary *)transition {
  9. self = [super init];
  10. self.springDamping = [RNNUtils getDoubleOrKey:transition withKey:@"springDamping" withDefault:0.85];
  11. self.springVelocity = [RNNUtils getDoubleOrKey:transition withKey:@"springVelocity" withDefault:0.8];
  12. self.startDelay = [RNNUtils getDoubleOrKey:transition withKey:@"startDelay" withDefault:0];
  13. self.duration = [RNNUtils getDoubleOrKey:transition withKey:@"duration" withDefault:1];
  14. self.startAlpha = [RNNUtils getDoubleOrKey:transition withKey:@"startAlpha" withDefault:1];
  15. self.endAlpha = [RNNUtils getDoubleOrKey:transition withKey:@"endAlpha" withDefault:1];
  16. self.interactivePop = [RNNUtils getBoolOrKey:transition withKey:@"interactivePop" withDefault:NO];
  17. self.startX = [RNNUtils getDoubleOrKey:transition[@"x"] withKey:@"from" withDefault:0];
  18. self.startY = [RNNUtils getDoubleOrKey:transition[@"y"] withKey:@"from" withDefault:0];
  19. self.endX = [RNNUtils getDoubleOrKey:transition[@"x"] withKey:@"to" withDefault:0];
  20. self.endY = [RNNUtils getDoubleOrKey:transition[@"y"] withKey:@"to" withDefault:0];
  21. self.fromId = [transition objectForKey:@"fromId"];
  22. self.toId = [transition objectForKey:@"toId"];
  23. self.isSharedElementTransition = [[transition objectForKey:@"type"] isEqualToString:@"sharedElement"];
  24. self.interpolation = [self animationOptionsFromString:transition[@"interpolation"]];
  25. return self;
  26. }
  27. - (void)mergeWith:(NSDictionary *)transition {
  28. self.springDamping = [RNNUtils getDoubleOrKey:transition withKey:@"springDamping" withDefault:0.85];
  29. self.springVelocity = [RNNUtils getDoubleOrKey:transition withKey:@"springVelocity" withDefault:0.8];
  30. self.startDelay = [RNNUtils getDoubleOrKey:transition withKey:@"startDelay" withDefault:0];
  31. self.duration = [RNNUtils getDoubleOrKey:transition withKey:@"duration" withDefault:1];
  32. self.startAlpha = [RNNUtils getDoubleOrKey:transition withKey:@"startAlpha" withDefault:1];
  33. self.endAlpha = [RNNUtils getDoubleOrKey:transition withKey:@"endAlpha" withDefault:1];
  34. self.interactivePop = [RNNUtils getBoolOrKey:transition withKey:@"interactivePop" withDefault:NO];
  35. self.startX = [RNNUtils getDoubleOrKey:transition[@"x"] withKey:@"from" withDefault:0];
  36. self.startY = [RNNUtils getDoubleOrKey:transition[@"y"] withKey:@"from" withDefault:0];
  37. self.endX = [RNNUtils getDoubleOrKey:transition[@"x"] withKey:@"to" withDefault:0];
  38. self.endY = [RNNUtils getDoubleOrKey:transition[@"y"] withKey:@"to" withDefault:0];
  39. self.fromId = [transition objectForKey:@"fromId"];
  40. self.toId = [transition objectForKey:@"toId"];
  41. self.isSharedElementTransition = [[transition objectForKey:@"type"] isEqualToString:@"sharedElement"];
  42. self.interpolation = [self animationOptionsFromString:transition[@"interpolation"]];
  43. }
  44. - (UIViewAnimationOptions)animationOptionsFromString:(NSString*)interpolationString {
  45. if ([interpolationString isEqualToString:@"accelerate"]) {
  46. return UIViewAnimationOptionCurveEaseIn;
  47. } else if ([interpolationString isEqualToString:@"decelerate"]) {
  48. return UIViewAnimationOptionCurveEaseOut;
  49. }
  50. return UIViewAnimationOptionCurveEaseInOut;
  51. }
  52. - (void)setupInitialTransitionForView:(UIView*)view {
  53. _initialFrame = view.frame;
  54. view.alpha = self.startAlpha;
  55. view.frame = CGRectMake(_initialFrame.origin.x + self.startX, _initialFrame.origin.y + self.startY, view.frame.size.width, view.frame.size.height);
  56. }
  57. - (void)completeTransitionForView:(UIView*)view {
  58. view.alpha = self.endAlpha;
  59. view.frame = CGRectMake(_initialFrame.origin.x + self.endX, _initialFrame.origin.y + self.endY, view.frame.size.width, view.frame.size.height);
  60. [view layoutSubviews];
  61. }
  62. @end