Home Reference Source Repository

js/QuartzCore/CAAnimationGroup.js

  1. 'use strict'
  2.  
  3. import CAAnimation from './CAAnimation'
  4.  
  5.  
  6. /**
  7. * An object that allows multiple animations to be grouped and run concurrently.
  8. * @access public
  9. * @extends {CAAnimation}
  10. * @see https://developer.apple.com/documentation/quartzcore/caanimationgroup
  11. */
  12. export default class CAAnimationGroup extends CAAnimation {
  13.  
  14. /**
  15. * constructor
  16. * @access public
  17. * @constructor
  18. */
  19. constructor() {
  20. super()
  21.  
  22. // Grouped animations
  23.  
  24. /**
  25. * An array of CAAnimation objects to be evaluated in the time space of the receiver.
  26. * @type {?CAAnimation[]}
  27. * @see https://developer.apple.com/documentation/quartzcore/caanimationgroup/1412516-animations
  28. */
  29. this.animations = []
  30. }
  31.  
  32. /**
  33. * apply animation to the given node.
  34. * @access private
  35. * @param {Object} obj - target object to apply this animation.
  36. * @param {number} time - active time
  37. * @param {boolean} [needTimeConversion = true] -
  38. * @returns {void}
  39. */
  40. _applyAnimation(obj, time, needTimeConversion = true) {
  41. let t = time
  42. if(needTimeConversion){
  43. const baseTime = this._basetimeFromTime(time)
  44. t = baseTime
  45. if(this.timingFunction !== null){
  46. t = this.timingFunction._getValueAtTime(baseTime)
  47. }
  48. //console.log(`time ${time} activeTime ${time - this._animationStartTime} baseTime ${baseTime}`)
  49. }
  50.  
  51. this.animations.forEach((animation) => {
  52. animation._applyAnimation(obj, t, false)
  53. })
  54. this._handleEvents(obj, t)
  55. }
  56.  
  57. /**
  58. * @access public
  59. * @returns {CAAnimationGroup} -
  60. */
  61. copy() {
  62. //console.log('CAAnimationGroup.copy')
  63. const anim = super.copy()
  64.  
  65. anim.animations = this.animations.slice()
  66.  
  67. return anim
  68. }
  69.  
  70. /*
  71. _copyValue(src) {
  72. console.log('CAAnimationGroup._copyValue')
  73. //super._copyValue(src)
  74. this.animations = src.animations.slice()
  75. }
  76. */
  77.  
  78. }