Skip to content

Commit

Permalink
Properly implemented default layout manager. Improved performance
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasMata committed Oct 20, 2020
1 parent d9f94f1 commit 4384c70
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 50 deletions.
16 changes: 0 additions & 16 deletions spotlight/src/main/java/com/matadesigns/spotlight/SpotlightView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import android.widget.FrameLayout
import android.widget.TextView
import androidx.annotation.LayoutRes
import androidx.core.graphics.toRect
import androidx.core.view.marginBottom
import androidx.core.view.marginEnd
import androidx.core.view.marginStart
import androidx.core.view.marginTop
import androidx.fragment.app.Fragment
import com.matadesigns.spotlight.abstraction.*
import com.matadesigns.spotlight.config.SpotlightDismissType
Expand Down Expand Up @@ -173,7 +169,6 @@ open class SpotlightView @JvmOverloads constructor(
}

override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
_thisRect.set(
left,
top,
Expand All @@ -183,17 +178,6 @@ open class SpotlightView @JvmOverloads constructor(
layoutViews()
}

override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
_thisRect.set(
_thisRect.left,
_thisRect.top,
_thisRect.left + w,
_thisRect.top + h
)
postInvalidate()
}

override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)
val targetView = targetView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,6 @@ class DefaultLayoutManager : SpotlightLayoutManager {
message.measure(widthMeasureSpec, heightMeasureSpec)
messageWidth = message.measuredWidth
messageHeight = message.measuredHeight
if (originalMessageHeight != messageHeight || originalMessageWidth != messageWidth) {
val layoutParams = message.layoutParams
layoutParams.width = messageWidth
layoutParams.height = messageHeight
message.layoutParams = layoutParams
return
}
} else {
messageHeight = originalMessageHeight
messageWidth = originalMessageWidth
Expand Down Expand Up @@ -354,21 +347,9 @@ class DefaultLayoutManager : SpotlightLayoutManager {

repositionInside(rootRect, messageRect)

indicator.x = indicatorRect.left.toFloat()
indicator.y = indicatorRect.top.toFloat()
val indicatorWidth = indicatorRect.width()
val indicatorHeight = indicatorRect.height()
val indicatorLayoutParams = indicator.layoutParams
if (indicatorLayoutParams.width != indicatorWidth ||
indicatorLayoutParams.height != indicatorHeight
) {
indicatorLayoutParams.width = indicatorWidth
indicatorLayoutParams.height = indicatorHeight
indicator.layoutParams = indicatorLayoutParams
}
indicator.layout(indicatorRect.left,indicatorRect.top,indicatorRect.right,indicatorRect.bottom)

message.x = messageRect.left.toFloat()
message.y = messageRect.top.toFloat()
message.layout(messageRect.left,messageRect.top,messageRect.right,messageRect.bottom)
}

private fun repositionInside(parent: Rect, child: Rect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,6 @@ open class SimpleIndicatorView @JvmOverloads constructor(
_innerDotPaint.isAntiAlias = true
}

override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
val start = getLineStart()
_start.set(start)
_end.set(start)
}

override fun startAnimation() {
val start = getLineStart()
_start.set(start)
Expand All @@ -118,19 +111,18 @@ open class SimpleIndicatorView @JvmOverloads constructor(
_dotInnerRadius = animatedValue
postInvalidate()
}
val lineAnimator: ValueAnimator
when (spotlightGravity) {
val lineAnimator = when (spotlightGravity) {
SpotlightMessageGravity.right -> {
lineAnimator = ValueAnimator.ofFloat(_end.x, actualEnd.x + dotDiameter)
ValueAnimator.ofFloat(_end.x, actualEnd.x + dotDiameter)
}
SpotlightMessageGravity.left -> {
lineAnimator = ValueAnimator.ofFloat(_end.x, actualEnd.x - dotDiameter)
ValueAnimator.ofFloat(_end.x, actualEnd.x - dotDiameter)
}
SpotlightMessageGravity.bottom -> {
lineAnimator = ValueAnimator.ofFloat(_end.y, actualEnd.y + dotDiameter)
ValueAnimator.ofFloat(_end.y, actualEnd.y + dotDiameter)
}
SpotlightMessageGravity.top -> {
lineAnimator = ValueAnimator.ofFloat(_end.y, actualEnd.y - dotDiameter)
ValueAnimator.ofFloat(_end.y, actualEnd.y - dotDiameter)
}
}

Expand Down

0 comments on commit 4384c70

Please sign in to comment.