Aligns the ink bar to the current item.
(previousIndicatorClientRect?: DOMRect)
| 96 | |
| 97 | /** Aligns the ink bar to the current item. */ |
| 98 | activateInkBar(previousIndicatorClientRect?: DOMRect) { |
| 99 | const element = this._elementRef.nativeElement; |
| 100 | |
| 101 | // Early exit if no indicator is present to handle cases where an indicator |
| 102 | // may be activated without a prior indicator state |
| 103 | if ( |
| 104 | !previousIndicatorClientRect || |
| 105 | !element.getBoundingClientRect || |
| 106 | !this._inkBarContentElement |
| 107 | ) { |
| 108 | element.classList.add(ACTIVE_CLASS); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | // This animation uses the FLIP approach. You can read more about it at the link below: |
| 113 | // https://aerotwist.com/blog/flip-your-animations/ |
| 114 | |
| 115 | // Calculate the dimensions based on the dimensions of the previous indicator |
| 116 | const currentClientRect = element.getBoundingClientRect(); |
| 117 | const widthDelta = previousIndicatorClientRect.width / currentClientRect.width; |
| 118 | const xPosition = previousIndicatorClientRect.left - currentClientRect.left; |
| 119 | element.classList.add(NO_TRANSITION_CLASS); |
| 120 | this._inkBarContentElement.style.setProperty( |
| 121 | 'transform', |
| 122 | `translateX(${xPosition}px) scaleX(${widthDelta})`, |
| 123 | ); |
| 124 | |
| 125 | // Force repaint before updating classes and transform to ensure the transform properly takes effect |
| 126 | element.getBoundingClientRect(); |
| 127 | |
| 128 | element.classList.remove(NO_TRANSITION_CLASS); |
| 129 | element.classList.add(ACTIVE_CLASS); |
| 130 | this._inkBarContentElement.style.setProperty('transform', ''); |
| 131 | } |
| 132 | |
| 133 | /** Removes the ink bar from the current item. */ |
| 134 | deactivateInkBar() { |
nothing calls this directly
no test coverage detected