MediumTopAppBar and LargeTopAppBar have expanded and closed state.
EnterAlwaysScrollBehavior will immediately collapse when the content is pulled up, and will immediately appear when the content is pulled down. (from the doc)
If scrolled down and the page body content changes it'll still be in the closed state as expected. But I want to trigger an expanded state back when say content changed or a button is pressed without the user scrolling up.
What I need:
A method or workaround to change the TopAppBar state to expand.
Related
Background
I have created a Composable that contains a TopAppBar and a WebView which recreates the enterAlways collapsing-toolbar behavior that Xml has.
The way it works is by applying Modifier.offset {..} to the composables. The offset is calculated whenever the WebView is scrolled.
For example, if I'm at the top of the page, and I scroll towards the bottom of the page (swipe from bottom to top), the Y offset for both the WebView & TopAppBar decreases at the same time.
Problem
The problem is that it is very jittery whenever the TopAppBar is expanding or collapsing. I think this is because the offset for the WebView is changing while I'm still scrolling. In the previous example, the WebView moves up to take the place of the collapsing-toolbar, but my finger is still pressed on the screen while that happens, which may cause the device to interpret that as an upward scroll (swiping from top to bottom).
Basic Outline of Code:
Column {
TopAppBar(
Modifier.offset { IntOffset(0, state.toolbarOffsetHeightPx) },
...
)
WebView(
Modifier.offset { IntOffset(0, state.toolbarOffsetHeightPx) },
onWebPageScrolled = /** Update state.toolbarOffsetHeightPx */
...
)
}
What I tried
One potential solution I thought of involves reading the scrolls (like I currently am) and also consuming them.
When the toolbar is collapsing or expanding, I realized that I should probably only adjust the offset during that time, and I should ensure that the WebView does not scroll its content.
Since the WebView's height is the screen height, when the TopAppBar is collapsing, the part of the WebView which was hidden at the bottom of the screen now comes into view, and to the user, the offset of the WebView changing would make it look like they are scrolling. Therefore, I should force the WebView to not scroll during this time.
--
The problem with this approach is that I'm getting the data about WebView scrolls from the onScrollChangedListener, so if I disable WebView scrolling while the TopAppBar is expanding or collapsing, then I also lose the ability to keep expanding/collapsing the TopAppBar...
Some solutions I came up for this are:
Have a wrapper Composable around the WebView which can receive the scrolls.
I could not figure out how to implement this. It looks like there is a nestedScrolling Modifier which allows capturing scrolls, so I wrapped my WebView in a Box which had that Modifier, but even though I was consuming the scrolls in the NestedScrollConnection the WebView was still receiving scrolls normally..
Use onTouchListener to receive scroll events rather than onScrollListener.
This gets a little complicated because onTouchListener is not only called for scrolls. I tried only running my TopAppBar/WebView offset logic if the onTouchListener was called for MotionEvent.ACTION_DOWN, but the results were very strange.
I did manage to replicate the original expanding/collapsing w/ the TopAppBar & WebView, but rather than expanding/collapsing while I'm scrolling, the entire expanding/collapsing would complete before I even started dragging my finger - just pressing my finger and twisting it up or down completely expanded/collapsed the TopAppBar.
The desired behavior is that the expanding/collapsing should happen linearly with the webpage scrolling, so this did not work.
I really appreciate any help. I've created a simple app on a GitHub repo if you would like to test the behavior.
Is it possible to to have BottomSheet initial position start from approx. middle of screen? instead of having at end of screen?
How can I set that initial position? I want BottomSheet (that has a recyclerView in it) to appear initially from middle of screen (towards bottom). When user swap it up, it should come up and stop just under my app main Title bar.
Your expert opinion is appreciated.
Since I'm a new to stack overflow, please forgive for my mistakes.
I've an Horizontal scroll view and few child views inside it.
When I do a fling on the screen to navigate across child views using accessibility focus, it navigates fine (Assume I kept the focus on any child view). I've dismissed that view and reopened it. I'm reusing the view as it is and no accessibility focus I can see on screen. When I fling again to navigate across child views, the focus is missing or jumping some child views.
If I recreate the view or do a small scroll on re open, the focus navigates fine, but not after invalidating the view.
I guess some view status is being maintained with accessibility service, and focus delivered accordingly. Is it possible to update the view's details to accessibility service manually instead of recreating it?
I have two Webviews but at certain point i would like to bring the one on the back to front. I want both visible.
Is it possible to change the layout order?
There is no concept of Z-axis position in Android view stack so you can't bring views to front or send to back. You need to set the view's visibility flag to hide, visible or invisible (.setVisibility(GONE , VISIBLE, or INVISIBLE) respectively). If you want them both visible at times then you need to have at least the top view (the one added to the parent view last) be with transparent background so that if their Visibilities are set to VISIBLE then the behind view will show through the top view.
Kevin
From readings, I have the height of the soft keyboard with the onSizeChanged method. What I want to do is to display a list in place of the soft keyboard when it is closed, and remove the list when the keyboard is required again.
The way I'm doing it at the moment is that when a button is pressed, a list will be made visible and the keyboard dismissed using the InputMethodManager. The problem in the button's onClick method, I set the list to be visible, but the keyboard hiding animation is still ongoing. This causes a visible flicker to happen, since the set visible call triggers the layout to be redone, and the list becomes visible while the keyboard is still there, pushing other views out of sight to the top. After the keyboard animation is finished, other views become visible again, this process causes a visible flicker...
Anyone got any suggestions on how I should approach this??
Pulling my hair at the moment, since setting the list visible during onLayout or onSizeChanged doesn't let the list become visible...
Thanks!!!
Dave.
you can implement onConfigurationChanged(Configuration) method in your activity. Also, to get this method called you should add information in your manifest file to specify in what situations the method should be called like that:
android:configChanges="keyboardHidden|orientation"
Look here for additional details.