2.3.0 • Published 7 months ago

react-native-switch-component v2.3.0

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

Switch Component

The Switch component is compatible with both iOS and Android. The steps to include it in your React Native project are outlined below.

Dependencies

To use the Switch component, you need to install the following dependencies:

  • react-native-reanimated: For animations and transitions in the Switch.
  • react-native: The core library for building your React Native app.

You can install these dependencies using npm or yarn.

UI and Using

Switch Component Video

Get Started

Follow these steps to include the Switch component in your project:

  1. Install the necessary dependency:

First, you need to add the react-native-switch-component package to your project. This package helps you manage animations.

npm i react-native-switch-component

or

yarn add react-native-switch-component
  1. Usage with Default Values:
const App = () => {
  return (
    <Switch />
  );
};
export default App;
  1. Usage with Customized Values:

const App = () => {
  return (
    <Switch
      activeIconColor="white"
      activeBgColor="#02D95A"
      passiveIconColor="white"
      passiveBgColor="lightgray"
      dumping={20}
      startPosition={0}
      endPosition={20}
    />
  );
};
export default App;

Customizable Switch Component

This Switch component allows for extensive customization, including the ability to modify icon colors, background colors, animations, and more. You can also personalize its appearance with additional styling properties for the Switch, container, and inner box.

Props

PropertyTypeDefaultDescription
activeIconColorstringwhiteDefines the color of the icon when the Switch is active.
activeBgColorstring#02D95ADefines the background color when the Switch is active.
passiveIconColorstringwhiteDefines the color of the icon when the Switch is passive.
passiveBgColorstringlightgrayDefines the background color when the Switch is passive.
dumpingnumber20Controls the speed (slowing down) of the animation.
startPositionnumber0Defines the starting position of the Switch's movement.
endPositionnumber20Defines the ending position of the Switch's movement.
styleStyleProp<ViewStyle>undefinedAllows customization of the Switch component's overall style.
styleBoxContainerStyleProp<ViewStyle>undefinedEnables customization of the container's style surrounding the Switch.
styleBoxStyleProp<ViewStyle>undefinedAllows you to style the inner box or the toggle itself within the Switch.

Customization

With the new style, styleBoxContainer, and styleBox properties, you can fully customize the appearance of the Switch component, its container, and the inner box, allowing it to fit seamlessly into your app's design.

Example

<Switch 
  activeIconColor="blue"
  activeBgColor="green"
  passiveIconColor="gray"
  passiveBgColor="lightgray"
  dumping={20}
  startPosition={0}
  endPosition={20}
  style={{ flex:1, justifyContent: 'center', alignItems: 'center' }}
  styleBoxContainer={{ width: 20, height: 20 }}
  styleBox={{ borderRadius: 10 }}
/>
2.3.0

7 months ago

2.2.0

7 months ago

2.1.0

7 months ago

2.0.0

7 months ago

1.24.0

7 months ago

1.23.0

7 months ago

1.22.0

7 months ago

1.21.0

7 months ago

1.20.0

7 months ago

1.19.0

7 months ago

1.18.0

7 months ago

1.17.0

7 months ago

1.16.0

7 months ago

1.15.0

7 months ago

1.14.0

7 months ago

1.13.0

7 months ago

1.12.0

7 months ago

1.11.0

7 months ago

1.10.0

7 months ago

1.9.0

7 months ago

1.8.0

7 months ago

1.7.0

7 months ago

1.6.0

7 months ago

1.5.0

7 months ago

1.4.0

7 months ago

1.3.0

7 months ago

1.2.0

7 months ago

1.1.0

7 months ago

1.0.0

7 months ago