项目作者: muhammedtanriverdi

项目描述 :
SwiftUI Progressive Onboard
高级语言: Swift
项目地址: git://github.com/muhammedtanriverdi/SwiftUIProgressiveOnboard.git
创建时间: 2020-10-20T13:39:11Z
项目社区:https://github.com/muhammedtanriverdi/SwiftUIProgressiveOnboard

开源协议:MIT License

下载


SwiftUIProgressiveOnboard

SwiftUIProgressiveOnboard is designed for progressive onboards in SwiftUI.

Installation

Swift Package Manager

Open your project in Xcode, click File -> Swift Packages -> Add Package Dependency, enter the repo’s URL.

  1. https://github.com/muhammedtanriverdi/SwiftUIProgressiveOnboard.git

Usage

Import the library

  1. import SwiftUIProgressiveOnboard

STEP 1: Set your data as a json format string

  1. let progressiveOnboardsJson = """
  2. [
  3. {
  4. "description": "You can use onboard screens. This is the first onboard text. Let's make it longer with the same text. You can use onboard screens. This is the first onboard text.",
  5. "previousButtonTitle": "",
  6. "nextButtonTitle": "Next"
  7. },
  8. {
  9. "description": "This is the second one, go down for a button",
  10. "previousButtonTitle": "Previous",
  11. "nextButtonTitle": "Go"
  12. }
  13. ]
  14. """

STEP 2: Create an observable ProgressiveOnboard object with your data

  1. @ObservedObject var onboard = ProgressiveOnboard.init(withJson: progressiveOnboardsJson)

STEP 3: Create a ZStack for overlay

  1. var body: some View {
  2. ZStack {
  3. }
  4. .frame(maxWidth: .infinity, maxHeight: .infinity)
  5. .edgesIgnoringSafeArea(.all)
  6. }

STEP 4: Add progressive board views to the buttons, texts, views… (filterViews are automatically created by the given data count)

  1. var body: some View {
  2. ZStack {
  3. VStack {
  4. Text("Lorem Ipsum 1")
  5. .background(ProgressiveOnboardGeometry(withRect: $onboard.filterViews[0]))
  6. Button("Simple Button") {}
  7. .background(ProgressiveOnboardGeometry(withRect: $onboard.filterViews[1]))
  8. }
  9. }
  10. }

STEP 5: Show your onboard view at the top of ZStack

  1. var body: some View {
  2. ZStack {
  3. VStack {
  4. Text("Lorem Ipsum 1")
  5. .background(ProgressiveOnboardGeometry(withRect: $onboard.filterViews[0]))
  6. Button("Simple Button") {}
  7. .background(ProgressiveOnboardGeometry(withRect: $onboard.filterViews[1]))
  8. }
  9. if(onboard.showOnboardScreen) {
  10. ProgressiveOnboardView.init(withProgressiveOnboard: self.onboard)
  11. }
  12. }
  13. }

USING ON DETAIL VIEW
If you want to use it in another view, you can follow the same steps from the beginning.
You also need to define the coordinate system as “OnboardSpace” for the GeometryReader for the ZStack.

STEP 6:

  1. ZStack {
  2. ...
  3. }
  4. .frame(maxWidth: .infinity, maxHeight: .infinity)
  5. .coordinateSpace(name: "OnboardSpace")

Licence

SwiftUIProgressiveOnboard is available under the MIT license. See the LICENSE file for more info.