POPAnimationEvent.mm 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. Copyright (c) 2014-present, Facebook, Inc.
  3. All rights reserved.
  4. This source code is licensed under the BSD-style license found in the
  5. LICENSE file in the root directory of this source tree. An additional grant
  6. of patent rights can be found in the PATENTS file in the same directory.
  7. */
  8. #import "POPAnimationEvent.h"
  9. #import "POPAnimationEventInternal.h"
  10. static NSString *stringFromType(POPAnimationEventType aType)
  11. {
  12. switch (aType) {
  13. case kPOPAnimationEventPropertyRead:
  14. return @"read";
  15. case kPOPAnimationEventPropertyWrite:
  16. return @"write";
  17. case kPOPAnimationEventToValueUpdate:
  18. return @"toValue";
  19. case kPOPAnimationEventFromValueUpdate:
  20. return @"fromValue";
  21. case kPOPAnimationEventVelocityUpdate:
  22. return @"velocity";
  23. case kPOPAnimationEventSpeedUpdate:
  24. return @"speed";
  25. case kPOPAnimationEventBouncinessUpdate:
  26. return @"bounciness";
  27. case kPOPAnimationEventFrictionUpdate:
  28. return @"friction";
  29. case kPOPAnimationEventMassUpdate:
  30. return @"mass";
  31. case kPOPAnimationEventTensionUpdate:
  32. return @"tension";
  33. case kPOPAnimationEventDidStart:
  34. return @"didStart";
  35. case kPOPAnimationEventDidStop:
  36. return @"didStop";
  37. case kPOPAnimationEventDidReachToValue:
  38. return @"didReachToValue";
  39. case kPOPAnimationEventAutoreversed:
  40. return @"autoreversed";
  41. default:
  42. return nil;
  43. }
  44. }
  45. @implementation POPAnimationEvent
  46. @synthesize type = _type;
  47. @synthesize time = _time;
  48. @synthesize animationDescription = _animationDescription;
  49. - (instancetype)initWithType:(POPAnimationEventType)aType time:(CFTimeInterval)aTime
  50. {
  51. self = [super init];
  52. if (nil != self) {
  53. _type = aType;
  54. _time = aTime;
  55. }
  56. return self;
  57. }
  58. - (NSString *)description
  59. {
  60. NSMutableString *s = [NSMutableString stringWithFormat:@"<POPAnimationEvent:%f; type = %@", _time, stringFromType(_type)];
  61. [self _appendDescription:s];
  62. [s appendString:@">"];
  63. return s;
  64. }
  65. // subclass override
  66. - (void)_appendDescription:(NSMutableString *)s
  67. {
  68. if (0 != _animationDescription.length) {
  69. [s appendFormat:@"; animation = %@", _animationDescription];
  70. }
  71. }
  72. @end
  73. @implementation POPAnimationValueEvent
  74. @synthesize value = _value;
  75. @synthesize velocity = _velocity;
  76. - (instancetype)initWithType:(POPAnimationEventType)aType time:(CFTimeInterval)aTime value:(id)aValue
  77. {
  78. self = [self initWithType:aType time:aTime];
  79. if (nil != self) {
  80. _value = aValue;
  81. }
  82. return self;
  83. }
  84. - (void)_appendDescription:(NSMutableString *)s
  85. {
  86. [super _appendDescription:s];
  87. if (nil != _value) {
  88. [s appendFormat:@"; value = %@", _value];
  89. }
  90. if (nil != _velocity) {
  91. [s appendFormat:@"; velocity = %@", _velocity];
  92. }
  93. }
  94. @end