WalkingSnackBar

WalkingSnackbar is a small library to help you implement own snackbar layout with custom position and animation in easily.

Screenshot

Usage

‼️ Current version 0.0.1 support only message text for default snackbar layout, if you need custom layout , you just need to implement Decorator interface

Initialisation

WalkingSnackbar.make(view , message , decorator)

It need to set view or view group in first parameter.
For eg . WalkingSnackbar.make(binding.rootLayout,"hello message").show()
For duration .setDuration(10000)

This is just a simple default snackbar usage.

Custom layout Usage

You need to add Decorator interface in third parameter of .make(view , message , decorator)

Example usage

object : WalkingSnackbar.Decorator { override fun contentIn(view: View) { ObjectAnimator.ofFloat( view, View.TRANSLATION_X, -500f, 0f ).start() }
                override fun withCustomLayout(
                    inflater: LayoutInflater,
                    containerView: ViewGroup
                ): View? {
                    val binding = CustomSnackBarBinding.inflate(
                        inflater, containerView, false
                    )
                    binding.tv.text = "Oh my god custom message"
                    return binding.root
                }
contentIn(view: View) will called when you start .show() This method is to add animation when snackbar start
Use .show() to start showing snackbar
withCustomLayout(inflater: LayoutInflater,containerView: ViewGroup): View? to add custom layout binding , default snackbar will use when return null

For first parameter view

Usage of view parameter

When you add one of view in your layout hierarchy , (not WalkingSnackbarContainer view) then it will search up to suitable parent view
Default searching behaviour of snackbar)

‼️ But… when you add WalkingSnackbarContainer view , then it will use it as parent to customize your viewgroup position and measurement .

Note..

When you add WalkingSnackbarContainer view in your layout hierarchy
and you add another parent or sibling view in first parameter , then it will search WalkingSnackbarContainer in your layout first,
and it will only use default suitale view when no WalkingSnackbarContainer in your layout

Suggestion..

if you have WalkingSnackbarContainer view in your layout hierarchy , then directly add this view in parameter
because it will take parent searching with complexity

O(1)

.



With direct add WalkingSnackbarContainer container view

Otherwise it will search WalkingSnackbarContainer by using Depth First Search Algorithm before searching suitable view as default snackbar

and as we known that with complexity O(V + E)

.



With random added view will transver with DFS to get WalkingSnackbarContainer

GitHub

View Github