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

TapThrough Functionality #112

Merged
merged 2 commits into from
Oct 5, 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
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
31 changes: 22 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Download](https://img.shields.io/cocoapods/v/MaterialShowcase.svg)](https://cocoapods.org/pods/MaterialShowcase)

**An elegant and beautiful tap showcase view for iOS apps based on Material Design Guidelines.**
**An elegant and beautiful tap showcase view for iOS apps based on Material Design Guidelines.**

| ![Screenshots](https://github.com/aromajoin/material-showcase-ios/blob/master/art/material-showcase.gif) | ![Screenshots](https://github.com/aromajoin/material-showcase-ios/blob/master/art/demo2.png) |
| ---------------------------------------- | ---------------------------------------- |
Expand All @@ -16,7 +16,7 @@
## Installation

### CocoaPods
You can install it by using CocoaPods. Please add the following line to your Podfile.
You can install it by using CocoaPods. Please add the following line to your Podfile.
```
pod 'MaterialShowcase'
```
Expand Down Expand Up @@ -56,7 +56,7 @@ In order to integrate the library into Object-C project, please follow the instr
**Note**: `showcase.show()` should be called after your views are placed correctly, for example inside UIViewController's `viewWillAppear()` or `viewDidAppear()` function. You **SHOULD NOT** call it inside `viewDidLoad()` because views have not laid down correctly yet, `showcase` can not calculate these views positions and it results in unexpected errors.

### Supported target views
There are several target view supported.
There are several target view supported.

```swift
// Any UIView
Expand All @@ -68,16 +68,29 @@ There are several target view supported.
// UItableViewCell
showcase.setTargetView(tableView: tableView, section: 0, row: 0)
```

### Enable TapThrough
By default, tapping a showcase's target does not perform it's predefined action. This can be overridden.

```swift
// UIButton
showcase.setTargetView(button: button, tapThrough: true)
// UIBarButtonItem
showcase.setTargetView(barButtonItem: barItem, tapThrough: true)
// UITabBar item
showcase.setTargetView(tabBar: tabBar, itemIndex: 0, tapThrough: true)
```

### Handle showcase status
```swift
// Right after showing.
showcase.show(completion: {
// You can save showcase state here
})

// To handle other behaviors when showcase is dismissing, delegate should be declared.
showcase.delegate = self

extension ViewController: MaterialShowcaseDelegate {
func showCaseWillDismiss(showcase: MaterialShowcase, didTapTarget: Bool) {
print("Showcase \(showcase.primaryText) will dismiss.")
Expand Down Expand Up @@ -129,7 +142,7 @@ You can define your own styles based on your app.
// Animation
showcase.aniComeInDuration = 0.5 // unit: second
showcase.aniGoOutDuration = 0.5 // unit: second
showcase.aniRippleScale = 1.5
showcase.aniRippleScale = 1.5
showcase.aniRippleColor = UIColor.white
showcase.aniRippleAlpha = 0.2
//...
Expand Down Expand Up @@ -175,8 +188,8 @@ extension ViewController: MaterialShowcaseDelegate {

For more information, please take a look at [sample app](/Sample).

If you have any issues or feedback, please visit [issue section](https://github.com/aromajoin/material-showcase-ios/issues).
Please feel free to create a pull request.
If you have any issues or feedback, please visit [issue section](https://github.com/aromajoin/material-showcase-ios/issues).
Please feel free to create a pull request.

## Third Party Bindings

Expand All @@ -189,6 +202,6 @@ For [NativeScript](https://nativescript.org) developers, you can use this librar
## FAQ
Please check the FAQ page [here](https://github.com/aromajoin/material-showcase-ios/wiki/FAQ).

## License
## License

`Material Showcase` is available under the Apache license. See the LICENSE file for more info.