Skip to content

Commit

Permalink
Fix style bug
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Apr 22, 2024
1 parent 3c39d6a commit fee5249
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
8 changes: 8 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ OnboardingKit honors semver.



## 7.0.1

### 🐛 Bug Fixes

* The custom onboarding page view style is now applied on appear, instead of as a task.



## 7.0

This version drastically simplifies the library and bumps the platform deployment targets to more modern platform versions.
Expand Down
48 changes: 35 additions & 13 deletions Sources/OnboardingKit/Views/OnboardingPageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ import SwiftUI
import UIKit
#endif

/**
This view can be used to render a collection of pages, that
can be swiped through horizontally.

This will use a regular `TabView` on iOS, and a custom page
view on other platforms.

Apply the `.onboardingPageViewStyle(...)` modifier to style
this view.
*/
/// This view can be used to show a collection of pages that
/// can be swiped through horizontally.
///
/// This view uses a regular SwiftUI `TabView` on iOS, and a
/// custom page view implementation on other platforms.
///
/// Apply an ``SwiftUI/View/onboardingPageViewStyle(_:)`` to
/// your view to customize its style.
public struct OnboardingPageView<Page, PageItemView: View>: View {

/// Create a tutorial page view.
Expand Down Expand Up @@ -51,7 +49,7 @@ public struct OnboardingPageView<Page, PageItemView: View>: View {

public var body: some View {
bodyContent
.task { setupAppearance() }
.onAppear { setupAppearance() }
}
}

Expand All @@ -72,7 +70,7 @@ private extension OnboardingPageView {
.tag($0.offset)
}
}
.tabViewStyle(.page)
.tabViewStyle(.page(indexDisplayMode: .always))
#else
PageView(
pages: Array(pages.enumerated()),
Expand All @@ -99,8 +97,32 @@ private extension OnboardingPageView {
func setupAppearance() {
#if os(iOS)
let appearance = UIPageControl.appearance()
appearance.currentPageIndicatorTintColor = UIColor(style.currentPageIndicatorTintColor)
appearance.pageIndicatorTintColor = UIColor(style.pageIndicatorTintColor)
appearance.currentPageIndicatorTintColor = UIColor(style.currentPageIndicatorTintColor)
#endif
}
}

#Preview {

struct Preview: View {

@State
private var index = 0

var body: some View {
OnboardingPageView(pages: Array(0...10), pageIndex: $index) { index, info in
Text("Page \(index)/\(info.totalPageCount)")
}
.onboardingPageViewStyle(
.init(
pageIndicatorTintColor: .red,
currentPageIndicatorTintColor: .gray
)
)
.background(Color.blue)
}
}

return Preview()
}

0 comments on commit fee5249

Please sign in to comment.