Skip to content

Commit cc1e44f

Browse files
authored
Merge pull request #94 from Yalantis/develop
Develop
2 parents 2e28534 + 7c27eef commit cc1e44f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/src/main/java/com/yalantis/contextmenu/lib/ContextMenuDialogFragment.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ open class ContextMenuDialogFragment : DialogFragment() {
4646
if (menuParams.isClosableOutside) {
4747
rootRelativeLayout.setOnClickListener {
4848
if (isAdded) {
49-
dismissAllowingStateLoss()
49+
dropDownMenuAdapter.closeOutside()
5050
}
5151
}
5252
}
@@ -65,6 +65,10 @@ open class ContextMenuDialogFragment : DialogFragment() {
6565
).apply {
6666
setAnimationDuration(menuParams.animationDuration)
6767

68+
onCloseOutsideClickListener = { _ ->
69+
close()
70+
}
71+
6872
onItemClickListener = { view ->
6973
val position = (view.parent as ViewGroup).indexOfChild(view)
7074
menuItemClickListener(view, position)

lib/src/main/java/com/yalantis/contextmenu/lib/MenuAdapter.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ open class MenuAdapter(
1717
private val gravity: MenuGravity
1818
) {
1919

20+
var onCloseOutsideClickListener: (view: View) -> Unit = {}
2021
var onItemClickListener: (view: View) -> Unit = {}
2122
var onItemLongClickListener: (view: View) -> Unit = {}
2223
private var onItemClickListenerCalled: (view: View) -> Unit = {}
@@ -68,6 +69,13 @@ open class MenuAdapter(
6869
}
6970
}
7071

72+
fun closeOutside() {
73+
onItemClickListenerCalled = onCloseOutsideClickListener
74+
menuWrapper.getChildAt(FIRST_CHILD_INDEX)?.let {
75+
viewClicked(it)
76+
}
77+
}
78+
7179
fun getItemCount() = menuObjects.size
7280

7381
private fun getLastItemPosition() = getItemCount() - 1
@@ -204,12 +212,12 @@ open class MenuAdapter(
204212
return AnimatorSet().apply {
205213
duration = animationDurationMillis
206214
startDelay = 0
215+
interpolator = HesitateInterpolator()
207216

208217
playTogether(
209218
AnimatorSet().apply { playSequentially(textAnimations) },
210219
AnimatorSet().apply { playSequentially(imageAnimations) }
211220
)
212-
setInterpolator(HesitateInterpolator())
213221
onAnimationEnd { toggleIsAnimationRun() }
214222
}
215223
}
@@ -403,5 +411,7 @@ open class MenuAdapter(
403411
companion object {
404412

405413
const val ANIMATION_DURATION_MILLIS = 100L
414+
415+
private const val FIRST_CHILD_INDEX = 0
406416
}
407417
}

0 commit comments

Comments
 (0)