Closed Tunous closed 5 years ago
The might be some issues in MaterialRecyclerViewPopupWindow#measureHeightOfChildrenCompat
. In theory it does invoke bindViewHolder
, but I've never really tested it with e.g. wrap_content
.
Most of that stuff was copied from DropDownListView
(pre-AndroidX version). I see there were some changed in AndroidX so maybe applying them might fix the issue.
I'll have a look.
I think I have a fix although I'll need to do more testing tomorrow (hopefully) to make sure this does not break something else. This is how it looks like after the fix:
Almost there. I just accidentally found that the height is also incorrect if you add vertical margin to custom items. It is calculated without taking it into account.
I can try to create a pull request for that tomorrow unless someone else will be quicker.
I don't have ideas how to fix that currently but calculation of height for the popup appears to work incorrectly when items can have dynamic height.
This can be easily reproduced with item that has long text applied in the
viewBoundCallback
block like I've done with below code:Sample
```patch diff --git a/sample/src/main/java/com/github/zawadz88/materialpopupmenu/sample/LightActivity.kt b/sample/src/main/java/com/github/zawadz88/materialpopupmenu/sample/LightActivity.kt index c1823d606dbf7d2d1d2a4cbff025bce15ff756d2..e6e5652772bc62f1e91584cb7321141d0d0a86d6 100644 --- a/sample/src/main/java/com/github/zawadz88/materialpopupmenu/sample/LightActivity.kt +++ b/sample/src/main/java/com/github/zawadz88/materialpopupmenu/sample/LightActivity.kt @@ -321,6 +321,10 @@ class LightActivity : AppCompatActivity() { } customItem { layoutResId = R.layout.view_custom_item_large + viewBoundCallback = { view -> + val textView: TextView = view.findViewById(R.id.customItemTextView) + textView.text = "Some long text that is applied later to see if height calculation indeed is incorrectly calculated due to this binding." + } } } } diff --git a/sample/src/main/res/layout/view_custom_item_large.xml b/sample/src/main/res/layout/view_custom_item_large.xml index 7223c7b5b7d2087b3dc02972de35a5686403ce01..4486a545636d298fad9ecf39ce87f1ede481eb34 100644 --- a/sample/src/main/res/layout/view_custom_item_large.xml +++ b/sample/src/main/res/layout/view_custom_item_large.xml @@ -1,24 +1,30 @@