Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions examples/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ const BaseExample: React.FunctionComponent = (): JSX.Element => (
</Section>
);

const DirectionExample: React.FunctionComponent = (): JSX.Element => (
<Section>
<Title>Default</Title>
<Example>
<TextLoop direction="down">
<span>Trade faster</span>
<span>Increase sales</span>
<span>Stock winners</span>
</TextLoop>{" "}
and{" "}
<TextLoop direction="up">
<span>be awesome</span>
<span>win big</span>
<span>live the dream</span>
</TextLoop>
</Example>
</Section>
);

const FastExample: React.FunctionComponent = (): JSX.Element => (
<Section>
<Title>Fast transition</Title>
Expand Down Expand Up @@ -178,6 +197,7 @@ const StaggeredExample: React.FunctionComponent = (): JSX.Element => (

enum Sections {
Base,
Direction,
Fast,
Smooth,
Variable,
Expand All @@ -191,6 +211,7 @@ const App: React.FunctionComponent = (): JSX.Element => {

const mapSectionToComponent = {
[Sections.Base]: BaseExample,
[Sections.Direction]: DirectionExample,
[Sections.Fast]: FastExample,
[Sections.Smooth]: SmoothExample,
[Sections.Variable]: VariableExample,
Expand All @@ -210,6 +231,7 @@ const App: React.FunctionComponent = (): JSX.Element => {
}}
>
<option value={Sections.Base}>Default</option>
<option value={Sections.Direction}>Direction</option>
<option value={Sections.Fast}>Fast</option>
<option value={Sections.Smooth}>Smooth</option>
<option value={Sections.Variable}>Variable</option>
Expand Down
8 changes: 6 additions & 2 deletions src/components/TextLoop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Props = {
noWrap: boolean;
className?: string;
onChange?: Function;
direction: "up" | "down";
};

type State = {
Expand Down Expand Up @@ -50,6 +51,7 @@ class TextLoop extends React.PureComponent<Props, State> {
fade: true,
mask: false,
noWrap: true,
direction: "up",
};

constructor(props: Props) {
Expand Down Expand Up @@ -136,19 +138,21 @@ class TextLoop extends React.PureComponent<Props, State> {
willLeave = (): { opacity: OpaqueConfig; translate: OpaqueConfig } => {
const { height } = this.getDimensions();

const dirAdjust = this.props.direction === "up" ? -1 : 1;
return {
opacity: spring(this.getOpacity(), this.props.springConfig),
translate: spring(-height, this.props.springConfig),
translate: spring(height * dirAdjust, this.props.springConfig),
};
};

// Fade in animation
willEnter = (): { opacity: 0 | 1; translate: number } => {
const { height } = this.getDimensions();

const dirAdjust = this.props.direction === "up" ? 1 : -1;
return {
opacity: this.getOpacity(),
translate: height,
translate: height * dirAdjust,
};
};

Expand Down