hanks-zyh / SmallBang

twitter like animation for any view :heartbeat:
Apache License 2.0
1k stars 158 forks source link

Any examples with DataBinding? #17

Open nowiwr01w opened 4 years ago

nowiwr01w commented 4 years ago

Please, share with us, if it's possible.

Arunachalamkalimuthu commented 3 years ago

@nowiwr01 Used Datbinding to change the state of the view

 @JvmStatic
    @BindingAdapter(value = ["bind:favouriteChildView"])
    fun bindFavouriteState(view: SmallBangView, childView: View) {
        view.setOnClickListener {
            if (view.isSelected) {
                view.isSelected = false
            } else {
                view.isSelected = true
                view.likeAnimation(object : AnimatorListenerAdapter() {
                    override fun onAnimationEnd(animation: Animator?) {
                        super.onAnimationEnd(animation)
                    }
                })
            }

        }
    }
                    <xyz.hanks.library.bang.SmallBangView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentEnd="true"
                        android:layout_centerVertical="true"
                        android:layout_marginStart="16dp"
                        android:layout_marginEnd="16dp"
                        bind:favouriteChildView="@{favouriteChildView}">

                        <ImageView
                            android:id="@+id/favourite_child_view"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:src="@drawable/favourite_selector_selected" />
                    </xyz.hanks.library.bang.SmallBangView>

`

`