0.1.8 โ€ข Published 1 year ago

@petros-g/react-native-switch v0.1.8

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

React Native Switch

๐Ÿš€ Fast, Smooth, and Performant Switch Component

  • ๐ŸŒ Universal: Same UI for both Android & iOS.
  • ๐ŸŽฌ Animated: Seamlessly animated transitions.
  • โšก Fast: Optimized for speed and responsiveness.
  • ๐Ÿ’ก Smooth: Provides a smooth user experience.
  • ๐Ÿ‹๏ธ Performant: High-performance rendering.
  • ๐Ÿ–ฑ๏ธ Gestures: Supports draggable interactions.
  • ๐Ÿงต Runs on UI Thread: Does not block the JavaScript thread.

Try it now! Enhance your app with a powerful React Native Switch component!

Installation

To be able to run this screen you need to run the following:

yarn add @petros-g/react-native-switch react-native-gesture-handler react-native-reanimated

or

npm install @petros-g/react-native-switch react-native-gesture-handler react-native-reanimated

Basic Usage

import React, { useState } from 'react';
import { View, Text } from 'react-native';
import Switch from 'react-native-animated-switch';

const App = () => {
  const [switchValue, setSwitchValue] = useState(false);

  return (
    <View>
      <Switch
          value={switchValue}
          onValueChange={setSwitchValue}
          enableDrag
          trackWidth={50}
          trackHeight={20}
          circleSize={25}
          circleOffset={3}
          circleActiveColor="white"
          trackActiveColor="#42adff"
          animationDuration={200}
        />
      <Text>The switch is {switchValue ? "On" : "Off"}</Text>
    </View>
  );
};

export default App;

Props

Prop NameTypeDefaultDescription
valuebooleanfalseCurrent state of the switch (on/off).
disabledbooleanfalseIf true, the switch will be unclickable.
trackWidthnumber95Width of the track.
trackHeightnumber45Height of the track.
circleSizenumber40Diameter of the circle.
activeTextstringnoneText displayed when the switch is active.
inactiveTextstringnoneText displayed when the switch is inactive.
animationDurationnumber600Duration of the switch animation in milliseconds. If 0 animations are disabled.
trackActiveColorstring'#3dcc63'Background color of the track when the switch is active.
trackInactiveColorstring'#bdbdbd'Background color of the track when the switch is inactive.
circleActiveColorstringwhiteColor of the circle when the switch is active.
circleInactiveColorstringwhiteColor of the circle when the switch is inactive.
circleOffsetnumber0Offset position of the circle.
textStyletextStylenoneCustom style for the active/inactive text.
trackStyleViewStylenoneCustom style for the track.
enableDragbooleanfalseIf true, enables dragging the switch instead of tapping.
circleSlidebooleanfalseIf true, enables sliding animation for the circle.
circleStyleViewStylenoneCustom style for the circle.
onValueChangefunctionnoneCallback function called when the switch value changes.
renderCircleChildReact.JSX.Element \| React.ReactNodenoneCustom content to render inside the circle.
0.1.8

1 year ago

0.1.6

1 year ago

0.1.7

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago