Gathering detailed insights and metrics for levy-rn-tourguide
Gathering detailed insights and metrics for levy-rn-tourguide
Gathering detailed insights and metrics for levy-rn-tourguide
Gathering detailed insights and metrics for levy-rn-tourguide
🚩Make an interactive step by step tour guide for your react-native app (a rewrite of react-native-copilot)
npm install levy-rn-tourguide
Typescript
Module System
Node Version
NPM Version
TypeScript (97.58%)
JavaScript (2.42%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
NOASSERTION License
1 Stars
377 Commits
6 Branches
1 Contributors
Updated on Apr 04, 2023
Latest Version
1.1.12
Package Id
levy-rn-tourguide@1.1.12
Unpacked Size
71.60 kB
Size
17.45 kB
File Count
41
NPM Version
6.14.17
Node Version
14.19.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
30
A flexible tourguide for your react native app!
🎉 Webable 🎉
(a rewriting of react-native-copilot)
This is a fork of https://github.com/xcarpentier/rn-tourguide
with extra features.
yarn add rn-tourguide
yarn add react-native-svg
react-native link react-native-svg
If you are using Expo:
expo install react-native-svg
1import { 2 TourGuideProvider, // Main provider 3 TourGuideZone, // Main wrapper of highlight component 4 TourGuideZoneByPosition, // Component to use mask on overlay (ie, position absolute) 5 useTourGuideController, // hook to start, etc. 6} from 'rn-tourguide' 7 8// Add <TourGuideProvider/> at the root of you app! 9function App() { 10 return ( 11 <TourGuideProvider {...{ borderRadius: 16 }}> 12 <AppContent /> 13 </TourGuideProvider> 14 ) 15} 16 17const AppContent = () => { 18 const iconProps = { size: 40, color: '#888' } 19 20 // Use Hooks to control! 21 const { 22 canStart, // a boolean indicate if you can start tour guide 23 start, // a function to start the tourguide 24 stop, // a function to stopping it 25 eventEmitter, // an object for listening some events 26 } = useTourGuideController() 27 28 // Can start at mount 🎉 29 // you need to wait until everything is registered 😁 30 React.useEffect(() => { 31 if (canStart) { 32 // 👈 test if you can start otherwise nothing will happen 33 start() 34 } 35 }, [canStart]) // 👈 don't miss it! 36 37 const handleOnStart = () => console.log('start') 38 const handleOnStop = () => console.log('stop') 39 const handleOnStepChange = () => console.log(`stepChange`) 40 41 React.useEffect(() => { 42 eventEmitter.on('start', handleOnStart) 43 eventEmitter.on('stop', handleOnStop) 44 eventEmitter.on('stepChange', handleOnStepChange) 45 46 return () => { 47 eventEmitter.off('start', handleOnStart) 48 eventEmitter.off('stop', handleOnStop) 49 eventEmitter.off('stepChange', handleOnStepChange) 50 } 51 }, []) 52 53 return ( 54 <View style={styles.container}> 55 {/* 56 57 Use TourGuideZone only to wrap your component 58 59 */} 60 <TourGuideZone 61 zone={2} 62 text={'A react-native-copilot remastered! 🎉'} 63 borderRadius={16} 64 > 65 <Text style={styles.title}> 66 {'Welcome to the demo of\n"rn-tourguide"'} 67 </Text> 68 </TourGuideZone> 69 <View style={styles.middleView}> 70 <TouchableOpacity style={styles.button} onPress={() => start()}> 71 <Text style={styles.buttonText}>START THE TUTORIAL!</Text> 72 </TouchableOpacity> 73 74 <TourGuideZone zone={3} shape={'rectangle_and_keep'}> 75 <TouchableOpacity style={styles.button} onPress={() => start(4)}> 76 <Text style={styles.buttonText}>Step 4</Text> 77 </TouchableOpacity> 78 </TourGuideZone> 79 <TouchableOpacity style={styles.button} onPress={() => start(2)}> 80 <Text style={styles.buttonText}>Step 2</Text> 81 </TouchableOpacity> 82 <TouchableOpacity style={styles.button} onPress={stop}> 83 <Text style={styles.buttonText}>Stop</Text> 84 </TouchableOpacity> 85 <TourGuideZone 86 zone={1} 87 shape='circle' 88 text={'With animated SVG morphing with awesome flubber 🍮💯'} 89 > 90 <Image source={{ uri }} style={styles.profilePhoto} /> 91 </TourGuideZone> 92 </View> 93 <View style={styles.row}> 94 <TourGuideZone zone={4} shape={'circle'}> 95 <Ionicons name='ios-contact' {...iconProps} /> 96 </TourGuideZone> 97 <Ionicons name='ios-chatbubbles' {...iconProps} /> 98 <Ionicons name='ios-globe' {...iconProps} /> 99 <TourGuideZone zone={5}> 100 <Ionicons name='ios-navigate' {...iconProps} /> 101 </TourGuideZone> 102 <TourGuideZone zone={6} shape={'circle'}> 103 <Ionicons name='ios-rainy' {...iconProps} /> 104 </TourGuideZone> 105 <TourGuideZoneByPosition 106 zone={7} 107 shape={'circle'} 108 isTourGuide 109 bottom={30} 110 left={35} 111 width={300} 112 height={300} 113 /> 114 </View> 115 </View> 116 ) 117}
TourGuide
props:
1interface TourGuideZoneProps { 2 zone: number // A positive number indicating the order of the step in the entire walkthrough. 3 tourKey?: string // A string indicating which tour the zone belongs to 4 isTourGuide?: boolean // return children without wrapping id false 5 text?: string // text in tooltip 6 shape?: Shape // which shape 7 maskOffset?: number // offset around zone 8 borderRadius?: number // round corner when rectangle 9 keepTooltipPosition?: boolean 10 tooltipBottomOffset?: number 11 tooltipLeftOffset?: number 12 children: React.ReactNode 13 handleFunction?: () => void // allow pass a method to focused area 14 blockMaskClick?: boolean // flag to set if svg mask is clickable 15} 16 17type Shape = 'circle' | 'rectangle' | 'circle_and_keep' | 'rectangle_and_keep' 18 19export interface TourGuideProviderProps { 20 tooltipComponent?: React.ComponentType<TooltipProps> 21 tooltipStyle?: StyleProp<ViewStyle> 22 labels?: Labels 23 startAtMount?: boolean | string // start at mount, boolean for single tours, string for multiple tours 24 androidStatusBarVisible?: boolean 25 backdropColor?: string 26 verticalOffset?: number 27 wrapperStyle?: StyleProp<ViewStyle> 28 maskOffset?: number 29 borderRadius?: number 30 animationDuration?: number 31 children: React.ReactNode 32 dismissOnPress?: boolean 33 preventOutsideInteraction?: boolean 34 blockMaskClick?: boolean // block click outside mask but allow click in focused element 35} 36 37interface TooltipProps { 38 isFirstStep?: boolean 39 isLastStep?: boolean 40 currentStep: Step 41 labels?: Labels 42 handleNext?(): void 43 handlePrev?(): void 44 handleStop?(): void 45} 46 47interface Labels { 48 skip?: string 49 previous?: string 50 next?: string 51 finish?: string 52}
In order to start the tutorial, you can call the start
function from useTourGuideController
hook:
1function HomeScreen() { 2 const { start } = useTourGuideController() 3 4 React.useEffect(() => { 5 start() 6 }, []) 7 8 9 render() { 10 // ... 11 } 12} 13 14export default HomeScreen
If you are looking for a working example, please check out this link.
If you'd like to have multiple tours (different pages, differnt user types, etc) you can pass in a tourKey
to useTourGuideController
to create a tour that is keyed to that tourKey
. Important If you use a keyed tour, in order for the TourGuideZone
components to register correctly you must do one of two things. Either (1) pass along the tourKey
to the TourGuideZone
components, or (2) extract the TourGuideZone
components from the hook itself
(1) If you want to pass along the tourKey
1import { TourGuideZone, useTourGuideController } from 'rn-tourguide' 2const { 3 canStart, // <-- These are all keyed to the tourKey 4 start, // <-- These are all keyed to the tourKey 5 stop, // <-- These are all keyed to the tourKey 6 eventEmitter, // <-- These are all keyed to the tourKey 7 tourKey, // <-- Extract the tourKey 8} = useTourGuideController('results') 9 10return ( 11 <TourGuideZone 12 tourKey={tourKey} // <-- Pass in the tourKey 13 zone={2} 14 text='Check on your results' 15 > 16 {/** Children */} 17 </TourGuideZone> 18)
Or (2) if you want to extract the components directly from the hook
1import { useTourGuideController } from 'rn-tourguide' 2const { canStart, start, stop, TourGuideZone } = 3 useTourGuideController('results') 4 5return ( 6 <TourGuideZone // <-- No need to pass in the tourKey 7 zone={2} 8 text='Check on your results' 9 > 10 {/** Children */} 11 </TourGuideZone> 12)
If you use multiple tours and would like to use the startAtMount
prop on the TourGuideProvider
component, then pass in the string of the tour you'd like to start
You can customize the tooltip by passing a component to the copilot
HOC maker. If you are looking for an example tooltip component, take a look at the default tooltip implementation.
1const TooltipComponent = ({ 2 isFirstStep, 3 isLastStep, 4 handleNext, 5 handlePrev, 6 handleStop, 7 currentStep, 8}) => ( 9 // ... 10); 11 12<TourGuideProvider {...{tooltipComponent: TooltipComponent}}> 13// ... 14</TourGuideProvider>
You can customize tooltips style:
1const style = { 2 backgroundColor: '#9FA8DA', 3 borderRadius: 10, 4 paddingTop: 5, 5} 6 7<TourGuideProvider {...{ tooltipStyle: style }}> 8// ... 9</TourGuideProvider>
You can customize the mask color - default is rgba(0, 0, 0, 0.4)
, by passing a color string to the copilot
HOC maker.
1<TourGuideProvider {...{ backdropColor: 'rgba(50, 50, 100, 0.9)' }}> 2 // ... 3</TourGuideProvider>
You can localize labels:
1<TourGuideProvider 2 {...{ 3 labels: { 4 previous: 'Vorheriger', 5 next: 'Nächster', 6 skip: 'Überspringen', 7 finish: 'Beenden', 8 }, 9 }} 10> 11 // ... 12</TourGuideProvider>
Along with start()
, useTourGuideController
passes copilotEvents
function to the component to help you with tracking of tutorial progress. It utilizes mitt under the hood, you can see how full API there.
List of available events is:
start
— Copilot tutorial has started.stop
— Copilot tutorial has ended or skipped.stepChange
— Next step is triggered. Passes Step
instance as event handler argument.Sometimes you need to prevent users to interact with app while tour is shown, in such case preventOutsideInteraction
prop is up for you.
default: false
1<TourGuideProvider preventOutsideInteraction> 2 <AppContent /> 3</TourGuideProvider>
Issues and Pull Requests are always welcome.
Looking for a ReactNative freelance expert with more than 14 years experience? Contact me from my website!
No vulnerabilities found.
No security vulnerabilities found.