react-native-navigation的迁移库

RNNTransitionStateHolder.m 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #import "RNNTransitionStateHolder.h"
  2. #import "RNNUtils.h"
  3. @interface RNNTransitionStateHolder() {
  4. CGRect _initialFrame;
  5. }
  6. @end
  7. @implementation RNNTransitionStateHolder
  8. -(instancetype)initWithTransition:(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. - (UIViewAnimationOptions)animationOptionsFromString:(NSString*)interpolationString {
  28. if ([interpolationString isEqualToString:@"accelerate"]) {
  29. return UIViewAnimationOptionCurveEaseIn;
  30. } else if ([interpolationString isEqualToString:@"decelerate"]) {
  31. return UIViewAnimationOptionCurveEaseOut;
  32. }
  33. return UIViewAnimationOptionCurveEaseInOut;
  34. }
  35. - (void)setupInitialTransitionForView:(UIView*)view {
  36. _initialFrame = view.frame;
  37. view.alpha = self.startAlpha;
  38. view.frame = CGRectMake(_initialFrame.origin.x + self.startX, _initialFrame.origin.y + self.startY, view.frame.size.width, view.frame.size.height);
  39. }
  40. - (void)completeTransitionForView:(UIView*)view {
  41. view.alpha = self.endAlpha;
  42. view.frame = CGRectMake(_initialFrame.origin.x + self.endX, _initialFrame.origin.y + self.endY, view.frame.size.width, view.frame.size.height);
  43. [view layoutSubviews];
  44. }
  45. @end