Giter VIP home page Giter VIP logo

react-native-multistep-forms's Introduction

React Native Animated Multistep

installation

You can install this package with the following command:

yarn add react-native-multistep-forms

or

npm install react-native-multistep-forms

How to use

In the top level component add

import AnimatedFormView from 'react-native-multistep-forms'
import StepOne from './StepOne'
import StepTwo from './StepTwo'
import StepThree from './StepThree'

/* Define the steps  */

import Step1 from "./steps/step1";
import Step2 from "./steps/step2";
import Step3 from "./steps/step3";
import Step4 from "./steps/step4";

const allSteps = [
  { name: "step 1", component: Step1 },
  { name: "step 2", component: Step2 },
  { name: "step 3", component: Step3 },
  { name: "step 4", component: Step4 }
];

/* Define your class */
export default class App extends Component {

/* define the method to be called when you go on next step */

  onNext = () => {
    console.log("Next");
  };

  /* define the method to be called when you go on back step */

  onBack = () => {
    console.log("Back");
  };

/* define the method to be called when the wizard is finished */

  finish = finalState => {
    console.log(finalState);
  };

/* render MultiStep */
  render() {
    return (
      <View style={{ flex: 1 }}>
        <AnimatedFormView
          steps={allSteps}
          onFinish={this.finish}
          onBack={this.onBack}
          onNext={this.onNext}
          comeInOnNext="bounceInUp"
          OutOnNext="bounceOutDown"
          comeInOnBack="bounceInDown"
          OutOnBack="bounceOutUp"
        />
      </View>
    );
}
}

In the step

import React, { Component } from "react";
import { Text, View, TouchableOpacity } from "react-native";

import styles from "./styles";

class step1 extends Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  nextStep = () => {
    const { next, saveState } = this.props;
    // Save state for use in other steps
    saveState({ name: "samad" });

    // Go to next step
    next();
  };

  goBack() {
    const { back } = this.props;
    // Go to previous step
    back();
  }

  render() {
    return (
      <View style={[styles.container, styles.step1]}>
        <Text> Step 1 </Text>
        <View style={styles.btnContainer}>
          <TouchableOpacity onPress={this.nextStep}>
            <Text>Next</Text>
          </TouchableOpacity>
        </View>
      </View>
    );
  }
}

export default step1;

API

this.props.saveState({ key: value, key2: value2})

Use this to save state

this.props.getState()

Use this to get all the values saved with saveState so far. Retuns an object

this.props.next()

Use this to go to next step in the app.

this.props.back()

Use this to go to previos step in the app.

Props

Props Type Notes Required
steps Array array containing steps ✔️
onFinish function a function, which will run when all steps are finish
onNext function a function, which will run when you go on next step
onBack function a function, which will run when you go on back step
comeInOnNext String define you animation type when the component comes in on next, default is bounceInLeft
OutOnNext String define you animation type when the component goes out on next, default is bounceOutRight
comeInOnBack String define you animation type when the component comes in on back, default is bounceInRight
OutOnBack String define you animation type when the component goes out on next, default is bounceOutLeft

Note:

you can more animation and set-up animations by your self on react-native-animatable

Methods

Method Name Arguments Notes
next() none use this method to jump on next step
back() none use this method to go back on previos step
saveState() Object use this method to save your state, in order to get in other steps
getState() none use this method to get you saved state by saveState() method

react-native-multistep-forms's People

Contributors

trinadhkoya avatar lenigmacedo avatar

Stargazers

Jonathan Bavurhe avatar Pedro Henrico avatar Pavel Shum avatar Money Nguyen avatar

Watchers

James Cloos avatar  avatar

react-native-multistep-forms's Issues

Import error react-native-web

There's an import error on react native npm/yarn package, when you use it:
import AnimatedFormView from 'react-native-multistep-forms'
you get an error saying:

Unable to resolve "./src" from "node_modules/react-native-multistep-forms/index.js"

i fixed it by going to the package path and adding /Index to the import statement at the first line in index.js file inside the react-native-multistep-forms folder, hope this helps if anyone falls in the same error, regards!

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.