-
Notifications
You must be signed in to change notification settings - Fork 59
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
Add flag to dim background behind popup #43
Conversation
@@ -89,6 +89,12 @@ class MaterialRecyclerViewPopupWindow( | |||
|
|||
private val contextThemeWrapper: Context | |||
|
|||
private val windowManager: WindowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe initialize this lazily via by lazy { }
since this is only used if dimming is enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Done.
@@ -105,6 +111,8 @@ class MaterialRecyclerViewPopupWindow( | |||
|
|||
dropDownHorizontalOffset = a.getDimensionPixelOffset(androidx.appcompat.R.styleable.ListPopupWindow_android_dropDownHorizontalOffset, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we add a new styleable
I think it would be better not to mix androidx.appcompat.R.styleable.ListPopupWindow_XXX
and R.styleable.ListPopupWindow_
which might be a bit confusing.
Therefore could you change:
val a = context.obtainStyledAttributes(null, androidx.appcompat.R.styleable.ListPopupWindow, 0, defStyleRes)
dropDownHorizontalOffset = a.getDimensionPixelOffset(androidx.appcompat.R.styleable.ListPopupWindow_android_dropDownHorizontalOffset, 0)
dropDownVerticalOffset = a.getDimensionPixelOffset(androidx.appcompat.R.styleable.ListPopupWindow_android_dropDownVerticalOffset, 0)
to:
val a = context.obtainStyledAttributes(null, R.styleable.ListPopupWindow, 0, defStyleRes)
dropDownHorizontalOffset = a.getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownHorizontalOffset, 0)
dropDownVerticalOffset = a.getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownVerticalOffset, 0)
please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable. I've went a bit further and also renamed the styleable
to MaterialRecyclerViewPopupWindow
so it'll match the name of class.
@@ -105,6 +111,8 @@ class MaterialRecyclerViewPopupWindow( | |||
|
|||
dropDownHorizontalOffset = a.getDimensionPixelOffset(androidx.appcompat.R.styleable.ListPopupWindow_android_dropDownHorizontalOffset, 0) | |||
dropDownVerticalOffset = a.getDimensionPixelOffset(androidx.appcompat.R.styleable.ListPopupWindow_android_dropDownVerticalOffset, 0) | |||
backgroundDimEnabled = a.getBoolean(R.styleable.ListPopupWindow_android_backgroundDimEnabled, false) | |||
backgroundDimAmount = a.getFloat(R.styleable.ListPopupWindow_android_backgroundDimAmount, 0.3f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move 0.3f
to a constant inside the companion object
e.g. private const val DEFAULT_BACKGROUND_DIM_AMOUNT = 0.3f
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -359,4 +371,12 @@ class MaterialRecyclerViewPopupWindow( | |||
|
|||
return menuWidth | |||
} | |||
|
|||
private fun addBackgroundDimming() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, didn't know that adding a dim can be done with few lines of code like this!
Can be enabled via style attribute `android:backgroundDimEnabled` and customized with `android:backgroundDimAmount` where amount can be a float number betwen 0.0 and 1.0.
I've made also an additional change and moved the new styles to sample module since they aren't used in library. |
Can be enabled via style attribute
android:backgroundDimEnabled
and customized withandroid:backgroundDimAmount
where amount can be a float number betwen0.0
and1.0
.Example