1.1.1 • Published 1 year ago

react-native-before-after-slider v1.1.1

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

react-native-before-after-slider

A lightweight and customizable React Native component for creating before and after image sliders using react-native-reanimated and react-native-gesture-handler.

Features

  • Smooth and performant animations using Reanimated 2
  • Highly customizable with styled-components
  • Easy to integrate into any React Native project

Installation

Using npm

First, install the necessary dependencies:

npm install react-native-reanimated react-native-gesture-handler styled-components

Then, install the react-native-before-after-slider package:

npm install react-native-before-after-slider

Using yarn

yarn add react-native-reanimated react-native-gesture-handler styled-components

Then, install the react-native-before-after-slider package:

yarn add react-native-before-after-slider

Make sure to follow the setup instructions for react-native-reanimated and react-native-gesture-handler if you haven't already.

Reanimated Setup

  1. Add Reanimated's Babel plugin to your babel.config.js:
module.exports = {
  presets: ["module:metro-react-native-babel-preset"],
  plugins: ["react-native-reanimated/plugin"],
};
  1. Wrap your app with Reanimated's GestureHandlerRootView:
import "react-native-gesture-handler";
import React from "react";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import { enableScreens } from "react-native-screens";
import MainScreen from "./screens/MainScreen";

enableScreens();

const Stack = createStackNavigator();

export default function App() {
  return (
    <GestureHandlerRootView style={{ flex: 1 }}>
      <NavigationContainer>
        <Stack.Navigator>
          <Stack.Screen name="Main" component={MainScreen} />
        </Stack.Navigator>
      </NavigationContainer>
    </GestureHandlerRootView>
  );
}

Usage

Here is a basic example of how to use the BeforeAfterSlider component:

import React from "react";
import { View } from "react-native";
import { BeforeAfterSlider } from "react-native-before-after-slider";

const beforeImage = require("./path-to-before-image.jpg");
const afterImage = require("./path-to-after-image.jpg");
const delimiterIcon = require("./path-to-icon.png");

const App = () => {
  return (
    <View style={{ flex: 1 }}>
      <BeforeAfterSlider
        beforeImage={beforeImage}
        afterImage={afterImage}
        handleWidth={30}
        handleColor="blue"
        delimiterIcon={delimiterIcon}
        delimiterIconStyles={{ width: 30, height: 30, tintColor: "red" }} // Customize the styles here
      />
    </View>
  );
};

export default App;

Props

BeforeAfterSlider Props

PropTypeDefaultDescription
beforeImageImageSourcePropTypeRequiredThe source for the before image.
afterImageImageSourcePropTypeRequiredThe source for the after image.
handleWidthnumber20The width of the slider handle.
handleColorstring'white'The color of the slider handle.
delimiterIconImageSourcePropTypeOptionalThe source for the delimiter icon inside the handle.
delimiterIconStylesobject{}Styles for the delimiter icon.

Contributing

Contributions are welcome! Please open an issue or submit a pull request to discuss any changes.

License

This project is licensed under the MIT License.

1.1.1

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago