Skip to content

Commit 4a3c91f

Browse files
authored
Merge pull request #17 from edwardloopez/docs/improve-examples
docs: add example for managing multiple tours in one app
2 parents 6ded3f2 + ec9c7fb commit 4a3c91f

File tree

1 file changed

+236
-0
lines changed

1 file changed

+236
-0
lines changed

docs/EXAMPLES.md

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,239 @@ function ThemeDemo() {
332332
);
333333
}
334334
```
335+
336+
## Example 4: Multiple Tours in One App
337+
338+
Manage different tours for different user flows (onboarding, feature discovery, etc).
339+
340+
```tsx
341+
import { useEffect, useState } from 'react';
342+
import { View, Text, Button, ScrollView } from 'react-native';
343+
import {
344+
CoachmarkProvider,
345+
CoachmarkAnchor,
346+
CoachmarkOverlay,
347+
createTour,
348+
useCoachmark,
349+
} from '@edwardloopez/react-native-coachmark';
350+
351+
function MainApp() {
352+
const [userType, setUserType] = useState<'new' | 'returning'>('new');
353+
const { start, isActive } = useCoachmark();
354+
355+
// Tour 1: First-time user onboarding
356+
const onboardingTour = createTour('onboarding-new-user', [
357+
{
358+
id: 'welcome-banner',
359+
title: '🎉 Welcome!',
360+
description: 'This is your new dashboard. Let\'s explore key features.',
361+
placement: 'bottom',
362+
shape: 'rect',
363+
},
364+
{
365+
id: 'main-actions',
366+
title: 'Main Actions',
367+
description: 'Create, edit, or view your content here',
368+
placement: 'top',
369+
shape: 'rect',
370+
radius: 12,
371+
},
372+
{
373+
id: 'profile-menu',
374+
title: 'Your Profile',
375+
description: 'Access settings, preferences, and account info',
376+
placement: 'bottom',
377+
shape: 'circle',
378+
padding: 16,
379+
},
380+
], {
381+
delay: 500,
382+
showOnce: true, // Only show once per user
383+
});
384+
385+
// Tour 2: Feature discovery for returning users
386+
const featureDiscoveryTour = createTour('feature-discovery', [
387+
{
388+
id: 'new-feature-badge',
389+
title: '✨ New Feature!',
390+
description: 'We\'ve added a powerful new search capability',
391+
placement: 'bottom',
392+
},
393+
{
394+
id: 'search-bar',
395+
title: 'Advanced Search',
396+
description: 'Find anything instantly with smart filters',
397+
placement: 'bottom',
398+
autoFocus: 'ifNeeded',
399+
},
400+
], {
401+
delay: 2000,
402+
showOnce: true,
403+
});
404+
405+
// Tour 3: Quick tips (can be triggered manually)
406+
const quickTipsTour = createTour('quick-tips', [
407+
{
408+
id: 'bulk-actions',
409+
title: 'Pro Tip: Bulk Actions',
410+
description: 'Select multiple items with checkboxes, then act on all at once',
411+
placement: 'top',
412+
onEnter: () => console.log('Tip viewed: Bulk Actions'),
413+
},
414+
{
415+
id: 'keyboard-shortcuts',
416+
title: 'Pro Tip: Shortcuts',
417+
description: 'Press ? to see all keyboard shortcuts',
418+
placement: 'bottom',
419+
},
420+
]);
421+
422+
useEffect(() => {
423+
// Auto-start appropriate tour based on user type
424+
if (!isActive) {
425+
if (userType === 'new') {
426+
start(onboardingTour);
427+
} else {
428+
start(featureDiscoveryTour);
429+
}
430+
}
431+
}, [userType]);
432+
433+
const handleStartTips = () => {
434+
start(quickTipsTour);
435+
};
436+
437+
const toggleUserType = () => {
438+
setUserType(userType === 'new' ? 'returning' : 'new');
439+
};
440+
441+
return (
442+
<ScrollView style={{ flex: 1, backgroundColor: '#f5f5f5' }}>
443+
<View style={{ padding: 20 }}>
444+
{/* Welcome Banner */}
445+
<CoachmarkAnchor id="welcome-banner">
446+
<View style={{
447+
backgroundColor: '#007AFF',
448+
borderRadius: 12,
449+
padding: 20,
450+
marginBottom: 20,
451+
}}>
452+
<Text style={{ color: '#fff', fontSize: 20, fontWeight: 'bold' }}>
453+
Welcome, User!
454+
</Text>
455+
<Text style={{ color: '#fff', marginTop: 8 }}>
456+
{userType === 'new' ? 'First time here? Let\'s get started!' : 'Welcome back!'}
457+
</Text>
458+
</View>
459+
</CoachmarkAnchor>
460+
461+
{/* Main Actions */}
462+
<CoachmarkAnchor id="main-actions">
463+
<View style={{
464+
flexDirection: 'row',
465+
gap: 12,
466+
marginBottom: 20,
467+
}}>
468+
<Button title="Create" color="#34C759" />
469+
<Button title="Edit" color="#FF9500" />
470+
<Button title="View" color="#5856D6" />
471+
</View>
472+
</CoachmarkAnchor>
473+
474+
{/* New Feature Badge */}
475+
<CoachmarkAnchor id="new-feature-badge">
476+
<View style={{
477+
backgroundColor: '#fff',
478+
borderLeftWidth: 4,
479+
borderLeftColor: '#34C759',
480+
padding: 16,
481+
marginBottom: 20,
482+
borderRadius: 8,
483+
}}>
484+
<Text style={{ fontSize: 14, fontWeight: '600', marginBottom: 4 }}>
485+
✨ New: Advanced Search
486+
</Text>
487+
<Text style={{ fontSize: 12, color: '#666' }}>
488+
Discover the new search feature
489+
</Text>
490+
</View>
491+
</CoachmarkAnchor>
492+
493+
{/* Search Bar */}
494+
<CoachmarkAnchor id="search-bar">
495+
<View style={{
496+
backgroundColor: '#fff',
497+
borderRadius: 8,
498+
padding: 12,
499+
marginBottom: 20,
500+
borderWidth: 1,
501+
borderColor: '#ddd',
502+
}}>
503+
<Text style={{ color: '#999' }}>🔍 Search everything...</Text>
504+
</View>
505+
</CoachmarkAnchor>
506+
507+
{/* Bulk Actions Section */}
508+
<CoachmarkAnchor id="bulk-actions">
509+
<View style={{
510+
backgroundColor: '#fff',
511+
padding: 16,
512+
borderRadius: 8,
513+
marginBottom: 20,
514+
}}>
515+
<Text style={{ fontSize: 16, fontWeight: '600', marginBottom: 8 }}>
516+
Select Multiple Items
517+
</Text>
518+
<View style={{ flexDirection: 'row', gap: 8 }}>
519+
<Text>☐ Item 1</Text>
520+
<Text>☐ Item 2</Text>
521+
<Text>☐ Item 3</Text>
522+
</View>
523+
</View>
524+
</CoachmarkAnchor>
525+
526+
{/* Keyboard Shortcuts Info */}
527+
<CoachmarkAnchor id="keyboard-shortcuts">
528+
<View style={{
529+
backgroundColor: '#f9f9f9',
530+
padding: 12,
531+
borderRadius: 8,
532+
marginBottom: 20,
533+
}}>
534+
<Text style={{ fontSize: 12, color: '#666' }}>
535+
💡 Press ? anywhere to view keyboard shortcuts
536+
</Text>
537+
</View>
538+
</CoachmarkAnchor>
539+
540+
{/* Action Buttons */}
541+
<CoachmarkAnchor id="profile-menu">
542+
<View style={{
543+
backgroundColor: '#fff',
544+
padding: 12,
545+
borderRadius: 8,
546+
flexDirection: 'row',
547+
justifyContent: 'space-around',
548+
marginBottom: 20,
549+
}}>
550+
<Button
551+
title="Quick Tips"
552+
color="#007AFF"
553+
onPress={handleStartTips}
554+
/>
555+
<Button
556+
title={`Switch to ${userType === 'new' ? 'Returning' : 'New'} User`}
557+
color="#666"
558+
onPress={toggleUserType}
559+
/>
560+
</View>
561+
</CoachmarkAnchor>
562+
</View>
563+
564+
<CoachmarkOverlay />
565+
</ScrollView>
566+
);
567+
}
568+
569+
export default MainApp;
570+
```

0 commit comments

Comments
 (0)