Skip to content

CalebSDHUB/FavOnboardingKit

Repository files navigation

FavOnboardingKit

FavOnboardingKit provides an onboarding flow that is simple and easy to implement.

App start screen

Contents

Requirements

  • iOS 15.0 or later
  • Xcode 13.0 or later
  • Swift 5.0 or later

Installation

There are two ways to use FavOnboardingKit in your project:

  • using Swift Package Manager
  • manual install (build frameworks or embed Xcode Project)

Swift Package Manager

To integrate FavOnboardingKit into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:

dependencies: [
    .package(url: "https://github.com/CalebSDHUB/FavOnboardingKit", .upToNextMajor(from: "1.0.0"))
]

Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

Manually

If you prefer not to use Swift Package Manager, you can integrate FavOnboardingKit into your project manually.


Usage

Quick Start

import UIKit
import FavOnboardingKit

class ViewController: UIViewController {
    private var onboardingKit: FavOnboardingKit?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        DispatchQueue.main.async {
            self.onboardingKit = FavOnboardingKit(
                slides: [
                    .init(image: UIImage(named: "imSlide1")!,
                          title: "Personalised offers at 40,000+ places"),
                    .init(image: UIImage(named: "imSlide2")!,
                          title: "Stack your rewards every time you pay"),
                    .init(image: UIImage(named: "imSlide3")!,
                          title: "Enjoy now, FavePay Later"),
                    .init(image: UIImage(named: "imSlide4")!,
                          title: "Earn cashback with your physical card"),
                    .init(image: UIImage(named: "imSlide5")!,
                          title: "Save and earn cashback with Deals or eCards")
                ],
                tintColor: UIColor(red: 220/255, green: 20/255, blue: 60/255, alpha: 1.0),
                themeFont: UIFont(name: "Baskerville", size: 28) ?? .systemFont(ofSize: 28, weight: .bold))
            self.onboardingKit?.delegate = self
            self.onboardingKit?.launchOnboarding(rootVC: self)
        }
    }
}

extension ViewController: FavOnboardingKitDelegate {
    func nextButtonTap(atIndex: Int) {
        print("Next button is pressed at index: \(atIndex)")
    }
    
    func getStartedTap() {
        onboardingKit?.dismissOnboarding()
        onboardingKit = nil
        transit(viewController: MainViewController())
    }
    
    private func transit(viewController: UIViewController) {
        let foregroundScene = UIApplication.shared.connectedScenes.filter({
            $0.activationState == .foregroundActive
        })
        
        let window = foregroundScene
            .map({ $0 as? UIWindowScene })
            .compactMap({ $0 })
            .first?
            .windows
            .filter({ $0.isKeyWindow })
            .first
        
        guard let uWindow = window else { return }
        uWindow.rootViewController = viewController
        
        UIView.transition(with: uWindow, duration: 0.3, options: .transitionCrossDissolve, animations: nil)
    }
}

final class MainViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        let label = UILabel()
        label.text = "Main View Controller"
        view.addSubview(label)
        label.snp.makeConstraints { make in
            make.center.equalTo(view)
        }
        view.backgroundColor = .gray
    }
}

Credits

  • Caleb Danielsen

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages