0.0.4 • Published 5 years ago

draggableview v0.0.4

Weekly downloads
29
License
MIT
Repository
github
Last release
5 years ago

react-native-draggableview

npm (scoped)

Alt Text

Alt Text

Installation

Installation can be done through npm or yarn:

npm i draggableview --save
yarn add draggableview

Basic Usage

import * as React from 'react';
import { StyleSheet, View } from 'react-native';
import DraggableView from 'draggableview';

export default class App extends React.Component {
  render() {
    return (
      <DraggableView
        style={styles.container}
        backgroundComponent={<View style={styles.view} />}
      />
    );
  }
}

const styles = StyleSheet.create({
  container: {
    backgroundColor: 'white',
    flex: 1,
  },
  view: {
    flex: 1,
    backgroundColor: 'red',
  },
});

API

Props

PropTypeDescription
styleViewStyleStyles of DraggableView.
childrenComponentThe component to render on the DraggableView.
backgroundComponentComponentThe component to render behind the DraggableView.
offsetnumberIf you want to give to DraggableView an offset once it's fully dragged. This offset will be positioned based on the drag direction.
directionstringCan be either "up" or "down". This determines the drag direction. Default is "down".
thresholdnumberThe minimum drag distance required to trigger the drag animation.

Methods WIP, might change.

Use ref to access these methods.

MethodParameterDescription
moveToNormalvoidMoves DraggableView to it's default position
moveToBottomvoidMoves DraggableView to it's bottom position
moveToTopvoidMoves DraggableView to it's top position

Examples

1.

Alt Text

import * as React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import DraggableView from 'draggableview';

export default class App extends React.Component {
  render() {
    return (
      <DraggableView
        style={styles.container}
        backgroundComponent={<View style={styles.view} />}
        offset={85}
        threshold={300}
        direction="up"
      >
        <View style={styles.innerView}>
          <Text>Drag me up!!</Text>
        </View>
      </DraggaleView>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    backgroundColor: 'white',
    flex: 1,
    marginBottom: 35,
  },
  view: {
    flex: 1,
    backgroundColor: 'red',
  },
  innerView: {
    flex: 1,
    padding: 15,
    justifyContent: 'flex-end',
    alignItems: 'center',
  },
});

2.

Alt Text

import * as React from 'react';
import { StyleSheet, View, Text } from 'react-native';

import DraggableView from 'draggableview';

export default class App extends React.Component {
  render() {
    return (
      <DraggableView
        style={styles.container}
        backgroundComponent={<View style={styles.view} />}
        offset={40}
        threshold={300}
      >
        <View style={styles.innerView}>
          <Text>Drag me down!!</Text>
        </View>
      </DraggaleView>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    backgroundColor: 'white',
    flex: 1,
  },
  view: {
    flex: 1,
    backgroundColor: 'red',
  },
  innerView: {
    flex: 1,
    padding: 20,
    alignItems: 'center',
  },
});

License

MIT.