From 6aabc646b55636299695156b34bcb2d3cdfce71b Mon Sep 17 00:00:00 2001 From: Saurabh Verma Date: Sat, 21 Aug 2021 21:52:25 +0530 Subject: [PATCH] Issue 121 | Fixed : Multiple Times Anchor Adjustment Prevented --- .../java/com/takusemba/spotlight/SpotlightView.kt | 13 ++++++++----- .../src/main/java/com/takusemba/spotlight/Target.kt | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/spotlight/src/main/java/com/takusemba/spotlight/SpotlightView.kt b/spotlight/src/main/java/com/takusemba/spotlight/SpotlightView.kt index 02cf0ba..ddbe77b 100644 --- a/spotlight/src/main/java/com/takusemba/spotlight/SpotlightView.kt +++ b/spotlight/src/main/java/com/takusemba/spotlight/SpotlightView.kt @@ -114,11 +114,14 @@ internal class SpotlightView @JvmOverloads constructor( removeAllViews() 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 (!this.isAnchorAdjusted) { + // 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) + this.isAnchorAdjusted = true + } } this.shapeAnimator?.removeAllListeners() this.shapeAnimator?.removeAllUpdateListeners() diff --git a/spotlight/src/main/java/com/takusemba/spotlight/Target.kt b/spotlight/src/main/java/com/takusemba/spotlight/Target.kt index 4a16fc2..9f0b8e2 100644 --- a/spotlight/src/main/java/com/takusemba/spotlight/Target.kt +++ b/spotlight/src/main/java/com/takusemba/spotlight/Target.kt @@ -17,6 +17,10 @@ class Target( val overlay: View?, val listener: OnTargetListener? ) { + /** + * This variable is to prevent multiple times anchor adjustment. + */ + var isAnchorAdjusted: Boolean = false /** * [Builder] to build a [Target].