forked from aromajoin/material-showcase-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
92 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// MaterialShowCaseSequence.swift | ||
// MaterialShowcase | ||
// | ||
// Created by VB on 16.04.2019. | ||
// Copyright © 2019 Aromajoin. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public class MaterialShowcaseSequence { | ||
|
||
var showcaseArray : [MaterialShowcase] = [] | ||
var currentCase : Int = 0 | ||
var key : String? | ||
|
||
public func temp(_ showcase: MaterialShowcase) -> MaterialShowcaseSequence { | ||
showcaseArray.append(showcase) | ||
return self | ||
} | ||
public func start() { | ||
guard getUserState(key: self.key) else { | ||
return | ||
} | ||
showcaseArray.first?.show(completion: increase) | ||
} | ||
func increase() -> Void { | ||
self.currentCase += 1 | ||
} | ||
|
||
/// Set user show retry | ||
public func setKey(key : String? = nil) -> MaterialShowcaseSequence { | ||
guard key != nil else { | ||
return self | ||
} | ||
self.key = key | ||
return self | ||
} | ||
|
||
/// Remove user state | ||
public func removeUserState(key : String = MaterialKey._default.rawValue) { | ||
UserDefaults.standard.removeObject(forKey: key) | ||
} | ||
/// Remove user state | ||
func getUserState(key : String?) -> Bool { | ||
guard key != nil else { | ||
return false | ||
} | ||
return UserDefaults.standard.bool(forKey: key!) | ||
} | ||
public init() { } | ||
|
||
public func showCaseWillDismis() { | ||
guard self.showcaseArray.count > currentCase else { | ||
//last index | ||
UserDefaults.standard.set(true, forKey: key!) | ||
return | ||
} | ||
showcaseArray[currentCase].show(completion: self.increase) | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters