0.0.9 • Published 3 years ago

@nghinv/react-native-app-tour v0.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@nghinv/react-native-app-tour

React Native App Tour Library


CircleCI Version MIT License

Installation

yarn add @nghinv/react-native-app-tour

or

npm install @nghinv/react-native-app-tour
yarn add react-native-gesture-handler react-native-reanimated react-native-animateable-text react-native-svg

IOS run cd ios && pod install

Usage

  1. Wrapper AppTourProvider in the Root Component
import { AppTourProvider } from '@nghinv/react-native-app-tour';

...
render() {
  return (
    <AppTourProvider
      sceneIndex={0}
      scenes={[
        [
          { 
            id: '1',
            nextDelay: 50,
            pressToNext: true,
            enablePressNode: true,
            prevDisable: true,
          }, 
          { id: '2' },
        ],
        [
          { id: '2' }, 
          { id: '1' },
        ],
      ]}
      options={{
        buttonTitleColor: {
          next: 'red',
          prev: 'orange',
        },
        borderRadius: 5,
        colorNodeOnPress: 'tomato',
        ...otherOptionsProps,
      }}
    >
      <Root />
    </AppTourProvider>
  )
}
...
  1. Use AppTourStep
import React, { useEffect } from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import { AppTourStep, useAppTour, AppTour, useEvent } from '@nghinv/react-native-app-tour';

export function App() {
  const { addEventListener, removeEventListener } = useEvent();

  useEffect(() => {
    // Listener AppTour Event
    const id = addEventListener('AppTourEvent', (event) => {
      console.log('AppTourEvent', event.name, event.node?.id);

    return () => {
      removeEventListener(id);
    };
  }, []);

  const onStartAppTour = () => {
    // Start show AppTour
    // Use AppTour.start(step) to jump to step
    AppTour.start();
  };

  return (
    <View style={{flex: 1}}>
      <View style={styles.viewTitle}>
        <AppTourStep
          id='1'
          title='Text welcome'
          describe='This is welcome title app'
        >
          <Text>
            {'Welcome to the demo of\n"React Native AppTour"'}
          </Text>
        </AppTourStep>
      </View>
      <View style={styles.viewAvatar}>
        <AppTourStep
          id='2'
          title='avatar'
          describe='Press here to change your avatar'
        >
          <Image 
            style={styles.avatar} 
            source={require('../assets/avatar.jpg')} 
            resizeMode='cover' 
          />
        </AppTourStep>
      </View>

      <TouchableOpacity 
        onPress={onStartAppTour} 
        style={styles.button}
      >
        <Text>Start App Tour</Text>
      </TouchableOpacity>
    </View>
  )
}

Property

AppTourProvider

PropertyTypeDefaultDescription
sceneIndexnumber0Index of scenes
scenesArray<Array<SceneProperty>>[]Index of scenes
optionsOptionsPropertyundefinedCustom app tour props
  • SceneProperty
PropertyTypeDefaultDescription
idstringID of AppTourStep
nextDelaynumberundefinedunit: ms
prevDelaynumberundefinedunit: ms
pressToNextbooleanfalsePress to Element to next step
enablePressNodebooleanfalse
nextDisablebooleanfalsedisable next step button
prevDisablebooleanfalsedisable prev step button
  • OptionsProperty
PropertyTypeDefaultDescription
nativeModalbooleanfalseUse Modal from react native
backdropOpacitynumber0.8value from 0 to 1
backgroundColorstringundefinedbackgroundColor of content
borderRadiusnumber5borderRadius of content
titleShowbooleantrue
titleStyleTextStyleundefined
describeStyleTextStyleundefined
stepShowbooleantrue
stepTitleColorstringwhite
stepBackgroundColorstringgreen
pathAnimatedbooleantrueDefault set pathAnimated = false on Android
stepHeightnumber20
triangleHeightnumber8
colorNodeOnPressstringrgba(255, 255, 255, 0.8)
backAndroidToSkipbooleanfalseEnable skip AppTour on backAndroid press
debugbooleanfalseShow debug
buttonTitleButtonTitlePropsundefined
buttonTitleColorButtonTitleColorPropsundefined
  • ButtonTitleProps
PropertyTypeDefaultDescription
skipstringSkip
prevstringPrevious
nextstringNext
finishstringFinish
  • ButtonTitleColorProps
PropertyTypeDefaultDescription
skipstringgreen
prevstringgreen
nextstringgreen
finishstringgreen

AppTourStep

PropertyTypeDefaultDescription
idstringID of Element
titlestring
describestring
maskTypecircle \| rectrect
scrollToAnimated.SharedValue<ScrollToXY>
  • ScrollToXY
PropertyTypeDefaultDescription
xnumber
ynumber

AppTour

PropertyTypeDefaultDescription
start(step?: number) => voidStart show AppTour
stop(cb?: () => void) => voidStop AppTour
nextStep() => voidNext step AppTour
preStep() => voidPrevious step AppTour
currentStep() => numberGet current step

useAppTour

PropertyTypeDefaultDescription
setSceneIndexReact.Dispatch<React.SetStateAction<number>>Set scenes index

useEvent

PropertyTypeDefaultDescription
addEventListener(eventName: 'AppTourEvent', callback: (data: EventData) => void) => string
removeEventListener(id: string) => boolean
  • EventData
PropertyTypeDefaultDescription
nameonStart\|onStop\|onFinish\|onSkip\|onNext\|onPrevious\| onPressNode
stepnumber
nodeNodeType
sceneSceneType

Credits

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago