Skip to content

Commit

Permalink
Update demo app with new slideshow
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed May 28, 2024
1 parent 8fc1ec7 commit bd9c1a4
Show file tree
Hide file tree
Showing 13 changed files with 540 additions and 373 deletions.
14 changes: 9 additions & 5 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
A915F3F82B9F2BF300A50849 /* DemoPageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A915F3F72B9F2BF300A50849 /* DemoPageView.swift */; };
A91D17442C06697000721C94 /* DemoPageBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = A91D17432C06697000721C94 /* DemoPageBackground.swift */; };
A922B1F726FC73FF00E235A1 /* DemoApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = A922B1F626FC73FF00E235A1 /* DemoApp.swift */; };
A922B1F926FC73FF00E235A1 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A922B1F826FC73FF00E235A1 /* ContentView.swift */; };
A922B1FB26FC740000E235A1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A922B1FA26FC740000E235A1 /* Assets.xcassets */; };
Expand All @@ -16,12 +17,13 @@
A922B22E26FC829400E235A1 /* Onboarding+Demo.swift in Sources */ = {isa = PBXBuildFile; fileRef = A922B22D26FC829400E235A1 /* Onboarding+Demo.swift */; };
A922B23026FC9F4400E235A1 /* Image+Demo.swift in Sources */ = {isa = PBXBuildFile; fileRef = A922B22F26FC9F4400E235A1 /* Image+Demo.swift */; };
A96AA2E62B28383A00A6F6E8 /* OnboardingKit in Frameworks */ = {isa = PBXBuildFile; productRef = A96AA2E52B28383A00A6F6E8 /* OnboardingKit */; };
A98B1A522C05A64300690057 /* DemoPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98B1A512C05A64300690057 /* DemoPage.swift */; };
A98B1A522C05A64300690057 /* DemoPageContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98B1A512C05A64300690057 /* DemoPageContent.swift */; };
A98B1A542C05A98100690057 /* DemoSlideshow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98B1A532C05A98100690057 /* DemoSlideshow.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
A915F3F72B9F2BF300A50849 /* DemoPageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoPageView.swift; sourceTree = "<group>"; };
A91D17432C06697000721C94 /* DemoPageBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoPageBackground.swift; sourceTree = "<group>"; };
A922B1F326FC73FF00E235A1 /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
A922B1F626FC73FF00E235A1 /* DemoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoApp.swift; sourceTree = "<group>"; };
A922B1F826FC73FF00E235A1 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand All @@ -30,7 +32,7 @@
A922B22326FC741900E235A1 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
A922B22D26FC829400E235A1 /* Onboarding+Demo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Onboarding+Demo.swift"; sourceTree = "<group>"; };
A922B22F26FC9F4400E235A1 /* Image+Demo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Image+Demo.swift"; sourceTree = "<group>"; };
A98B1A512C05A64300690057 /* DemoPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoPage.swift; sourceTree = "<group>"; };
A98B1A512C05A64300690057 /* DemoPageContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoPageContent.swift; sourceTree = "<group>"; };
A98B1A532C05A98100690057 /* DemoSlideshow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoSlideshow.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -66,12 +68,13 @@
isa = PBXGroup;
children = (
A922B1F626FC73FF00E235A1 /* DemoApp.swift */,
A98B1A512C05A64300690057 /* DemoPage.swift */,
A922B1F826FC73FF00E235A1 /* ContentView.swift */,
A91D17432C06697000721C94 /* DemoPageBackground.swift */,
A98B1A512C05A64300690057 /* DemoPageContent.swift */,
A915F3F72B9F2BF300A50849 /* DemoPageView.swift */,
A98B1A532C05A98100690057 /* DemoSlideshow.swift */,
A922B22F26FC9F4400E235A1 /* Image+Demo.swift */,
A922B22D26FC829400E235A1 /* Onboarding+Demo.swift */,
A922B1F826FC73FF00E235A1 /* ContentView.swift */,
A922B1FA26FC740000E235A1 /* Assets.xcassets */,
A922B1FC26FC740000E235A1 /* Preview Content */,
A922B22426FC741900E235A1 /* Localizable.strings */,
Expand Down Expand Up @@ -170,8 +173,9 @@
A922B1F726FC73FF00E235A1 /* DemoApp.swift in Sources */,
A922B23026FC9F4400E235A1 /* Image+Demo.swift in Sources */,
A915F3F82B9F2BF300A50849 /* DemoPageView.swift in Sources */,
A91D17442C06697000721C94 /* DemoPageBackground.swift in Sources */,
A922B22E26FC829400E235A1 /* Onboarding+Demo.swift in Sources */,
A98B1A522C05A64300690057 /* DemoPage.swift in Sources */,
A98B1A522C05A64300690057 /* DemoPageContent.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
231 changes: 114 additions & 117 deletions Demo/Demo/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import OnboardingKit

struct ContentView: View {

@State var isListConditionalEnabled = false
@State var isListConditionalPresented = false
@State var isListCorrectBehaviorPresented = false
@State var isListDelayedPresented = false
@State var isListPopoverPresented = false
@State var isListSheetPresented = false
@State var isLocalizedPageViewPresented = false
@State var isLocalizedSlideshowPresented = false
@State var isConditionalEnabled = false
@State var isConditionalPresented = false
@State var isCorrectBehaviorPresented = false
@State var isDelayedPresented = false
@State var isPopoverPresented = false
@State var isSheetPresented = false
@State var isPageViewPresented = false
@State var isSlideshowPresented = false
@State var isToolbarPopoverPresented = false

@State var pageViewPageIndex = 0
Expand All @@ -28,97 +28,107 @@ struct ContentView: View {
NavigationStack {
List {
Section("Onboardings") {

listButton(
.popover,
presentPopover,
"Onboarding popover",
"This will only be presented once"
)
.demoPopover($isPopoverPresented)

// Standard onboardings

Button(action: presentListPopover) {
LabeledContent {} label: {
Text("Present an onboarding popover")
Text("This will only be presented once")
}
}
.demoPopover($isListPopoverPresented)

Button(action: presentListSheet) {
LabeledContent {} label: {
Text("Present an onboarding sheet")
Text("This will only be presented once")
}
listButton(
.sheet,
presentSheet,
"Onboarding modal",
"This will only be presented once"
)
.sheet(isPresented: $isSheetPresented) {
Text("Use modal onboarding screens to show more complex onboardings, like page views or slideshows."
)
.padding()
.multilineTextAlignment(.center)
}

// Conditional onboarding

HStack(spacing: 0) {
Button(action: presentListConditional) {
LabeledContent {} label: {
Text("Present a conditional onboarding")
Text("This will only be presented once, and only if the toggle is enabled.")
}
}
Toggle(isOn: $isListConditionalEnabled) {}
VStack(spacing: 20) {
listButton(
.conditional,
presentConditional,
"Conditional onboarding",
"This will only be presented once, and only if the toggle below is enabled."
)
Toggle(isOn: $isConditionalEnabled) {}
.labelsHidden()
.padding(.leading, 5)
}
.demoPopover(
$isListConditionalPresented,
text: "Conditional onboardings are great if you have a prerequisite that needs to be true before an onboarding is performed."
$isConditionalPresented,
text: "Conditional onboardings are great if a condition must be met before the onboarding is presented."
)

listButton(
.delayed,
presentDelayed,
"Delayed onboarding",
"This will only be presented once, and only after \(Onboarding.demoDelayed.requiredPresentationAttempts) taps."
)

// Delayed onboarding

Button(action: presentListDelayed) {
LabeledContent {} label: {
Text("Present a delayed onboarding")
Text("This will be presented once, after \(Onboarding.demoDelayed.requiredPresentationAttempts) taps.")
}
}
.demoPopover(
$isListDelayedPresented,
text: "Delayed onboardings are great if you want to control the presentation order of a list of onboardings."
$isDelayedPresented,
text: "Delayed onboardings are great to control the order of a list of onboardings."
)

// Correct Behavior onboarding

button(
presentListCorrectBehavior,
"Present a correct behavior onboarding",
"You must tap this button \(Onboarding.demoCorrectBehavior.remainingPresentationAttempts) times more to show the onboarding."
listButton(
.correctBehavior,
presentCorrectBehavior,
"Correct behavior onboarding",
"This will be presented every 3rd tap."
)
.demoPopover(
$isListCorrectBehaviorPresented,
text: "Correct behavior onboardings are great if you want to make your users behave in a certain way, e.g. in games."
$isCorrectBehaviorPresented,
text: "Correct behavior onboardings are great to teach users how to behave, e.g. in games."
)
}

// Flows


Section("Flows") {
button(
presentLocalizedFlowAsPageView,
listButton(
.popover,
presentLocalizedPageView,
"Present an onboarding page view",
"This onboarding flow lets you swipe through a set of pages."
)
button(
presentLocalizedFlowAsSlideshow,
.sheet(isPresented: $isPageViewPresented) {
DemoPageView(
onboarding: .demo,
index: $pageViewPageIndex
)
}

listButton(
.popover,
presentLocalizedSlideshow,
"Present an onboarding slideshow",
"This onboarding flow automatically slides through a set of pages."
)
.sheet(isPresented: $isSlideshowPresented) {
DemoSlideshow(
onboarding: .demo,
index: $pageViewPageIndex
)
}
}
}
.navigationTitle("OnboardingKit")
.onAppear(perform: presentToolbarPopover)
.safeAreaInset(edge: .bottom) {
Button(action: reset) {
Text("Reset onboarding state")
.frame(minHeight: 50)
.frame(maxWidth: .infinity)
VStack {
Divider()
Button("Reset onboarding state", action: reset)
.buttonStyle(.borderedProminent)
.padding()
}
.buttonStyle(.borderedProminent)
.background(Color.blue)
.frame(maxWidth: .infinity)
.background(.thinMaterial)
}
.sheet(isPresented: $isListSheetPresented) { listSheet }
.sheet(isPresented: $isLocalizedPageViewPresented) { pageViewSheet }
.sheet(isPresented: $isLocalizedSlideshowPresented) { slideshowSheet }
.toolbar {
ToolbarItem(placement: .confirmationAction) {
toolbarButton
Expand All @@ -131,18 +141,27 @@ struct ContentView: View {

private extension View {

func button(
func listButton(
_ icon: Image,
_ action: @escaping () -> Void,
_ title: String,
_ text: String
) -> some View {
Button(action: action) {
LabeledContent {} label: {
Text(title)
Text(text)
}
Label(
title: {
LabeledContent {} label: {
Text(title)
Text(text)
}
},
icon: {
icon
}
)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
}

func demoPopover(
Expand All @@ -161,26 +180,6 @@ private extension View {
}
}

private extension ContentView {

var listSheet: some View {
Text("Use modal sheets or covers to present launch onboarding flows.")
.padding()
}

var pageViewSheet: some View {
DemoPageView(
onboarding: .demo,
index: $pageViewPageIndex
)
}

var slideshowSheet: some View {
Text("Use modal sheets or covers to present launch onboarding flows.")
.padding()
}
}

@MainActor
private extension ContentView {

Expand All @@ -190,41 +189,41 @@ private extension ContentView {
}
}

func presentListConditional() {
Onboarding.demoConditional { isListConditionalEnabled }
.tryPresent { isListConditionalPresented = true }
func presentConditional() {
Onboarding.demoConditional { isConditionalEnabled }
.tryPresent { isConditionalPresented = true }
}

func presentListCorrectBehavior() {
func presentCorrectBehavior() {
Onboarding.demoCorrectBehavior
.tryPresent { isListCorrectBehaviorPresented = true }
.tryPresent { isCorrectBehaviorPresented = true }
}

func presentListDelayed() {
func presentDelayed() {
Onboarding.demoDelayed
.tryPresent { isListDelayedPresented = true }
.tryPresent { isDelayedPresented = true }
}

func presentListPopover() {

func presentLocalizedPageView() {
isPageViewPresented = true
}

func presentLocalizedSlideshow() {
isSlideshowPresented = true
}

func presentPopover() {
Onboarding.demoPopover.tryPresent {
isListPopoverPresented = true
isPopoverPresented = true
}
}

func presentListSheet() {
func presentSheet() {
Onboarding.demoSheet.tryPresent {
isListSheetPresented = true
isSheetPresented = true
}
}

func presentLocalizedFlowAsPageView() {
isLocalizedPageViewPresented = true
}

func presentLocalizedFlowAsSlideshow() {
isLocalizedSlideshowPresented = true
}

func presentToolbarPopover() {
Onboarding.demoToolbarPopover.tryPresent {
isToolbarPopoverPresented = true
Expand All @@ -236,8 +235,6 @@ private extension ContentView {
}
}



#Preview {

ContentView()
Expand Down
Loading

0 comments on commit bd9c1a4

Please sign in to comment.