Coder Social home page Coder Social logo

ravanscafi / react-native-spotlight-tour Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stackbuilders/react-native-spotlight-tour

0.0 0.0 0.0 28.85 MB

A highly customizable tour feature with an awesome spotlight effect

Home Page: https://stackbuilders.github.io/react-native-spotlight-tour/

License: MIT License

JavaScript 2.45% Ruby 2.71% Objective-C 2.85% Kotlin 3.20% TypeScript 87.43% Objective-C++ 1.01% HTML 0.35%

react-native-spotlight-tour's Introduction

React Native Spotlight Tour

All Contributors

CI Release NPM version NPM downloads NPM license GitHub Release Date Known Vulnerabilities

react-native-spotlight-tour is a simple and intuitive library for React Native (Android, iOS, and Web compatible). It uses Floating UI under the hood in order to handle elements positioning, it re-exports all floating-ui middlewares to be configured in the tour. It also allows you to implement a highly customizable tour feature with an awesome spotlight effect. This library handles animations at the native level and is perfect for the following:

  • Guiding users on how to use your application
  • Showing an introduction to your users

spotlight-bounce-gif spotlight-fade-gif spotlight-slide-gif spotlight-rect-gif

Requirements

Install

With npm:

npm install react-native-spotlight-tour

With yarn:

yarn add react-native-spotlight-tour

๐Ÿšจ Breaking changes: v2 to v3

This major update brings a few fixes, some great new features, and some breaking changes. These are some highlight you'll need to consider while upgrading from v2 to v3:

  • The package has been renamed from @stackbuilders/react-native-spotlight-tour to just react-native-spotlight-tour
    • Don't worry, this library is still developed and maintained by the Stack Builders Inc. team!
    • Remove the former package from your dependencies and use the command described in the Install section
    • Rename any import from the previous name to use just react-native-spotlight-tour instead
  • Tooltip positioning was refactored
    • Props related to the tooltip position were removed from SpotlightTourProvider and the TourStep object.
      • Both Align and Position enums were removed
      • Both alignTo and position props were removed
    • We now delegate the positioning to FloatingUI, so you can use the floatingProps prop to configure its global behavior or granularly on each step.
    • Middleware functions are re-exported from @floating-ui/react-native to react-native-spotlight-tour.
    • You may not need to do changes on floatingProps since the default behavior is very similar to v2

Usage

To be able to use the tour, you'll need to wrap everything around a SpotlightTourProvider. This provider component will also give you access to a hook to retrieve the SpotlightTour context, which gives information and fine control over the tour.

import { Button, Text, View } from "react-native";
import {
  AttachStep,
  SpotlightTourProvider,
  TourStep,
  flip,
  offset,
  shift,
} from "react-native-spotlight-tour";

const mySteps: TourStep[] = [
  // ...setup the steps
];

return (
  <SpotlightTourProvider
    steps={mySteps}
    overlayColor={"gray"}
    overlayOpacity={0.36}
    // This configurations will apply to all steps
    floatingProps={{
      middleware:[offset(5), shift(), flip()],
      placement: "bottom",
    }}
  >
    {({ start }) => (
      <>
        <Button title="Start" onPress={start} />

        <View>
          <AttachStep index={0}>
            <Text>Introduction</Text>
          </AttachStep>

          <Text>
            This is an example using the spotlight-tour library.
            Press the Start button to see it in action.
          </Text>
        </View>

        <View>
          <AttachStep index={1}>
            <Text>Documentation</Text>
          </AttachStep>
          <DescriptionText>
            Please, read the documentation before installing.
          </DescriptionText>
        </View>
      </>
    )};
  </SpotlightTourProvider>
);

Floating-UI props can be defined in the <SpotlightTourProvider/> and this will be applied to all tour steps. If no configuration is given it will take a default with the next values: middlewares: [flip(), offset(4), shift()] and placement: "bottom".

The tour requires an array of steps to be configured, which will map directly to each <AttachStep /> index. Bellow is a complete example of a TourStep array:

import { Button, Text, View } from "react-native";
import {
  Align,
  TourStep,
  useSpotlightTour
} from "react-native-spotlight-tour";

const mySteps: TourStep[] = [{
  // This configurations will apply just for this step
  floatingProps:{
    middleware: [offset(0), shift(), flip()],
    placement: "right",
  },
  render: ({ next }) => (
    <View>
      <Text>This is the first step of tour!</Text>
      <Button title="Next" onPress={next} />
    </View>
  )
}, {
  before: () => {
    return DataService.fetchData()
      .then(setData);
  },
  render: () => {
    // You can also use the hook inside the step component!
    const { previous, stop } = useSpotlightTour();

    return (
      <View>
        <Text>This is the first step of tour!</Text>
        <Button title="Previous" onPress={previous} />
        <Button title="Stop" onPress={stop} />
      </View>
    );
  }
}];

Floating-UI props can be defined in each step for a custom configuration. If no floating configuration is specified in the step it will take the one defined in the <SpotlightTourProvider/>.

