Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added popTo(item:orDismiss:) #165

Merged
merged 1 commit into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,10 @@ The `BLTNItem` protocol exposes a `manager` property that is set when the item i

You can use it to interact with the presented bulletin. Call:

- `manager?.push(item:)` with a `BulletinItem` to present a new item
- `manager?.popItem()` to go back to the previous item
- `manager?.popToRootItem()` to go back to the first item
- `manager?.push(item:)` with a `BulletinItem` to present a new item
- `manager?.popTo(item:orDismiss:)` to go back to a specific item
- `manager?.dismissBulletin(animated:)` to dismiss the bulletin
- `manager?.displayNextItem()` to display the next item (see below)

Expand Down
34 changes: 34 additions & 0 deletions Sources/BLTNItemManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,40 @@ extension BLTNItemManager {

}

/**
* Removes items from the stack until a specific item is found.
* - parameter item: The item to seek.
* - parameter orDismiss: If true, dismiss bullein if not found. Otherwise popToRootItem()
*/

@objc public func popTo(item: BLTNItem, orDismiss: Bool) {

assertIsPrepared()
assertIsMainThread()

for index in 0..<itemsStack.count {

if itemsStack[index] === item {

self.currentItem = itemsStack[index]
shouldDisplayActivityIndicator = currentItem.shouldStartWithActivityIndicator
refreshCurrentItemInterface()

for removeIndex in (index+1..<itemsStack.count).reversed() {
let removeItem = itemsStack.remove(at: removeIndex)
tearDownItemsChain (startingAt: removeItem)
}
return
}
}

if item !== rootItem, orDismiss {
dismissBulletin(animated: true)
} else {
popToRootItem()
}
}

/**
* Removes all the items from the stack and displays the root item.
*/
Expand Down