Skip to main content

useOnboarding Hook

The useOnboarding hook provides programmatic control over the onboarding flow.

Basic Usage

import { useOnboarding } from 'react-native-app-onboard';

const OnboardingControls = () => {
const {
currentPage,
nextPage,
isDone,
progress,
scrollTo,
} = useOnboarding();

return (
<View>
<Text>Page {currentPage + 1}</Text>
<Button
title={isDone ? 'Finish' : 'Next'}
onPress={nextPage}
/>
</View>
);
};

Available Values

ValueTypeDescription
currentPagenumberCurrent page index
setCurrentPage(page: number) => voidSet current page
scrollEnabledbooleanScrolling enabled state
enableScroll(enabled: boolean) => voidEnable/disable scrolling
flatListRefReact.RefObject<FlatList>FlatList reference
numberOfScreensnumberTotal screens count
nextPage() => voidGo to next page
scrollTo(page: number) => voidScroll to page
progressnumberProgress (0-1)
isDonebooleanOnboarding complete

Examples

Progress Indicator

const ProgressBar = () => {
const { progress } = useOnboarding();

return (
<View style={styles.progressContainer}>
<Animated.View
style={[
styles.progressBar,
{
width: progress.interpolate({
inputRange: [0, 1],
outputRange: ['0%', '100%'],
}),
},
]}
/>
</View>
);
};

Custom Navigation

const Navigation = () => {
const { currentPage, numberOfScreens, scrollTo } = useOnboarding();

return (
<View style={styles.navigation}>
{Array.from({ length: numberOfScreens }).map((_, index) => (
<TouchableOpacity
key={index}
onPress={() => scrollTo(index)}
style={[
styles.dot,
currentPage === index && styles.activeDot,
]}
/>
))}
</View>
);
};

Scroll Control

const ScrollControls = () => {
const { enableScroll, scrollEnabled } = useOnboarding();

return (
<View>
<Switch
value={scrollEnabled}
onValueChange={enableScroll}
/>
<Text>
Scrolling: {scrollEnabled ? 'Enabled' : 'Disabled'}
</Text>
</View>
);
};

Progress-Based Content

const DynamicContent = () => {
const { progress, currentPage } = useOnboarding();

return (
<Animated.View
style={{
opacity: progress,
transform: [
{
translateY: progress.interpolate({
inputRange: [0, 1],
outputRange: [50, 0],
}),
},
],
}}
>
<Text>Content for page {currentPage + 1}</Text>
</Animated.View>
);
};