I know there is the animateItemPlacement method for LazyColumn, but in LazyGrid it's marked with internal modifier. In any case, this is not exactly what I need, it doesn't animate the addition/removal of items. Are there ready-made solutions (for example, third-party libraries)?
Related
In Android, I'm doing the new Jetpack compose and trying to figure out the equivalent of sharing a viewpool across recyclerviews.
If an app has multiple recyclerviews with similar content, then you can really speed up performance by sharing the same view pool across your recyclerviews. You can create a view pool, customize it, and then set it to each of the recyclerviews. This is something I'm used to doing.
In Jetpack Compose, instead of recycler view there is LazyColumn or LazyRow. How do I share the views or compositions across different lazy lists?
There's no such functionality available as of the current stable version, i.e., 1.1.1. You can, however, take a look at LazyLayout. It is currently available in the alpha versions of Compose, and can achieve what you require (AFAIK) if the layouts are close to each other. Basically, it will be a single Composable, which you handle the contents of, yourself. If the lists are right next to each other, just create a single LazyLayout, create two lists, add the same source to both, and you're all done. If you want to add some other Composables between lists, you'll need to merge those with this one, and render them inside the lazy layout. That's what the Compose team would likely go with, but you know... well actually you never know.
I've been having fun digging into Jetpack Compose. Here I used Rows, Columns, and Spacers to build this screenshot. Is there a better-suited Composable I should try?
I couldn't get LazyVerticalGrid to place the jellyfish in its position. It wants to put it on the left beneath the black dog, which leaves a blank space and pushes the brown dogs onto their own line.
I also tried Accompanist's FlowRow, which draws the same arrangement as LazyVerticalGrid. It's also likely I'm not familiar enough with the API of either.
Later I want to learn drag & drop to reorder the items. Are there considerations to make as I'm setting up this widget to make life easier? In my head it seems like these individual Rows and Columns could get in my way, maybe it has no bearing though.
Thanks for any insights!
I made a custom Layout instead, which allows for measuring and placing content. 🤞🏽
Google jetpack compose pathway has a lesson on custom layout, but i think you can use a Lazy Grid, it makes it easy to work with grids.
Link android developers Lazy Grids
if you click the lazy vertical grid link you'll see that you can have multiple rows of items with different modifiers and number of grid cells.
I would love to give you a working example, so I will probably edit this soon.
Being objective, my goal is simple (or not), drag a recycler's item to other one in my activity.
The scenario is the following.
I have a list of items, let's call them sections, and inside a section another list of items, of another type, the elements.
I want exchange the elements between the sections. The list of sections isn't fixed, can be changed adding and removing a section, but hasn't any movement behavior. The elements also can be added and removed from a section, but have this reorder approach.
I've found some strategies with fixed "section". Here is an example. This one uses drag and drop to make the exchange. But it's too simple. For example, don't consider the need to scroll recycle when the dragging reaches bottom or top of visible elements. That's because it has only two lists. Does Drag and Drop have this behavior, forcing the scroll?
Is there any way to do this using the ItemTouchHelper? If so, how would it be? ItemTouchHelper seems better, 'cause considers the scroll problem and has a more intuitive reorder animation.
If you think of a better approach than using recyclers, feel free to indicate such strategy to me.
You use drag and drop for the dragging and dropping, the scrolling and such you'd have to make yourself using the appropriate events in the OnDragListener.
I have a RecyclerView that display the list of modifications per day for a document. Items are TextView with values like "Line 3 updated to ...", "Line 5 removed", etc. The ViewHolder handle 2 types of views :
Headers : which are the days. These are simple TextView too that are in bold, larger, etc.
Logs: that's what I was talking about : "Line 3 updated ...", etc.
What I would like is that each "day", with its corresponding logs are embedded inside a CardView. But a document can have huge number of modifications per day (>100). So programmatically creating a layout with a CardView as the root, calling 100 times addView() on it to add each logs and then passing this layout to the RecyclerView does not seems a good idea to me.
Is their any way to delimit between a "positionStart" and a "positionEnd" views that will be embedded inside a CardView? It seems to me that this isn't possible or by adding each TextView programmatically inside a CardView but it will then slow down the binding of the views and break the ViewHolder pattern. Am I right or is their a solution I didn't think about ?
You have 3 options to achieve this "grouped in a card" behavior.
(as mentioned) you create the layout yourself and put the whole thing into the recyclerview. This is probably the worst solution since it negates the idea of a recyclerview in the first place.
You just wrap each of your items in a CardView (and set the corner radius to 0dp).
On < 21 devices (I think) there will be some additional padding and every item will appear as its own card, but on higher API versions those cards will lie next to each other and just have some "seam" between them. The shadow on the corner is also a bit buggy, but this is probably the easiest and cheapest solution.
Alternatively you can also create a custom view that fixes the errors mentioned above (margins between and shadow) and use your own to wrap the views. (I believe this is what the Inbox app does if I recall correctly, which also features lists in cards.)
You use an ItemDecoration. For this approach you need a kind of stable setup of your dataset, but if its just the headers and logs, you can draw a shadow above the header, draw borders to the left and right of every item, and draw a shadow beneath the last log. This will also require some setup, and if you introduce further view types you will also have to modify this code (it's highly dependent on your data set)
The 1. method is probably the worst idea. It will work for small lists.
The 2. method can work, but you either will have to create your own custom view or live with a "bugged" version on lower api levels.
The 3. method is something I tried once for fun, and will work, but you will have some additional dependency between your data, your adapter, and your decoration. You can see an example of this decoration here on GitHub. It just draws a shadow around all of the items.
I'm wondering how to implement a horizontal list of users, that become bigger and brighter once they are chosen:
I'm thinking about ViewPager with overriden getPageWidth so that it shows 3 items at the same time, but I don't know how do make the sibling views look differently then the one in the middle.
That would have been pretty easy to achieve with the Gallery widget that is now unfortunately deprecated.
But there is the EcoGallery project https://github.com/falnatsheh/EcoGallery that has the same functionalities and works pretty well.
To transform the view in the center you can simply subclass the EcoGallery and override the
getChildStaticTransformation
method.
BTW you can override exactly the same method also on the ViewPager.
It's pretty easy to find loads of good examples of how to use this method.