Skip to content

Commit

Permalink
feat: Improve UX when forcing align center
Browse files Browse the repository at this point in the history
Sleep 1 second after forcing align center
Add tapic engine feedback
  • Loading branch information
Yingtao Guo authored and Yingtao Guo committed May 11, 2021
1 parent 3da68be commit a49ba58
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Example/InchwormExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1110;
LastUpgradeCheck = 1110;
LastUpgradeCheck = 1250;
ORGANIZATIONNAME = Echo;
TargetAttributes = {
5F732C0D23579D89008B53DA = {
Expand Down Expand Up @@ -260,6 +260,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -320,6 +321,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down
12 changes: 6 additions & 6 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ PODS:
- Inchworm (0.1)

DEPENDENCIES:
- Inchworm
- Inchworm (from `../`)

SPEC REPOS:
trunk:
- Inchworm
EXTERNAL SOURCES:
Inchworm:
:path: "../"

SPEC CHECKSUMS:
Inchworm: 116adb753cce2e9e1562eddedc40f41968e03530

PODFILE CHECKSUM: 146d738dd50086fbb909ca09899271ab7a8f331e
PODFILE CHECKSUM: a7def8051ef5ab440125446435f200dc6b359121

COCOAPODS: 1.8.4
COCOAPODS: 1.10.1
1 change: 1 addition & 0 deletions Inchworm/Source/Inchworm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public func createSlider(config: Config = Config(),
public var indicatorSpan: CGFloat = 50
public var slideRulerSpan: CGFloat = 50
public var spaceBetweenIndicatorAndSlideRule: CGFloat = 10
public var forceAlignCenterFeedback = true

public override init() {

Expand Down
25 changes: 22 additions & 3 deletions Inchworm/Source/SlideRuler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protocol SlideRulerDelegate {
}

class SlideRuler: UIView {

var forceAlignCenterFeedback = true
let pointer = CALayer()
let centralDot = CAShapeLayer()
let slider = UIScrollView()
Expand Down Expand Up @@ -188,10 +188,29 @@ extension SlideRuler: UIScrollViewDelegate {

let limit = frame.width / CGFloat((scaleBarNumber - 1) * 2)
if abs(slider.contentOffset.x - frame.width / 2) < limit && abs(speed.x) < 10.0 {

if !reset {
reset = true
let offset = CGPoint(x: frame.width / 2, y: 0)
scrollView.setContentOffset(offset, animated: false)

if forceAlignCenterFeedback {
let generator = UIImpactFeedbackGenerator(style: .medium)
generator.impactOccurred()
}

func forceAlignCenter() {
let offset = CGPoint(x: frame.width / 2, y: 0)
scrollView.setContentOffset(offset, animated: false)
delegate?.didGetOffsetRatio(from: self, offsetRatio: 0)
}

DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
forceAlignCenter()
}

forceAlignCenter()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.11) {
usleep(1000000)
}
}
} else {
reset = false
Expand Down
1 change: 1 addition & 0 deletions Inchworm/Source/Slider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class Slider: UIView {
func createSlideRuler() {
slideRuler = SlideRuler(frame: CGRect(x: 0, y: baseContainer.frame.height / 2, width: baseContainer.frame.width, height: baseContainer.frame.height - config.slideRulerSpan))
slideRuler.delegate = self
slideRuler.forceAlignCenterFeedback = config.forceAlignCenterFeedback
}

func handleConfigChange() {
Expand Down

0 comments on commit a49ba58

Please sign in to comment.