Skip to content

Commit

Permalink
arrow location bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdi-khosravi-sh committed Dec 12, 2021
1 parent 8e5d299 commit eb4e666
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ open class ArrowLayout(context: Context) : FrameLayout(context) {
val paint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)
private val arrowPath: Path = Path()
private val path: Path = Path()

open var animator: BaseAnimator? = null
open var touchAnimator: TouchAnimator? = null

open var pivotToArrow = true

private val targetLocation: IntArray = IntArray(2)
private var firstYAxis: Float = 0.0F
private var firstXAxis: Float = 0.0F
Expand All @@ -40,6 +37,7 @@ open class ArrowLayout(context: Context) : FrameLayout(context) {
private var drawStroke = false
var arrowEdge: Int = Gravity.NO_GRAVITY
private set
internal var orientation = ArrowPanel.ORIENTATION_HORIZONTAL or ArrowPanel.ORIENTATION_VERTICAL

var maxHeight: Int = -1
var maxWidth: Int = -1
Expand Down Expand Up @@ -170,6 +168,22 @@ open class ArrowLayout(context: Context) : FrameLayout(context) {
this.endHideAction = runnable
}

private fun adjustArrowPathHorizontal(targetWidth: Int) {
if ((x > targetLocation[0] && x < targetLocation[0] + targetWidth) or (x > targetLocation[0] + targetWidth / 2)) {
adjustArrowPath(Gravity.LEFT)
} else {
adjustArrowPath(Gravity.RIGHT)
}
}

private fun adjustArrowPathVertical() {
if (y + height <= targetLocation[1]) {
adjustArrowPath(Gravity.BOTTOM)
} else if (y >= targetLocation[1]) {
adjustArrowPath(Gravity.TOP)
}
}

private fun adjustPath() {
path.reset()

Expand All @@ -186,15 +200,15 @@ open class ArrowLayout(context: Context) : FrameLayout(context) {
if (drawArrow) {
if (syncArrowPath) {
targetView?.let { target ->
if (y + height <= targetLocation[1]) {
adjustArrowPath(Gravity.BOTTOM)
} else if (y >= targetLocation[1]) {
adjustArrowPath(Gravity.TOP)
if (orientation == ArrowPanel.ORIENTATION_HORIZONTAL) {
adjustArrowPathHorizontal(target.width)
} else if (orientation == ArrowPanel.ORIENTATION_VERTICAL) {
adjustArrowPathVertical()
} else {
if ((x > targetLocation[0] && x < targetLocation[0] + target.width) or (x > targetLocation[0] + target.width / 2)) {
adjustArrowPath(Gravity.LEFT)
if (height < target.height) {
adjustArrowPathHorizontal(target.width)
} else {
adjustArrowPath(Gravity.RIGHT)
adjustArrowPathVertical()
}
}
} ?: kotlin.run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ open class ArrowPanel(context: Context) : Panel(context) {
open var drawTargetView: Boolean = true
open var type: Int = TYPE_DECOR
open var orientation = ORIENTATION_HORIZONTAL or ORIENTATION_VERTICAL
set(value) {
field = value
arrowLayout.orientation = field
}
open var reusable = false

var gravity: Int = GRAVITY_AUTO
Expand Down

0 comments on commit eb4e666

Please sign in to comment.