Skip to content

Commit

Permalink
Search RecyclerView limit height to 300dp. (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanniktech authored Apr 27, 2022
1 parent 84c391d commit 72ebb72
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal class EmojiSearchPopup(
val resources = context.resources
recyclerView.measure(
MeasureSpec.makeMeasureSpec(rootView.width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(resources.getDimensionPixelSize(R.dimen.emoji_search_max_height), MeasureSpec.AT_MOST),
0, // Internals will already limit this.
)

val height = recyclerView.measuredHeight
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.vanniktech.emoji

import android.content.Context
import android.util.AttributeSet
import androidx.recyclerview.widget.RecyclerView

internal class MaxHeightSearchRecyclerView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
) : RecyclerView(context, attrs) {
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(
widthMeasureSpec,
MeasureSpec.makeMeasureSpec(context.resources.getDimensionPixelSize(R.dimen.emoji_search_max_height), MeasureSpec.AT_MOST),
)
}
}
3 changes: 2 additions & 1 deletion emoji/src/main/res/layout/emoji_dialog_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
tools:ignore="LabelFor,UnusedAttribute"
tools:text="My brilliant name"
/>
<androidx.recyclerview.widget.RecyclerView
<com.vanniktech.emoji.MaxHeightSearchRecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
/>
</LinearLayout>
2 changes: 1 addition & 1 deletion emoji/src/main/res/layout/emoji_popup_search.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
<com.vanniktech.emoji.MaxHeightSearchRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/recyclerView"
android:layout_width="match_parent"
Expand Down

0 comments on commit 72ebb72

Please sign in to comment.