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

Fix SiblingConstraint Crash: Add Size check before getting child #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ open class SiblingConstraint @JvmOverloads constructor(
val index = component.parent.children.indexOf(component)

if (alignOpposite) {
if (index == 0) return component.parent.getRight() - component.getWidth()
val sibling = component.parent.children[index - 1]
return getLeftmostPoint(sibling, component.parent, index) - component.getWidth() - padding
if (index > 0) {
val sibling = component.parent.children[index - 1]
return getLeftmostPoint(sibling, component.parent, index) - component.getWidth() - padding
} else {
return component.parent.getRight() - component.getWidth()
}
} else {
if (index == 0) return component.parent.getLeft()
val sibling = component.parent.children[index - 1]
return getRightmostPoint(sibling, component.parent, index) + padding
if (index > 0) {
val sibling = component.parent.children[index - 1]
return getRightmostPoint(sibling, component.parent, index) + padding
} else {
return component.parent.getLeft()
}
}
}

Expand All @@ -51,13 +57,19 @@ open class SiblingConstraint @JvmOverloads constructor(
val index = component.parent.children.indexOf(component)

if (alignOpposite) {
if (index == 0) return component.parent.getBottom() - component.getHeight()
val sibling = component.parent.children[index - 1]
return getHighestPoint(sibling, component.parent, index) - component.getHeight() - padding
if (index > 0) {
val sibling = component.parent.children[index - 1]
return getHighestPoint(sibling, component.parent, index) - component.getHeight() - padding
} else {
return component.parent.getBottom() - component.getHeight()
}
} else {
if (index == 0) return component.parent.getTop()
val sibling = component.parent.children[index - 1]
return getLowestPoint(sibling, component.parent, index) + padding
if (index > 0) {
val sibling = component.parent.children[index - 1]
return getLowestPoint(sibling, component.parent, index) + padding
} else {
return component.parent.getTop()
}
}
}

Expand Down Expand Up @@ -188,4 +200,4 @@ open class SiblingConstraint @JvmOverloads constructor(
val index = component.parent.children.indexOf(component)
return if (index == 0 && constrainTo == null) 0f else padding
}
}
}