Jetpack Compose syncronize Animated Visibility animation based on state - android

I am using an Material 2 version of a BottomSheet and I get the animations current progress, I want to synchronize the appearance of the Top App Bar so that when the Bottom Sheet is fully up it is also visible.
This question applies to other kind of animations as well, I've been reading documentation and I didn't find any way of controlling any animation based on state.
I've used different kind of animations but the nearest I've got is to animate the content's height based on that state, but this doesn't come from the bottom up.
Thanks!

Related

How to navigate to a non bottom bar screen with jetpack compose?

So i have an app in compose that has startDestination set as a screen with scaffold with bottom nav bar having 3 items and top app bar, i am able to navigate through the 3 bottom navigation tabs. But suppose i want to click on a card in one of the bottom tab screen which should open a details screen without the bottom bar and app bar (Since Navhost is inside the scaffold, bottom and top bars show up on details screen too), what is the right way to do that? Currently i have tried the following ways:-
1. Starting the details screen in a new activity.
2. Using currentDestination route as state to conditionally hide bottom and app bar for details screen route.
Both work but, the problem with first approach is that, it isn't recommended to use multiple activity with jetpack navigation and rather we should stick to a single activity, it also further breaks the navigation if in case i want to move from details to another screen. The problem with second approach is that hiding and showing bottom/top bars create very bad transition between the screens and app doesn't feel smooth.
Hence, i am looking for an appropriate way to handle this as per the guidelines, although i couldn't find any info on this.
Update
I went with showing/hiding the bottom and app bar based on routes, turns out that bad and laggy animation i was facing was because i was running a debug app, with a release app with minifyEnabled true (R8) ,the transitions are very smooth and natural, as i wanted them.
Also it turns out, as per Google's official compose sample app JetSnack , this is the appropriate way of achieving navigation from a bottombar screen to a non-bottombar screen. Thanks to #vitidev for pointing it out in the comments.
You can use a nested Navigation Graph:
one principal graph according to your BottomBar
one nested graph inside each screen you want to go further
https://developer.android.com/jetpack/compose/navigation#nested-nav

What is scrim in collapsibletoolbarlayout?

I read collapsible toolbar layout on developers android. There is a term scrim used there. What is it?
Scrim: A thing that conceals or obscures something.
As per Android CollapsingToolbarLayout:
Content scrim: A full-bleed scrim which is show or hidden when the scroll position has hit a certain threshold. You can change this via setContentScrim(Drawable).
You can use drawable as a scrim on top of the CollapsingToolbarLayouts content when it has been scrolled sufficiently off screen.
app:contentScrim="YOUR_TOOLBAR_COLOR"
Status bar scrim: A scrim which is show or hidden behind the status bar when the scroll position has hit a certain threshold. You can change this via setStatusBarScrim(Drawable). This only works on LOLLIPOP devices when we set to fit system windows.
You can use drawable as a scrim for the status bar content when the CollapsingToolbarLayout has been scrolled sufficiently off screen.
app:statusBarScrim="YOUR_STATUSBAR_COLOR"
Hope this will help!
Here's what the material design docs say:
https://material.io/design/environment/surfaces.html#attributes
Scrims are temporary treatments that can be applied to Material surfaces for the purpose of making content on a surface less prominent. They help direct user attention to other parts of the screen, away from the surface receiving a scrim.
Scrims can be applied in a variety of ways, including:
Darkening or lightening the surface and its content
Reducing the opacity of the surface and its content
Multiple surfaces on a screen at a time can display scrims. Scrims can appear at any elevation, whether in the foreground or background.

In Android, what are window insets?

