Skip to content

Commit

Permalink
refactor(core): text animation functionalities
Browse files Browse the repository at this point in the history
  • Loading branch information
romelperez committed Feb 5, 2021
1 parent 17b555f commit d89a624
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/Text/Text.animator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
TextAnimationRefs,
startTextAnimation,
stopTextAnimation
} from './Text.animations';
} from '../utils/textAnimations';

const useAnimateEntering = (animator: AnimatorRef, refs: TextAnimationRefs, bleeps: Bleeps): void => {
startTextAnimation(animator, refs, bleeps);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Text/Text.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { jsx } from '@emotion/react';
import { WithAnimatorInputProps } from '@arwes/animation';
import { WithBleepsInputProps } from '@arwes/sounds';

import { TextAnimationRefs, startTextAnimation } from '../utils/textAnimations';
import { styles } from './Text.styles';
import { TextAnimationRefs, startTextAnimation } from './Text.animations';

// Browser normally renders 60 frames per second for requested animations.
const FPS_NORMAL_DURATION = 1000 / 60;
Expand Down
9 changes: 0 additions & 9 deletions packages/core/src/Text/Text.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ const styles: Record<string, CSSObject> = {
display: 'inline-block',
zIndex: 1
},
cloneNode: {
display: 'inline-block',
position: 'absolute',
zIndex: 0,
left: '0',
right: '0',
top: '0',
overflow: 'hidden'
},
blink: {
position: 'relative',
display: 'inline-block',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './setTextNodesEnteringContentLength';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './setTextNodesExitingContentLength';
1 change: 1 addition & 0 deletions packages/core/src/utils/textAnimations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './textAnimations';
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { RefObject, MutableRefObject } from 'react';
import { css } from '@emotion/css';
import { CSSObject, css } from '@emotion/css';
import { AnimatorRef } from '@arwes/animation';
import { Bleeps } from '@arwes/sounds';

import { walkTextNodes } from './utils/walkTextNodes';
import { setTextNodesEnteringContentLength } from './utils/setTextNodesEnteringContentLength';
import { setTextNodesExitingContentLength } from './utils/setTextNodesExitingContentLength';
import { styles } from './Text.styles';
import { walkTextNodes } from '../walkTextNodes';
import { setTextNodesEnteringContentLength } from '../setTextNodesEnteringContentLength';
import { setTextNodesExitingContentLength } from '../setTextNodesExitingContentLength';

type TextAnimationRefs = MutableRefObject<{
rootRef: RefObject<HTMLElement>
Expand All @@ -16,6 +15,20 @@ type TextAnimationRefs = MutableRefObject<{
animationFrame: MutableRefObject<number | null>
}>;

// TODO: Since these styles could be used simultaneously by many components,
// should these styles be memoized to improve performance?
const styles: Record<string, CSSObject> = {
cloneNode: {
display: 'inline-block',
position: 'absolute',
zIndex: 0,
left: '0',
right: '0',
top: '0',
overflow: 'hidden'
}
};

const stopTextAnimation = (animator: AnimatorRef, refs: TextAnimationRefs, bleeps: Bleeps): void => {
const {
rootRef,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils/walkTextNodes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './walkTextNodes';

0 comments on commit d89a624

Please sign in to comment.