Skip to content

Commit

Permalink
Added passTouchesToSuperview parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
yuravake committed Dec 23, 2018
1 parent 77fe67b commit 2f3f0ba
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Cosmos/CosmosSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public struct CosmosSettings {

/// When `true` the star fill level is updated when user touches the cosmos view. When `false` the Cosmos view only shows the rating and does not act as the input control.
public var updateOnTouch = CosmosDefaultSettings.updateOnTouch

/// Passes touches to superview
public var passTouchesToSuperview = true
}


18 changes: 12 additions & 6 deletions Cosmos/CosmosView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,18 @@ Shows: ★★★★☆ (123)

/// Overriding the function to detect the first touch gesture.
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
if settings.passTouchesToSuperview {
super.touchesBegan(touches, with: event)
}
guard let location = touchLocationFromBeginningOfRating(touches) else { return }
onDidTouch(location)
}

/// Overriding the function to detect touch move.
open override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
if settings.passTouchesToSuperview {
super.touchesMoved(touches, with: event)
}
guard let location = touchLocationFromBeginningOfRating(touches) else { return }
onDidTouch(location)
}
Expand All @@ -278,8 +282,9 @@ Shows: ★★★★☆ (123)

/// Detecting event when the user lifts their finger.
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)

if settings.passTouchesToSuperview {
super.touchesEnded(touches, with: event)
}
didFinishTouchingCosmos?(rating)
}

Expand All @@ -290,8 +295,9 @@ Shows: ★★★★☆ (123)

*/
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)

if settings.passTouchesToSuperview {
super.touchesCancelled(touches, with: event)
}
didFinishTouchingCosmos?(rating)
}

Expand Down
21 changes: 15 additions & 6 deletions Distrib/CosmosDistrib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,9 @@ public struct CosmosSettings {

/// When `true` the star fill level is updated when user touches the cosmos view. When `false` the Cosmos view only shows the rating and does not act as the input control.
public var updateOnTouch = CosmosDefaultSettings.updateOnTouch

/// Passes touches to superview
public var passTouchesToSuperview = true
}


Expand Down Expand Up @@ -1408,14 +1411,18 @@ Shows: ★★★★☆ (123)

/// Overriding the function to detect the first touch gesture.
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
if settings.passTouchesToSuperview {
super.touchesBegan(touches, with: event)
}
guard let location = touchLocationFromBeginningOfRating(touches) else { return }
onDidTouch(location)
}

/// Overriding the function to detect touch move.
open override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
if settings.passTouchesToSuperview {
super.touchesMoved(touches, with: event)
}
guard let location = touchLocationFromBeginningOfRating(touches) else { return }
onDidTouch(location)
}
Expand All @@ -1433,8 +1440,9 @@ Shows: ★★★★☆ (123)

/// Detecting event when the user lifts their finger.
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)

if settings.passTouchesToSuperview {
super.touchesEnded(touches, with: event)
}
didFinishTouchingCosmos?(rating)
}

Expand All @@ -1445,8 +1453,9 @@ Shows: ★★★★☆ (123)

*/
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)

if settings.passTouchesToSuperview {
super.touchesCancelled(touches, with: event)
}
didFinishTouchingCosmos?(rating)
}

Expand Down

0 comments on commit 2f3f0ba

Please sign in to comment.