Code Monkey home page Code Monkey logo

react-native-slide-button's Introduction

react-native-slide-button

Customizable slide button component for React Native.

Installation

npm i --save react-native-slide-button

Usage

import { SlideButton, SlideDirection } from 'react-native-slide-button';

<View style={{backgroundColor: 'blue'}}>        <!-- Outer wrapper -->
  <SlideButton
   onSlideSuccess={this.onSlide.bind(this)}
   slideDirection={SlideDirection.LEFT}
   width={500}
   height={50}>
    <View style={height: 50, width: 500}>       <!-- Inner wrapper -->
      <Text style={styles.button}>Slide Button</Text>
    </View>
  </SlideButton>
</View>
  • Inner wrapper: Contents that will move when swiped. Eg: Button text, image etc.
  • Outer wrapper: Contents that are static and will not move. Eg: Button's background, other styles

API

SlideButton

Prop Type Default Description
width number Width of button
height number Height of button
slideDirection string SlideDirection.RIGHT Determines which direction to slide. Either SlideDirection.LEFT, SlideDirection.RIGHT, SlideDirection.BOTH.
onSlideSuccess function Fired when slide succeeds
onSlide function Fired on every movement. Distance of movement is passed as argument.
successfulSlidePercent number Percent of total button width needed to slide before movement is seen as a successful slide. Default is 40.

TODO

  • Implement onSlide prop to let components listen to slide events.
  • Write testcases.
  • Write separate convenience component tailored to meet the most common usecase; button with text inside.

react-native-slide-button's People

Contributors

anttimann avatar sreejithr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-slide-button's Issues

Timeout triggered after component was unmounted

I'm using slider in a modal that will be removed when onSlideSuccess is executed. Problem is that timeout with setState is triggered 1 second after that. In my case component doesn't exist anymore and React complain about it:

Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the SlideButton component.

That timeout could be cleared with clearTimeout or fixed in some other way when React component is unmounted.

dimensions package dependency

Hi, I got some npm errors when I went to use this package.

It seems like the dimensions npm package is being referenced, but isn't declared as a dependency in package.json. The dimensions library has a further dependency on fs, which doesn't appear to be available from a react native environment.

It looks like it would be safe to just remove this dependency completely, along with the SCREEN_WIDTH and SCREEN_HEIGHT properties.

Publish 1.3.0 to npm

Hello!

Thanks for the component. ๐Ÿ‘ I see that the latest version is 1.3.0 but npm has 1.2.1 listed as the last one. Necessary update?

(I'm still getting the Dimensions import error and I believe it's due to that. Will try to pull from Github directly for now).

Thank you!

onPress is not getting called Inner wrapper

onPress is not getting called Inner wrapper

example

            <SlideButton
                onSlideSuccess={this.stopRecording}
                slideDirection={SlideDirection.RIGHT}
                width={SCREEN_WIDTH}
                height={50}>
                    <Button title={'Click me'} onPress={()=>console.warn('clicked')} /> // not working
            </SlideButton>

onSlideSuccess is not getting called

here is my component

/**

import React, {Component} from 'react';
import {View, Text} from 'react-native';
import {SlideButton, SlideDirection} from './SlideButton';
import Button from './Button';

export default class App extends Component {
onSlide() {
console.log('clicked!!');
}

render() {
    return (
        <View
            style={{
                backgroundColor: 'rgba(0,0,0,0.8)',
                position: 'absolute',
                bottom: 0,
                height: 70,
                flex: 1,
                width: 500
            }}>
            <View
                style={{
                    backgroundColor: '#212121',
                    borderRadius: 20,
                    width: 350,
                    height: 50,
                    marginTop: 10,
                    marginLeft: 5
                }}
            >
                <SlideButton
                    onSlideSuccess={()=>{console.log('clicked!!')}}
                    width={500}
                    height={50}
                    successfulSlidePercent={40}

                >
                    <View style={{height: 50, width: 80, flexDirection: 'row'}}>
                        <Button>Pay 250</Button>

                    </View>
                </SlideButton>
                <Text style={{position: 'absolute', marginLeft: 150, color: 'white', marginTop: 10}}>Swipe
                    to continue>></Text>
            </View>
        </View>
    );
}

}

const styles = {
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
buttonOuter: {
marginTop: 20
},

button: {
    color: 'black',
    fontSize: 15,
    width: 100,
    borderRadius: 10,
    backgroundColor: 'white',
    fontWeight: 'bold'
}

};

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.