Skip to content

Commit

Permalink
add custom indicator demo
Browse files Browse the repository at this point in the history
  • Loading branch information
HeathWang committed Sep 4, 2019
1 parent c461b85 commit caccc28
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 5 deletions.
2 changes: 1 addition & 1 deletion HWPanModal.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'HWPanModal'
s.version = '0.3.5'
s.version = '0.3.6'
s.summary = 'HWPanModal is used to present controller and drag to dismiss.'

# This description is used to generate tags and improve search results.
Expand Down
8 changes: 8 additions & 0 deletions HWPanModal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
7EA0F61A230D63D300ED20D2 /* HWShareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EA0F5FD230D63D300ED20D2 /* HWShareViewController.m */; };
7EA0F61B230D63D300ED20D2 /* HWViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EA0F5FE230D63D300ED20D2 /* HWViewController.m */; };
7EB5E92223169CB600CDB543 /* AlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EB5E92123169CB600CDB543 /* AlertController.swift */; };
7EEF4686231F8F23006F5997 /* CustomIndicatorController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EEF4685231F8F23006F5997 /* CustomIndicatorController.swift */; };
7EEF4688231F917B006F5997 /* IndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EEF4687231F917B006F5997 /* IndicatorView.swift */; };
B8CF44011F90CAC000389BFE /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B8CF43F71F90CAC000389BFE /* AppDelegate.m */; };
B8CF44021F90CAC000389BFE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B8CF43F81F90CAC000389BFE /* Assets.xcassets */; };
B8CF44031F90CAC000389BFE /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B8CF43F91F90CAC000389BFE /* LaunchScreen.storyboard */; };
Expand Down Expand Up @@ -182,6 +184,8 @@
7EA0F5FF230D63D300ED20D2 /* HWViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HWViewController.h; sourceTree = "<group>"; };
7EB5E92123169CB600CDB543 /* AlertController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertController.swift; sourceTree = "<group>"; };
7ECB23932310C522009C9A62 /* KVOController.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = KVOController.framework; path = Carthage/Checkouts/KVOController.framework; sourceTree = "<group>"; };
7EEF4685231F8F23006F5997 /* CustomIndicatorController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomIndicatorController.swift; sourceTree = "<group>"; };
7EEF4687231F917B006F5997 /* IndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IndicatorView.swift; sourceTree = "<group>"; };
AAD6968C508B3328E47CD906 /* Pods-HWPanModalDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HWPanModalDemo.debug.xcconfig"; path = "Target Support Files/Pods-HWPanModalDemo/Pods-HWPanModalDemo.debug.xcconfig"; sourceTree = "<group>"; };
B7169DDD6D3C823664D309DE /* Pods-SwiftDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftDemo.release.xcconfig"; path = "Target Support Files/Pods-SwiftDemo/Pods-SwiftDemo.release.xcconfig"; sourceTree = "<group>"; };
B8CF43C01F90C2C500389BFE /* HWPanModalDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HWPanModalDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -291,6 +295,8 @@
7E20ABBA231F8EA7005941C5 /* Indicator */ = {
isa = PBXGroup;
children = (
7EEF4685231F8F23006F5997 /* CustomIndicatorController.swift */,
7EEF4687231F917B006F5997 /* IndicatorView.swift */,
);
path = Indicator;
sourceTree = "<group>";
Expand Down Expand Up @@ -909,10 +915,12 @@
7E20ABB7231F6B37005941C5 /* ColorBlockController.swift in Sources */,
7E20ABB9231F8B21005941C5 /* BlurController.swift in Sources */,
7E8F6E8123162B3A00D9C897 /* DemoType.swift in Sources */,
7EEF4686231F8F23006F5997 /* CustomIndicatorController.swift in Sources */,
7E20ABA4231E7A5D005941C5 /* GroupController.swift in Sources */,
7E20ABA9231F562C005941C5 /* MyNavigationController.swift in Sources */,
7EB5E92223169CB600CDB543 /* AlertController.swift in Sources */,
7E300AE1230EB51C003FBFE7 /* ViewController.swift in Sources */,
7EEF4688231F917B006F5997 /* IndicatorView.swift in Sources */,
7E20ABB2231F5FD1005941C5 /* AutoHandleTextInputController.swift in Sources */,
7E8F6E7F231626CF00D9C897 /* BasicViewController.swift in Sources */,
7E20ABB4231F621D005941C5 /* InputTableViewCell.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- HWPanModal (0.3.5):
- HWPanModal (0.3.6):
- KVOController
- KVOController (1.2.0)
- Masonry (1.1.0)
Expand All @@ -21,7 +21,7 @@ EXTERNAL SOURCES:
:path: "./"

SPEC CHECKSUMS:
HWPanModal: 73fd97eaca258edff9eac6b0d1314cea4f3e71a9
HWPanModal: da3eebd8e97914025bb472c958ff9fd0b9d14ef8
KVOController: d72ace34afea42468329623b3379ab3cd1d286b6
Masonry: 678fab65091a9290e40e2832a55e7ab731aad201
SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// CustomIndicatorController.swift
// SwiftDemo
//
// Created by heath wang on 2019/9/4.
// Copyright © 2019 wangcongling. All rights reserved.
//

import Foundation
import UIKit
import HWPanModal

enum IndicatorStyle {
case changeColor, text, immobile
}

class IndicatorPopViewController: UIViewController {

private let style: IndicatorStyle

init(style: IndicatorStyle) {
self.style = style
super.init(nibName: nil, bundle: nil)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor(displayP3Red: 0, green: 1, blue: 8, alpha: 1)
}

override func longFormHeight() -> PanModalHeight {
return PanModalHeight(type: .topInset, height: 44)
}

override func customIndicatorView() -> (UIView & HWPanModalIndicatorProtocol)? {
switch style {
case .changeColor:
let indicatorView = HWPanIndicatorView()
indicatorView.indicatorColor = view.backgroundColor!
return indicatorView
case .text:
return TextIndicatorView()
case .immobile:
return ImmobileIndicatorView()
}
}

}
88 changes: 88 additions & 0 deletions SwiftDemo/ControllerExample/Indicator/IndicatorView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// IndicatorView.swift
// SwiftDemo
//
// Created by heath wang on 2019/9/4.
// Copyright © 2019 wangcongling. All rights reserved.
//

import Foundation
import UIKit
import HWPanModal

class TextIndicatorView: UIView, HWPanModalIndicatorProtocol {

lazy var stateLabel: UILabel = {
let label = UILabel()
label.textAlignment = .center
label.font = UIFont.systemFont(ofSize: 14)
label.textColor = UIColor.darkText
return label
}()

override init(frame: CGRect) {
super.init(frame: frame)

addSubview(stateLabel)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

extension TextIndicatorView {

func didChange(to state: HWIndicatorState) {
switch state {
case .normal:
stateLabel.textColor = .white
stateLabel.text = "Please pull down to dismiss"
case .pull:
stateLabel.textColor = UIColor(displayP3Red: 1, green: 0.200, blue: 0, alpha: 1)
stateLabel.text = "Keep pull down to dismiss"
default: break
}

}

func indicatorSize() -> CGSize {
return CGSize(width: 200, height: 18)
}

func setupSubviews() {
stateLabel.frame = bounds
}
}

class ImmobileIndicatorView: UIView {

lazy var lineView: UIView = {
let line = UIView()
line.backgroundColor = UIColor.lightGray
line.layer.cornerRadius = 4
return line
}()

override init(frame: CGRect) {
super.init(frame: frame)
addSubview(lineView)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

extension ImmobileIndicatorView: HWPanModalIndicatorProtocol {

func didChange(to state: HWIndicatorState) {}

func indicatorSize() -> CGSize {
return CGSize(width: 45, height: 8)
}

func setupSubviews() {
lineView.frame = CGRect(x: 0, y: 0, width: indicatorSize().width, height: indicatorSize().height)
}
}
14 changes: 13 additions & 1 deletion SwiftDemo/Model/DemoType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extension DemoRowInfo {
enum DemoList {
case home
case app
case indicator
}

enum Action {
Expand All @@ -46,8 +47,12 @@ struct DemoCell: DemoRowInfo {
let vc = ViewController()
vc.demoType = .app
let app = DemoCell(string: "App Demo", rowVC: vc, action: .push)

let indicatorVC = ViewController()
indicatorVC.demoType = .indicator
let indicator = DemoCell(string: "Custom Indicator", rowVC: indicatorVC, action: .push)

let blur = DemoCell(string: "Blur Background", rowVC: ColorBlocksViewController(), action: .push)
let indicator = DemoCell(string: "Custom Indicator", rowVC: BasicViewController(), action: .push)
let keyboard = DemoCell(string: "Auto Handle Keyboard", rowVC: InputTableViewController())
let basic = DemoCell(string: "Basic", rowVC: BasicViewController())
let alert = DemoCell(string: "Alert", rowVC: AlertController())
Expand All @@ -67,4 +72,11 @@ struct DemoCell: DemoRowInfo {
let jd = DemoCell(string: "Shopping - JD", rowVC: BasicViewController())
return [zhihu, picker, share, jd]
}

static func indicatorCells() -> [DemoCell] {
let color = DemoCell(string: "Custom Default Indicator Color", rowVC: IndicatorPopViewController(style: .changeColor))
let text = DemoCell(string: "A Text Indicator View", rowVC: IndicatorPopViewController(style: .text))
let immo = DemoCell(string: "Immobile Indicator View", rowVC: IndicatorPopViewController(style: .immobile))
return [color, text, immo]
}
}
7 changes: 6 additions & 1 deletion SwiftDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
title = "Swift Example"

if demoType == .home {
dataSource = DemoCell.homeDemoCells()
title = "Swift Example"
} else if demoType == .app {
dataSource = DemoCell.appDemoCells()
title = "App Example"
} else if demoType == .indicator {
dataSource = DemoCell.indicatorCells()
title = "Indicator Example"
}

view.addSubview(tableView)
Expand Down

0 comments on commit caccc28

Please sign in to comment.