Skip to content

Commit

Permalink
allowing tapThrough for buttons, barbuttonitems, and tabbaritems
Browse files Browse the repository at this point in the history
  • Loading branch information
GPryan committed Oct 4, 2019
1 parent 215324a commit 9351eff
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions MaterialShowcase/MaterialShowcase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public class MaterialShowcase: UIView {
var targetRippleView: UIView!
var targetCopyView: UIView!
var instructionView: MaterialShowcaseInstructionView!


var onTapThrough: (() -> Void)?

// MARK: Public Properties

Expand Down Expand Up @@ -125,19 +126,36 @@ extension MaterialShowcase {
}

/// Sets a UIBarButtonItem as target
@objc public func setTargetView(barButtonItem: UIBarButtonItem) {
@objc public func setTargetView(button: UIButton, tapThrough: Bool = false) {
targetView = button
let tintColor = button.titleColor(for: .normal)
targetTintColor = tintColor
backgroundPromptColor = tintColor
if tapThrough {
onTapThrough = { button.sendActions(for: .touchUpInside) }
}
}

/// Sets a UIBarButtonItem as target
@objc public func setTargetView(barButtonItem: UIBarButtonItem, tapThrough: Bool = false) {
if let view = (barButtonItem.value(forKey: "view") as? UIView)?.subviews.first {
targetView = view
if tapThrough {
onTapThrough = { _ = barButtonItem.target?.perform(barButtonItem.action, with: nil) }
}
}
}

/// Sets a UITabBar Item as target
@objc public func setTargetView(tabBar: UITabBar, itemIndex: Int) {
@objc public func setTargetView(tabBar: UITabBar, itemIndex: Int, tapThrough: Bool = false) {
let tabBarItems = orderedTabBarItemViews(of: tabBar)
if itemIndex < tabBarItems.count {
targetView = tabBarItems[itemIndex]
targetTintColor = tabBar.tintColor
backgroundPromptColor = tabBar.tintColor
if tapThrough {
onTapThrough = { tabBar.selectedItem = tabBar.items?[itemIndex] }
}
} else {
print ("The tab bar item index is out of range")
}
Expand Down Expand Up @@ -504,6 +522,9 @@ extension MaterialShowcase {
delegate?.showCaseDidDismiss?(showcase: self, didTapTarget: didTapTarget)
}

if didTapTarget {
onTapThrough?()
}
}

private func recycleSubviews() {
Expand Down

0 comments on commit 9351eff

Please sign in to comment.