Code Monkey home page Code Monkey logo

react-native-slider-button's Introduction

react-native-slider-button

Slider button inspired by the slide to unlock widget with an optional animation manipulating the text's transparency. Of course, both the animation duration and text can be customized too.

Demo

Slider button demo

A (hopefully simple enough) demo project is available too.

Add it to your project

Run npm install --save react-native-slider-button

var SliderButton = require("react-native-slider-button");

Basic usage

<SliderButton
	text={"Slide to start!"}
	textAnimated={true}
	minimumValue={0} maximumValue={100} value={0}
	minimumTrackTintColor={"rgba(0,0,0,0)"}
	maximumTrackTintColor={"rgba(0,0,0,0)"}
	onTrigger={this.onBurnOffStart}/>

Using a custom style

I strongly recommend creating a separate file holding the style definitions overwriting the following three definitons:

text describes the appearance of the text centered in the slider and supports all options of React Native's <Text> component. For instance, you can change the text colour and the font size, as shown below:

text:
{
	fontSize: 18,
	color: "#FFFFFF"
}

slider is responsible for customizing the slider. In the following example I am modifying the margin on the left and right side. Be cautios, that it is adviced to set flex to 1 too or to specify a custom width.

slider:
{
	flex: 1,
	marginLeft: 26,
	marginRight: 26
}

The slider's border can be adapted using by creating a custom object named sliderBorder, as shown below.

sliderBorder:
{
	borderWidth: 2,
	borderRadius: 20,
	borderColor: "#FFFFFF"
}

Please note that both slider as well as sliderBorder support all attributes of React Native's slider component. A complete example can be found in examples/SliderButtonStyle.js.

The custom style object can be applied to the component using the stylesheet property (see section Properties).

Properties

text (string) – The text to be displayed within the slider.

textAnimated (boolean) – Should the text change it's opacity from 1 to 0.5 and vice versa. The animation is endlessly repeated.

sliderCompletionValue (number) – Value the thumb needs to be moved beyond in order to trigger the event associated with the slider. For instance, if your minimum value is 0, your maximum value is 100 and this value is set to 89 the user has to move the thumb beyond 89 per cent of the slider's length.

onTrigger (function) – Callback invoked when the user moves the thumb beyond the completion value. No further parameters are passed to the callback method.

stylesheet (object) – Custom style for the slider button, as described in the custom style section.

resetAfterAction (boolean) – If this value is set to false the slider will remain in its position after the action is triggered. Otherwise, the slider will "jump" back to its initial value.

rightToLeft (boolean) (default: false) - This value allows to control the direction the user has to slide. In case it is set to true the user has to slide from 100 (right) to (100 - the value of sliderCompletionValue).

minimumValue (number) – The minimum allowed value (see React Native's documentation).

maximumValue (number) – The maximum allowed value (see React Native's documentation).

value (number) – The initial value (see React Native's documentation).

minimumTrackTintColor (string) – The track colour left to the thumb (see React Native's documentation).

maximumTrackTintColor (string) – The track colour right to the thumb (see React Native's documentation).

License

This project is MIT licensed. If there is a specific demand I am willing to change the license.

react-native-slider-button's People

Contributors

agents avatar

Watchers

David van Zyl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.