Gathering detailed insights and metrics for peerbr-tourguide-test
Gathering detailed insights and metrics for peerbr-tourguide-test
Gathering detailed insights and metrics for peerbr-tourguide-test
Gathering detailed insights and metrics for peerbr-tourguide-test
npm install peerbr-tourguide-test
Typescript
Module System
Node Version
NPM Version
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
23
A flexible tourguide for your react native app!
🎉 Webable 🎉
(a rewriting of react-native-copilot)
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 children: React.ReactNode 12} 13 14type Shape = 'circle' | 'rectangle' | 'circle_and_keep' | 'rectangle_and_keep' 15 16export interface TourGuideProviderProps { 17 tooltipComponent?: React.ComponentType<TooltipProps> 18 tooltipStyle?: StyleProp<ViewStyle> 19 labels?: Labels 20 startAtMount?: boolean | string // start at mount, boolean for single tours, string for multiple tours 21 androidStatusBarVisible?: boolean 22 backdropColor?: string 23 verticalOffset?: number 24 wrapperStyle?: StyleProp<ViewStyle> 25 maskOffset?: number 26 borderRadius?: number 27 animationDuration?: number 28 children: React.ReactNode 29 dismissOnPress?: boolean 30 preventOutsideInteraction?:boolean 31} 32 33interface TooltipProps { 34 isFirstStep?: boolean 35 isLastStep?: boolean 36 currentStep: Step 37 labels?: Labels 38 handleNext?(): void 39 handlePrev?(): void 40 handleStop?(): void 41} 42 43interface Labels { 44 skip?: string 45 previous?: string 46 next?: string 47 finish?: string 48}
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.