6

Let's say we have a BottomNavigationBar with a FAB on top. When using this setup and showing a Snackbar, the Snackbar should appear above the BottomNavigationBar and push up/down the FAB while appearing/dismissing.

This is a common scenario for the use of CoordinatorLayout. Is it also possible to create this animation using the new MotionLayout?

There is an issue in the bug tracker, but it's already closed, because OP didn't clearly formulate the question (https://issuetracker.google.com/issues/112665540)

Problems I ran into while trying: We don't have access to the layout-id of the Snackbar. We also don't have access to the general xml of the Snackbar, so we cannot set its Constraints.

UPDATE: I understand that a piece of code would help as a starting point to answer this question. But what ever piece of code I came up with yet, was not useful at all. I pinpointed now the 2 main problems:

  1. I do not know the layout-id of the Snackbar. Therefore I cannot use it in writing a Scene description.

  2. Even if I could create a Scene description (e.g. State1: SnackBar visible, State2: Snackbar not visible). I'd have to trigger these Scene transitions by hand. That means that I would re-create my own Snackbar instead of using the original Snackbar as it is intended.

COMMENTS: @mikejonesguy Yes, in my opinion they are similar. Not the same, but similar. And MotionLayout does also have the job you described: to coordinate interactions among its subviews. Replace "coordinate" with "animate" and you'll see my point. Also have a look at the OnSwipe/OnClick handlers. MotionLayout is still very fresh, but I think it will replace CoordinatorLayout in the future the same way ConstraintLayout replaced RelativeLayout. Maybe I'm wrong, maybe not...time will tell.

CONCLUSION: As far as I'm concerned, there seems to be no way (yet) to achieve what I want only by using MotionLayout. If it's possible one day, I'll update this question with a working example. Sorry for the impossible bounty... :)

muetzenflo
  • 5,653
  • 4
  • 41
  • 82
  • 1
    Post related code if possible. – Pravin Divraniya May 16 '19 at 09:11
  • 1
    What have you tried?, No one write code for you, just give it a try then i you fail somewhere or you need help then SO is there. – Akash Dubey May 17 '19 at 06:31
  • You speak of MotionLayout and CoordinatorLayout as if they were similar animals. They're not. CoordinatorLayout's job is to coordinate interactions among its subviews (i.e., when SnackBar appears, the FAB animates up, etc). MotionLayout does not have that job. So. Is it possible to achieve? Maybe. But you need to post some code so that we can see what you're working with. – mikejonesguy May 17 '19 at 14:16
  • I did post an answer. If it confuses you, post your current code and I will modify it achieve exactly what you need. – Nezih Yılmaz May 21 '19 at 14:28
  • Did you create a new issue for this specific use case on the issuetracker? Or tweet at the guys developing motionlayout? I did so for my use case and they picked it up *and* added support one update later. – ZeroStatic May 21 '19 at 19:32
  • Yeah, maybe this is a good idea. As I said there is already an issue, but it was described badly. Maybe I will raise this question again in a separate ticket. – muetzenflo May 21 '19 at 19:37

1 Answers1

1

You can design your layout files as if the snackbar is in your layout hierarchy. You need to make use of Constraintlayout's virtual helper objects. Virtual objects are invisible but they act as a regular view during measuring & layout, therefore their purpose is to help you create the exact positioning you want.

A snackbars default height is min 48dp and max 80dp. You are going to need this information.

Nezih Yılmaz
  • 626
  • 4
  • 8
  • cool, didn't know about the virtual helper objects. I will test this as soon as I have time again for this project (may take a week though). If it is the needed hint, you'll get the bounty :) – muetzenflo May 21 '19 at 19:36