Skip to content

Commit

Permalink
Merge pull request #94 from Yalantis/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
PenzK authored Jan 31, 2019
2 parents 2e28534 + 7c27eef commit cc1e44f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ open class ContextMenuDialogFragment : DialogFragment() {
if (menuParams.isClosableOutside) {
rootRelativeLayout.setOnClickListener {
if (isAdded) {
dismissAllowingStateLoss()
dropDownMenuAdapter.closeOutside()
}
}
}
Expand All @@ -65,6 +65,10 @@ open class ContextMenuDialogFragment : DialogFragment() {
).apply {
setAnimationDuration(menuParams.animationDuration)

onCloseOutsideClickListener = { _ ->
close()
}

onItemClickListener = { view ->
val position = (view.parent as ViewGroup).indexOfChild(view)
menuItemClickListener(view, position)
Expand Down
12 changes: 11 additions & 1 deletion lib/src/main/java/com/yalantis/contextmenu/lib/MenuAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ open class MenuAdapter(
private val gravity: MenuGravity
) {

var onCloseOutsideClickListener: (view: View) -> Unit = {}
var onItemClickListener: (view: View) -> Unit = {}
var onItemLongClickListener: (view: View) -> Unit = {}
private var onItemClickListenerCalled: (view: View) -> Unit = {}
Expand Down Expand Up @@ -68,6 +69,13 @@ open class MenuAdapter(
}
}

fun closeOutside() {
onItemClickListenerCalled = onCloseOutsideClickListener
menuWrapper.getChildAt(FIRST_CHILD_INDEX)?.let {
viewClicked(it)
}
}

fun getItemCount() = menuObjects.size

private fun getLastItemPosition() = getItemCount() - 1
Expand Down Expand Up @@ -204,12 +212,12 @@ open class MenuAdapter(
return AnimatorSet().apply {
duration = animationDurationMillis
startDelay = 0
interpolator = HesitateInterpolator()

playTogether(
AnimatorSet().apply { playSequentially(textAnimations) },
AnimatorSet().apply { playSequentially(imageAnimations) }
)
setInterpolator(HesitateInterpolator())
onAnimationEnd { toggleIsAnimationRun() }
}
}
Expand Down Expand Up @@ -403,5 +411,7 @@ open class MenuAdapter(
companion object {

const val ANIMATION_DURATION_MILLIS = 100L

private const val FIRST_CHILD_INDEX = 0
}
}

1 comment on commit cc1e44f

@kdwayne22
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k

Please sign in to comment.