You can also find a complete example here.

Built-in Helper Components

You can take advantage of the built-in customizable components. For example, our TourBox component can be used as a tooltip container for each step.

import { Text } from "react-native";
import { Align, TourBox, TourStep } from "react-native-spotlight-tour";

const tourSteps: TourStep[] = [{
    render: props => (
      <TourBox
        title="Tour: Customization"
        titleStyle={{
          fontFamily: 'Roboto',
          color: '#90EE90',
          fontWeight: 'bold'
        }}
        backText="Previous"
        nextText="Next"
        {...props}
      >
        <Text>
          {"This is the third step of tour example.\n"}
          {"If you want to go to the next step, please press "}<BoldText>{"Next.\n"}</BoldText>
          {"If you want to go to the previous step, press "}<BoldText>{"Previous.\n"}</BoldText>
        </Text>
      </TourBox>
    ),
  }];

Tour customization

The SpotlightTourProvider also allows you to customize the overlay through the overlayColor and overlayOpacity props.

import { AttachStep, SpotlightTourProvider, TourStep } from "react-native-spotlight-tour";

const mySteps: TourStep[] = [
  // ...
];

return (
  <SpotlightTourProvider steps={mySteps} overlayColor={"gray"} overlayOpacity={0.36}>
    {({ start }) => (
      <>
      {/* ... */}
      </>
    )};
  </SpotlightTourProvider>
);

Besides above customizations, you can also define the transition animation see motion and the behavior when the user presses the backdrop see onBackdropPress. Otherwise if you wish to make them different for an specific step you could override this properties in the TourStep configuration.

import { Button, Text, View } from "react-native";
import {
  Align
  AttachStep,
  SpotlightTourProvider,
  TourStep,
  TourBox
} from "react-native-spotlight-tour";

const tourSteps: TourStep[] = [{
    motion: "fade",
    onBackdropPress: "stop",
    render: props => (
      <TourBox
        title="Tour: Customization"
        backText="Previous"
        nextText="Next"
        {...props}
      >
        <Text>
          {"This is the first step of tour example.\n"}
          {"If you want to go to the next step, please press "}<BoldText>{"Next.\n"}</BoldText>
          {"If you want to go to the previous step, press "}<BoldText>{"Previous.\n"}</BoldText>
        </Text>
      </TourBox>
    ),
  }];

return (
  <SpotlightTourProvider
    steps={tourSteps}
    overlayColor={"gray"}
    overlayOpacity={0.36}
    onBackdropPress="continue"
    motion="bounce"
  >
    {({ start }) => (
      <>
      <Button title="Start" onPress={start} />

       <View>
          <AttachStep index={0}>
            <Text>Introduction</Text>
          </AttachStep>

          <Text>
            This is an example using the spotlight-tour library.
            Press the Start button to see it in action.
          </Text>
        </View>
      </>
    )};
  </SpotlightTourProvider>
);

API Reference

To view all the types, options, and props, please check the complete API Reference documentation.

Contributing

Do you want to contribute to this project? Please take a look at our contributing guideline to know how you can help us build it.


Stack Builders Check out our libraries | Join our team

Contributors โœจ

Thanks goes to these wonderful people (emoji key):

Jose Luis Leon
Jose Luis Leon

๐Ÿ’ป โš ๏ธ ๐Ÿ“– ๐Ÿš‡ ๐Ÿšง ๐Ÿ‘€
Sebastiรกn Estrella
Sebastiรกn Estrella

๐Ÿš‡
Angie Rojas
Angie Rojas

๐Ÿ’ป ๐Ÿ“–
Fernanda Andrade
Fernanda Andrade

๐Ÿš‡ โš ๏ธ
Steven Cuasqui
Steven Cuasqui

๐Ÿ“–
Alexander Mejรญa
Alexander Mejรญa

๐Ÿ’ป
Carolina Lรณpez
Carolina Lรณpez

๐Ÿ’ป ๐Ÿ’ก
cmarcag
cmarcag

โš ๏ธ
Ricardo Arrobo
Ricardo Arrobo

๐Ÿ’ป ๐Ÿ“–
Mohammad Abkal
Mohammad Abkal

๐Ÿ“–
Alexander Pokhil
Alexander Pokhil

๐Ÿ’ป
Alejandro Vivanco
Alejandro Vivanco

๐Ÿ’ป ๐Ÿ‘€
Wellington Mendoza
Wellington Mendoza

๐Ÿ‘€
Christian Samaniego
Christian Samaniego

๐Ÿ‘€
beKool.sh
beKool.sh

๐Ÿ“–
Add your contributions

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT, see the LICENSE file.

react-native-spotlight-tour's People

Contributors

joselion avatar allcontributors[bot] avatar krarrobo1 avatar dependabot[bot] avatar alejo0o avatar rojastob avatar flandrade avatar sestrella avatar alex0jk avatar lopenchi avatar franzgb avatar ravanscafi avatar stevencuasqui avatar bekoool avatar christianmarca 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.