react-native-navigation的迁移库

RNNTransitionStateHolder.m 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.interpolation = [self animationOptionsFromString:transition[@"interpolation"]];
  24. return self;
  25. }
  26. - (void)mergeWith:(NSDictionary *)transition {
  27. self.springDamping = [RNNUtils getDoubleOrKey:transition withKey:@"springDamping" withDefault:0.85];
  28. self.springVelocity = [RNNUtils getDoubleOrKey:transition withKey:@"springVelocity" withDefault:0.8];
  29. self.startDelay = [RNNUtils getDoubleOrKey:transition withKey:@"startDelay" withDefault:0];
  30. self.duration = [RNNUtils getDoubleOrKey:transition withKey:@"duration" withDefault:1];
  31. self.startAlpha = [RNNUtils getDoubleOrKey:transition withKey:@"startAlpha" withDefault:1];
  32. self.endAlpha = [RNNUtils getDoubleOrKey:transition withKey:@"endAlpha" withDefault:1];
  33. self.interactivePop = [RNNUtils getBoolOrKey:transition withKey:@"interactivePop" withDefault:NO];
  34. self.startX = [RNNUtils getDoubleOrKey:transition[@"x"] withKey:@"from" withDefault:0];
  35. self.startY = [RNNUtils getDoubleOrKey:transition[@"y"] withKey:@"from" withDefault:0];
  36. self.endX = [RNNUtils getDoubleOrKey:transition[@"x"] withKey:@"to" withDefault:0];
  37. self.endY = [RNNUtils getDoubleOrKey:transition[@"y"] withKey:@"to" withDefault:0];
  38. self.fromId = [transition objectForKey:@"fromId"];
  39. self.toId = [transition objectForKey:@"toId"];
  40. self.interpolation = [self animationOptionsFromString:transition[@"interpolation"]];
  41. }
  42. - (UIViewAnimationOptions)animationOptionsFromString:(NSString*)interpolationString {
  43. if ([interpolationString isEqualToString:@"accelerate"]) {
  44. return UIViewAnimationOptionCurveEaseIn;
  45. } else if ([interpolationString isEqualToString:@"decelerate"]) {
  46. return UIViewAnimationOptionCurveEaseOut;
  47. }
  48. return UIViewAnimationOptionCurveEaseInOut;
  49. }
  50. - (CGPoint)startPoint {
  51. return CGPointMake(self.startX, self.startY);
  52. }
  53. - (CGPoint)endPoint {
  54. return CGPointMake(self.endX, self.endY);
  55. }
  56. @end