This sounds like a dumb question, and I'm sorry if it is, but I've searched around to get a visual representation of what they are and came up with nothing.
Here is what Android has to say about it:
WindowInsets are immutable and may be expanded to include more inset types in the future.
http://developer.android.com/reference/android/view/WindowInsets.html
Google images autocorrect it to window inserts...
Why would anyone work with these "insets"? Do they have anything to do with the navigation bar on mobile phones with no home physical keys?
Insets are areas of your view that you should not put elements, like behind the status bar or navigation bar. Think of them like paddings for the window.
If you want to draw behind them, like putting an image to the top that should be behind a translucent status bar, you will need to consume the window insets. In some views this is as easy as putting android:fitsSystemWindows=true, but in others you will have to override the onApplyWindowInsets method.
Usually the window insets for phones are the size of the height of the status bar as the top, the size of the navigation bar as the bottom and 0 as left and right. But It can be different, like in watches or phones with physical buttons.
They are some kind of colored margin (used in Android Wear).
They are used to create a padding from the main content to the actual border:
There are a few examples here.
This is an image with 2 insets: Circle/Squared.
They can also be used in other views to handle especial rendering requirements, like in a ScrollView: where to put the actual scroll can be defined with an insideInset as mentioned in this question.
<ScrollView
android:id="#+id/view2"
android:layout_width="100dip"
android:layout_height="120dip"
android:padding="8dip"
android:scrollbarStyle="insideInset"
android:background="#android:color/white"
android:overScrollMode="never">
You may use onApplyWindowInsets:
#Override
public void onApplyWindowInsets(WindowInsets insets) {
super.onApplyWindowInsets(insets);
mRound = insets.isRound();
}
to detect if wearable android device is round or square, then using that information draw appropriate application interface (with round or square background)
WindowInsets is a class that represents the so-called window insets. They're some kind of margins/paddings your content should have not to overlap unusable areas of the screen. As many people suggested, they can be used to detect whether an Android Wear device is round and handle that shape. However, the probably most common case of use is on mobile phones. Status and navigation bars are both part of the System UI, and thus they cover different rooms of the screen you should not place your content in.
An Activity, depending on the window flags set in, can either use the whole screen or be resized below the status bar and above the navigation bar (see WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN and WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS). So, if you set your activity not to handle window insets, you'll have to do it all by yourself. And you would use View.setOnApplyWindowInsetsListener method to let yourself notice whenever those insets change, and you would handle UI changes (e.g. set some padding) based on the values provided in the listener.
I wrote sample.
This repository can help to grasp android windows insets idea and Edge-To-Edge concept + we can detect keyboard without assumption that "keyboard should be more than X part of screen"

UI screen design

I am working on an Android application and have to code up the following design for one of the screens:
(Ignore the yellow stuff, I have just masked the Logo and the App-specific information for now)
My question is: How do I design this particular type of screen? The top pane is akin to an ActionBar in Android. However, when any button on the top pane is hit, this custom "popup" having a rectangular form with a small arrow on top pointing towards the button is display and does not interrupt the current/main activity.
I have looked around, but still dont understand how to accomplish this.
Any thoughts? Thanks!
You can use the native Action Bar along with the icons.
The only problem is if you want to show them all at once.
Some icons may be hidden depending on the size of the phone.
As for the custom pop-up, the toast feature is available to do that.
It is quite easy to adjust the position of toasts and customise toasts :
Customisation of toasts: http://developer.android.com/guide/topics/ui/notifiers/toasts.html#CustomToastView
Changing postion of toasts: How to change position of Toast in Android?

sliding drawer options android

I have a project where the designs require a sliding drawer that comes from the bottom and has essentially three states.
fully collapsed (just the handle at the bottom
half mast (drawer opens from bottom but only halfway up the screen
full mast (drawer opens from bottom and takes up the whole screen minus a top margin of lets say 80dp
I am developing for android 4.0 and higher and obviously sliding drawer is deprecated. But the Navigation drawer only supports left and right (which i already have in use)
So i am wondering if anyone knows a tutorial or even a custom component someone has written that meets the above functionality requirements
In my experience, you probably have to create something yourself, but since you're developing for api lvl 14, check out ObjectAnimator. It allows you to move Views around and still use them (by that I mean that it's the original view that has been moved and not a copy of it)
This will probably be the easiest way.
FYI, using the Navigation Drawer, you can't open the drawer halfway, or you should programmatically invoke touch events...
I think this is what you are looking for.
I have found this library best so far for sliding up menus in Android.
https://github.com/umano/AndroidSlidingUpPanel
You can specify what screen area slide up menu or view will use.
Accept & vote up my answer if it is what you are looking for.

Categories

Resources