Testing view in DecorView
This commit is contained in:
parent
ac62d632ed
commit
aeb9a8376c
4 changed files with 36 additions and 22 deletions
|
@ -5,7 +5,7 @@ import android.content.Context
|
|||
import android.graphics.Rect
|
||||
import android.util.AttributeSet
|
||||
import android.view.animation.AlphaAnimation
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.FrameLayout
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.github.wulkanowy.materialchipsinput.util.dpToPx
|
||||
|
@ -18,10 +18,8 @@ internal class DropdownListView : RecyclerView {
|
|||
|
||||
constructor(context: Context, attr: AttributeSet, defStyleAttr: Int) : super(context, attr, defStyleAttr)
|
||||
|
||||
fun fadeIn() {
|
||||
if (visibility == VISIBLE || parent !is MaterialChipInput) return
|
||||
|
||||
val chipInput = parent as MaterialChipInput
|
||||
fun fadeIn(chipInput: MaterialChipInput) {
|
||||
if (visibility == VISIBLE) return
|
||||
|
||||
val visibleRect = Rect().apply {
|
||||
rootView.getWindowVisibleDisplayFrame(this)
|
||||
|
@ -32,11 +30,12 @@ internal class DropdownListView : RecyclerView {
|
|||
chipInput.getLocationOnScreen(this)
|
||||
}
|
||||
|
||||
updateLayoutParams<LinearLayout.LayoutParams> {
|
||||
val defaultHeight = context.dpToPx(72f).toInt()
|
||||
updateLayoutParams<FrameLayout.LayoutParams> {
|
||||
val defaultHeight = context.dpToPx(144f).toInt()
|
||||
val calculatedHeight = visibleRect.height() - (coordinators[1] + chipInput.height)
|
||||
|
||||
height = if (calculatedHeight < defaultHeight) defaultHeight else calculatedHeight
|
||||
topMargin = chipInput.height
|
||||
}
|
||||
|
||||
visibility = VISIBLE
|
||||
|
|
|
@ -10,6 +10,7 @@ import android.view.MotionEvent
|
|||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
import android.view.inputmethod.EditorInfo.IME_FLAG_NO_EXTRACT_UI
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.LinearLayout
|
||||
import androidx.core.view.setPadding
|
||||
import androidx.core.widget.doOnTextChanged
|
||||
|
@ -59,7 +60,12 @@ class MaterialChipInput : LinearLayout {
|
|||
|
||||
orientation = VERTICAL
|
||||
addView(chipGroup, LayoutParams(MATCH_PARENT, WRAP_CONTENT))
|
||||
addView(dropdownListView, LayoutParams(MATCH_PARENT, WRAP_CONTENT))
|
||||
|
||||
post {
|
||||
val root = this.rootView
|
||||
val parentOfParent = this.parent.parent as FrameLayout
|
||||
parentOfParent.addView(dropdownListView, FrameLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT))
|
||||
}
|
||||
}
|
||||
|
||||
private fun processChangedText(text: CharSequence?) {
|
||||
|
@ -73,7 +79,7 @@ class MaterialChipInput : LinearLayout {
|
|||
dropdownListViewAdapter.filterText(text) {
|
||||
with(dropdownListView) {
|
||||
if (it > 0) {
|
||||
fadeIn()
|
||||
fadeIn(this@MaterialChipInput)
|
||||
smoothScrollToPosition(0)
|
||||
} else fadeOut()
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ class MainActivity : AppCompatActivity() {
|
|||
|
||||
contactsQuery.close()
|
||||
mainChipsInput.itemList = contactList ?: emptyList()
|
||||
mainChipsInput.onTextChangeListener = { scroll.smoothScrollTo(0, scroll.bottom) }
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -7,24 +7,32 @@
|
|||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/scroll"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
<FrameLayout
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<io.github.wulkanowy.materialchipsinput.MaterialChipInput
|
||||
android:id="@+id/mainChipsInput"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="58dp" />
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:ignore="UselessParent">
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="58dp"
|
||||
android:background="@color/colorPrimary"
|
||||
tools:ignore="Autofill,LabelFor,TextFields" />
|
||||
</LinearLayout>
|
||||
<io.github.wulkanowy.materialchipsinput.MaterialChipInput
|
||||
android:id="@+id/mainChipsInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="58dp" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="144dp"
|
||||
android:background="@color/colorPrimary"
|
||||
tools:ignore="Autofill,LabelFor,TextFields" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</LinearLayout>
|
||||
|
|
Loading…
Reference in a new issue