File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import React , { FC } from 'react' ;
22import { DEFAULT_HEIGHT , DEFAULT_WIDTH } from '../../constants/constants' ;
33import { IconProps } from '../types' ;
4- import { PathStyle , injectKeyframes } from './style' ;
5-
6- injectKeyframes ( ) ;
4+ import { PathStyle , keyframesCSS } from './style' ;
75
86export interface ConfigurationIconProps extends IconProps {
97 isHoverEffect ?: boolean ;
@@ -25,6 +23,7 @@ export const ConfigurationIcon: FC<ConfigurationIconProps> = ({
2523 className = { isHoverEffect ? 'configuration-icon-go' : undefined }
2624 { ...props }
2725 >
26+ { isHoverEffect ? < style > { keyframesCSS } </ style > : null }
2827 < path
2928 className = "configuration-icon-path1"
3029 style = { PathStyle }
Original file line number Diff line number Diff line change 11import React from 'react' ;
22
3- export const StyleID = 'configuration-icon-keyframes' ;
4-
53export const keyframesCSS = `
64@keyframes config-wrench-shake {
75 0% { transform: rotate(-20deg); }
@@ -21,12 +19,3 @@ export const PathStyle: React.CSSProperties = {
2119 transformBox : 'fill-box' ,
2220 transformOrigin : 'center' ,
2321} ;
24-
25- export function injectKeyframes ( ) : void {
26- if ( typeof document === 'undefined' ) return ;
27- if ( document . getElementById ( StyleID ) ) return ;
28- const style = document . createElement ( 'style' ) ;
29- style . id = StyleID ;
30- style . textContent = keyframesCSS ;
31- document . head . appendChild ( style ) ;
32- }
Original file line number Diff line number Diff line change @@ -19,10 +19,14 @@ export function useAnimationTrigger(
1919 svg . classList . add ( 'dashboard-icon-go' ) ;
2020
2121 const lastPath = svg . querySelector ( '.dashboard-icon-bl' ) ;
22- lastPath ?. addEventListener (
23- 'animationend' ,
24- ( ) => svg . classList . remove ( 'dashboard-icon-go' ) ,
25- { once : true }
26- ) ;
22+ const handleAnimationEnd = ( ) => {
23+ svg . classList . remove ( 'dashboard-icon-go' ) ;
24+ } ;
25+
26+ lastPath ?. addEventListener ( 'animationend' , handleAnimationEnd , { once : true } ) ;
27+
28+ return ( ) => {
29+ lastPath ?. removeEventListener ( 'animationend' , handleAnimationEnd ) ;
30+ } ;
2731 } , [ isHoverEffect , svgRef ] ) ;
2832}
Original file line number Diff line number Diff line change @@ -44,18 +44,25 @@ export function useNeedleSpring(
4444 s . current = { cur : ROT_ZERO , vel : 0 } ;
4545 set ( ROT_ZERO ) ;
4646
47- const tick = ( ) => {
47+ let lastTime = performance . now ( ) ;
48+
49+ const tick = ( now : number ) => {
50+ const dt = Math . min ( ( now - lastTime ) / 1000 , 0.1 ) ;
51+ lastTime = now ;
4852 const { cur, vel } = s . current ;
49- const v = vel + ( - 32.5 * ( cur - ROT_REST ) - 9 * vel ) * 0.016 ;
50- const c = cur + v * 0.016 ;
53+ const v = vel + ( - 32.5 * ( cur - ROT_REST ) - 9 * vel ) * dt ;
54+ const c = cur + v * dt ;
5155 s . current = { cur : c , vel : v } ;
5256 set ( c ) ;
5357 if ( Math . abs ( c - ROT_REST ) > 0.05 || Math . abs ( v ) > 0.05 )
5458 raf . current = requestAnimationFrame ( tick ) ;
5559 else { set ( ROT_REST ) ; s . current = { cur : ROT_REST , vel : 0 } ; raf . current = null ; }
5660 } ;
5761
58- timer . current = setTimeout ( ( ) => { raf . current = requestAnimationFrame ( tick ) ; } , 60 ) ;
62+ timer . current = setTimeout ( ( ) => {
63+ lastTime = performance . now ( ) ;
64+ raf . current = requestAnimationFrame ( tick ) ;
65+ } , 60 ) ;
5966
6067 return ( ) => {
6168 if ( timer . current ) {
You can’t perform that action at this time.
0 commit comments