gk-rn-onboarding
v1.0.4
Published
A customizable onboarding screen component for React Native applications.
Downloads
2
Maintainers
Readme
gk-rn-onboarding Package
gk-rn-onboarding
is a customizable onboarding screen component for React Native applications.
Installation
You can install the package via npm or yarn:
npm install gk-rn-onboarding
or
yarn add gk-rn-onboarding
Usage
Import the OnboardingScreen
component and use it in your application.
import React, { useState } from "react";
import { View } from "react-native";
import { OnboardingScreen, Slide } from "gk-rn-onboarding";
const slides: Slide[] = [
{
title: "Welcome",
subtitle: "Introduction",
description: "This is the first slide",
image: require("./assets/image1.png"),
backgroundColor: "#fff",
},
{
title: "Learn",
subtitle: "Educational",
description: "This is the second slide",
image: require("./assets/image2.png"),
backgroundColor: "#f7f7f7",
},
];
const App = () => {
const [isOnboardingOpen, setOnboardingOpen] = useState(true);
return (
<View style={{ flex: 1 }}>
<OnboardingScreen
slides={slides}
isOpen={isOnboardingOpen}
setIsOpen={setOnboardingOpen}
onComplete={() => console.log("Onboarding complete")}
/>
</View>
);
};
export default App;
Props
OnboardingScreen
| Prop | Type | Default | Description |
| --------------------- | ---------------------------------- | ------------------- | ------------------------------------------------------------------------- |
| slides
| Slide[]
| []
| An array of slide objects defining the content of each onboarding screen. |
| isOpen
| boolean
| false
| Controls whether the onboarding screen is visible. |
| setIsOpen
| (isOpen: boolean) => void
| | Function to set the visibility of the onboarding screen. |
| onComplete
| () => void
| undefined
| Callback function when the onboarding is completed. |
| onNext
| () => void
| undefined
| Callback function when the next button is pressed. |
| onPrev
| () => void
| undefined
| Callback function when the previous button is pressed. |
| onSkip
| () => void
| undefined
| Callback function when the skip button is pressed. |
| ButtonComponent
| React.ComponentType<ButtonProps>
| DefaultButton
| Custom button component. |
| TextComponent
| React.ComponentType<any>
| DefaultText
| Custom text component. |
| TitleComponent
| React.ComponentType<any>
| DefaultTitle
| Custom title component. |
| SubtitleComponent
| React.ComponentType<any>
| DefaultSubtitle
| Custom subtitle component. |
| ImageComponent
| React.ComponentType<any>
| Image
| Custom image component. |
| buttonStyles
| any
| undefined
| Styles for the buttons. |
| textColor
| string
| black
| Text color for the title, subtitle, and description. |
| iconStyle
| StyleProp<ViewStyle>
| undefined
| Styles for the icon. |
| imageStyle
| StyleProp<ImageStyle>
| undefined
| Styles for the image. |
| contentStyle
| StyleProp<ViewStyle>
| undefined
| Styles for the content container. |
| SkipButtonComponent
| React.ComponentType<ButtonProps>
| DefaultSkipButton
| Custom skip button component. |
| skipButtonStyle
| StyleProp<ViewStyle>
| undefined
| Styles for the skip button. |
| skipIcon
| React.ReactNode
| undefined
| Custom icon for the skip button. |
Slide
| Prop | Type | Default | Description |
| ----------------- | ----------------- | ----------- | ----------------------------------- |
| title
| string
| undefined
| Title text of the slide. |
| subtitle
| string
| undefined
| Subtitle text of the slide. |
| description
| string
| required
| Description text of the slide. |
| icon
| React.ReactNode
| undefined
| Icon to be displayed on the slide. |
| image
| any
| undefined
| Image to be displayed on the slide. |
| backgroundColor
| string
| white
| Background color of the slide. |
Customization
You can customize the onboarding screen by providing your own components for buttons, text, titles, subtitles, and images. Use the corresponding props to pass your custom components.
Example
const CustomButton = ({ onPress, text }: ButtonProps) => (
<TouchableOpacity
onPress={onPress}
style={{ padding: 10, backgroundColor: "blue" }}
>
<Text style={{ color: "white" }}>{text}</Text>
</TouchableOpacity>
);
const App = () => {
const [isOnboardingOpen, setOnboardingOpen] = useState(true);
return (
<View style={{ flex: 1 }}>
<OnboardingScreen
slides={slides}
isOpen={isOnboardingOpen}
setIsOpen={setOnboardingOpen}
ButtonComponent={CustomButton}
onComplete={() => console.log("Onboarding complete")}
/>
</View>
);
};
export default App;
License
MIT