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

anchor position use offset after passing view. #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions spotlight/src/main/java/com/takusemba/spotlight/SpotlightView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ internal class SpotlightView @JvmOverloads constructor(
addView(target.overlay, MATCH_PARENT, MATCH_PARENT)
this.target = target.apply {
// adjust anchor in case where custom container is set.
val location = IntArray(2)
getLocationInWindow(location)
val offset = PointF(location[0].toFloat(), location[1].toFloat())
anchor.offset(-offset.x, -offset.y)
if (isNeedOffset) {
val location = IntArray(2)
getLocationInWindow(location)
val offset = PointF(location[0].toFloat(), location[1].toFloat())
anchor.offset(-offset.x, -offset.y)
}
}
this.shapeAnimator?.removeAllListeners()
this.shapeAnimator?.removeAllUpdateListeners()
Expand Down
4 changes: 4 additions & 0 deletions spotlight/src/main/java/com/takusemba/spotlight/Target.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.takusemba.spotlight.shape.Shape
* Target represents the spot that Spotlight will cast.
*/
class Target(
var isNeedOffset: Boolean = false,
val anchor: PointF,
val shape: Shape,
val effect: Effect,
Expand All @@ -24,6 +25,7 @@ class Target(
*/
class Builder {

private var isNeedOffset: Boolean = false
private var anchor: PointF = DEFAULT_ANCHOR
private var shape: Shape = DEFAULT_SHAPE
private var effect: Effect = DEFAULT_EFFECT
Expand All @@ -38,6 +40,7 @@ class Target(
view.getLocationInWindow(location)
val x = location[0] + view.width / 2f
val y = location[1] + view.height / 2f
isNeedOffset = true
setAnchor(x, y)
}

Expand Down Expand Up @@ -84,6 +87,7 @@ class Target(
}

fun build() = Target(
isNeedOffset = isNeedOffset,
anchor = anchor,
shape = shape,
effect = effect,
Expand Down