1.0.4 • Published 1 year ago

gk-rn-onboarding v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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

PropTypeDefaultDescription
slidesSlide[][]An array of slide objects defining the content of each onboarding screen.
isOpenbooleanfalseControls whether the onboarding screen is visible.
setIsOpen(isOpen: boolean) => voidFunction to set the visibility of the onboarding screen.
onComplete() => voidundefinedCallback function when the onboarding is completed.
onNext() => voidundefinedCallback function when the next button is pressed.
onPrev() => voidundefinedCallback function when the previous button is pressed.
onSkip() => voidundefinedCallback function when the skip button is pressed.
ButtonComponentReact.ComponentType<ButtonProps>DefaultButtonCustom button component.
TextComponentReact.ComponentType<any>DefaultTextCustom text component.
TitleComponentReact.ComponentType<any>DefaultTitleCustom title component.
SubtitleComponentReact.ComponentType<any>DefaultSubtitleCustom subtitle component.
ImageComponentReact.ComponentType<any>ImageCustom image component.
buttonStylesanyundefinedStyles for the buttons.
textColorstringblackText color for the title, subtitle, and description.
iconStyleStyleProp<ViewStyle>undefinedStyles for the icon.
imageStyleStyleProp<ImageStyle>undefinedStyles for the image.
contentStyleStyleProp<ViewStyle>undefinedStyles for the content container.
SkipButtonComponentReact.ComponentType<ButtonProps>DefaultSkipButtonCustom skip button component.
skipButtonStyleStyleProp<ViewStyle>undefinedStyles for the skip button.
skipIconReact.ReactNodeundefinedCustom icon for the skip button.

Slide

PropTypeDefaultDescription
titlestringundefinedTitle text of the slide.
subtitlestringundefinedSubtitle text of the slide.
descriptionstringrequiredDescription text of the slide.
iconReact.ReactNodeundefinedIcon to be displayed on the slide.
imageanyundefinedImage to be displayed on the slide.
backgroundColorstringwhiteBackground 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

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago