0.1.5 • Published 1 year ago

@ilz5753/react-native-time-line v0.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@ilz5753/react-native-time-line

A customizable and animated timeline component for React Native applications.

Demo

https://github.com/ilz5753/react-native-time-line/assets/87062381/3796bc4c-eee1-4f56-8e08-f3b5427b4a0e

Note

The react-native-time-line package relies on react-native-reanimated to provide smooth animations. These dependencies must be installed and properly configured in your React Native project for the timeline component to function correctly.

Installation

npm install @ilz5753/react-native-time-line
# or yarn
yarn add @ilz5753/react-native-time-line
# or bun
bun add @ilz5753/react-native-time-line

Usage

import TimeLine, {
  ITimeLineItem,
  TTimeLineAnimatedComponentProps,
} from "@ilz5753/react-native-time-line";

function Node({
  animatedValue,
  sharedProps = {},
  goto,
  activeIndex,
  isActive,
}: TTimeLineAnimatedComponentProps) {
  return (
    <View>
      <Text>Hello from Node</Text>
    </View>
  );
}
function Label({
  animatedValue,
  sharedProps = {},
  goto,
  activeIndex,
  isActive,
}: TTimeLineAnimatedComponentProps) {
  return (
    <View>
      <Text>Hello from Label</Text>
    </View>
  );
}
function Line({
  animatedValue,
  sharedProps = {},
  goto,
  activeIndex,
  isActive,
}: TTimeLineAnimatedComponentProps) {
  return (
    <View>
      <Text>Hello from Line</Text>
    </View>
  );
}
function Render({
  animatedValue,
  sharedProps = {},
  goto,
  activeIndex,
  isActive,
}: TTimeLineAnimatedComponentProps) {
  return (
    <View>
      <Text>Hello from Render</Text>
    </View>
  );
}

const timeLines: ITimeLineItem[] = [
  {
    id: "1",
    Node,
    Label,
    Line,
    Render,
    // disabled: true,
  },
  // ...
];

function App() {
  return (
    <TimeLine
      items={timeLines}
      delayBetween={200}
      duration={500}
      initialIndex={0}
      isRTL={false}
      spaceOut={50}
      gapHor={20}
      gapVert={20}
    />
  );
}

TimeLine Props

PropTypeDefaultDescription
itemsITimeLineItem[]An array of timeline items. Each item consists of an id, a Node component, a Line component, a Label component, and an optional disabled flag.
delayBetweennumber0The delay between the end of the previous animation and the start of the next one.
durationnumber300The duration of each animation.
initialIndexnumber0The index of the initially active item.
isRTLbooleanfalseDetermines the direction of the timeline. Set to true for right-to-left languages.
spaceOutnumber20The padding space arround component.
gapHornumber10The horizontal gap between the node-label and line-render components.
gapVertnumber10The vertical gap between the node-line and label-render components.
sharedPropsobjectAny additional props that should be shared among the animated components.

TimeLineItem Props

PropTypeDescription
idstringA unique identifier for the timeline item.
NodeTTimeLineAnimatedComponentA component representing the visual element (node) in the timeline.
LabelTTimeLineAnimatedComponentA component representing the label for the timeline item.
LineTTimeLineAnimatedComponentA component representing the line connecting the nodes in the timeline.
RenderTTimeLineAnimatedComponentA component representing the time line item Render.
disabledbooleanWhen true, the item is disabled and not interactive.

Animated Component Props

The animated components (Node, Line, Label, and Render) receive the following props:

PropTypeDescription
animatedValueSharedValueThe current animated value (0-1).
activeIndexnumberThe index of the currently active item.
isActivebooleanboolean flag indicates item is active or not.
sharedPropsobjectAny additional props passed to the component through the sharedProps prop of the TimeLine component.
goto(index: number)functionManually move the timeline to the specified index.

Methods

The TimeLine component provides the following methods via the ref prop:

MethodDescription
goto(index: number)Manually move the timeline to the specified index.

License

This package is licensed under the MIT license.


Made with create-react-native-library

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago