Enable Auto-scrolling LazyColumn to the bottom when reverseLayout = false - android-jetpack-compose

I have a LazyColumn holding some Items. I listen a Flow from Room and everything works great when reverseLayout = true. When new Item get inserted into the database, the LazyColumn scrolls to the bottom and shows last Item just fine. But reverseLayout = true inverts the headers too. So I disabled it with reverseLayout = false. This does not work in that when Item get inserted, it is shown on the list but the list does not get scrolled to show the bottom item. I have to manually scroll.
How can I scroll to the bottom Item when the LazyColumn get recomposed on items change?
I don't think I need to put the code since the problem happens with any use of LazyColumn but if that is important let me know and I can redact the code and post them!

In a messaging app i scroll to bottom using size of items and LazyListState
as
coroutineScope.launch {
scrollState.animateScrollToItem(messages.size - 1)
}
and whenever user inputs a message it gets added to
val messages = remember { mutableStateListOf<ChatMessage>() }
you can call scroll in a LaunchedEffect(messages.size){...} for it to be invoked only when recomposition happens and item count has changed

Related

carouselCurrentItemIndexDidChange on iCarousel only being called when I swipe

I'm using iCarousel in my Swift+Sprite Kit game, where the user has unlocked and locked items.
The locked items would display some info like current user coins, and some text that says "UNLOCK THIS FOR: X amount of coins", if the carousel item isn't locked, it won't display any of that information, just a button that says "Select".
Now, I got that working, but it will only work when i start swiping the items and not the first time the carousel shows up.
To make that work, I do it inside carouselCurrentItemIndexDidChange() method. And that obviously changes when I swipe.
How can I set the current carousel index at start so then I can force to show or not show the information depending if the item is locked or unlocked and not only when I start swiping?
To add more information about this, imagine that the user selected the item at index 4, i save that index locally. So if the user closes and opens the game, the carousel should begin at 4 not 0.
Thanks in advance.
You should set up your carousel views in viewForItemAtIndex: reusingView:. The view returned by this method should represent the current state of that carousel item; so locked or "Select" as appropriate.
If the state of an item changes then you can call reloadItemAtIndex: to have iCarousel request an updated view for that item by calling viewForItemAtIndex: reusingView:.
You can scroll the carousel to a particular item by calling scrollToItemAtIndex:animated:

Titanium Mobile editable row moves inner row elements

I have a tableView with multiple TableViewRow objects, always 4.
When the edit button is clicked the row can be reordered, which is working.
But when the edit button is clicked the elements inside of a row seem to be moved with margins from left and right.
The items in a row should not be moved, so I was hoping someone could tell me how I can make sure the labels inside a row element are not being moved around when edited.
I have included some images, hoping to clarify my question:
Rows when not edited
Rows when edited
The solution was easy, but I didnt know.
The way to achieve this; Add a view to each row and do NOT set the left or right properties.
This way the delete button and move icon are not pushing the inner view away.
Its a default behavior. I dont think there's any way defined in Titanium API to override the moving of inner elements. So you cannot change this default behavior.

Blackberry return to the previus position in ListField

In my application I'm using a list.
This list can be updated by a refresh list button which is retriving more data from serever.
When user pressing the refresh button, my application seves the last selected item into a memeber field -
lastPosition = listField.getSelectedIndex();
After updating the list, my application uses -
listField.setSelectedIndex(lastPosition);
for setting the last position.
But nothing happen.
How can i "move" the list's cursor to point on the lastPosition?
Thanks,
Eyal.
listField.setKeyword("");
listField.v = userVector;
listField.updateList();
listField.getResultList();
listField.setSelectedIndex(lastPosition);
listField.setFocus();
Manager manager = listField.getManager();
int rowHeight = listField.getRowHeight();
manager.setVerticalScroll(lastPosition * rowHeight);
listField.invalidate();
It's hard to guess what is wrong without seeing the code, however the first thing that comes to mind is probably you don't set focus on the list right after you restore the position? If you don't, then try it:
listField.setSelectedIndex(lastPosition);
listField.setFocus();

BlackBerry 6: how to scroll to a new item in KeywordFilterList?

the SearchFieldDemo works well for me, but has one problem: when you add a new country to the KeywordFilterList through the menu and that new item is on the bottom of the sorted list, then the user doesn't see anything and is unsure if the new item has been added or not.
A solution would be to make the KeywordFilterList scroll to the new item, but I can't figure out, how to do that. I've tried:
void addElementToList(Country country)
{
_countryList.addElement(country);
_keywordFilterField.updateList();
int index = _countryList.getIndex(country);
System.err.println("XXX index: " + index);
_keywordFilterField.setSelectedIndex(index);
}
But this does not have any effect: the printed index is correct and the KeywordFilterList scrolls, but not to a correct spot.
Any ideas please?
Alex
In the sample app you might have noticed the _keywordFilterField.setKeyword(""); line as the first thing they do before adding a new item to the list. This is to guarantee the new item will be visible in the list. Otherwise with some filter applied the list may not display the new item.
So in your code it looks like you don't handle this point. As a result the index you get with int index = _countryList.getIndex(country); may not be the same as it is in the visible filtered by some current keyword list. BTW, to find the index in the visible list you could use the ReadableList which can be got with _keywordFilterField.getResultList().
So the workflow could be as follows:
reset keyword by _keywordFilterField.setKeyword(""); - now there is no filtering applied so the visible list should include a new item.
add a new item to the underlying collection - _countryList.addElement(country);
call _keywordFilterField.updateList(); to refresh the ListField.
to be on the safe side find an index to scroll to by using the collection got by calling the _keywordFilterField.getResultList()
select the new item with _keywordFilterField.setSelectedIndex(index);

jQuery slideToggle() applies display:block while sliding

I have a page that's like a discussion where you can make posts and reply to those posts. When there are more than 2 replies, I show the two most recent ones and hide the rest by default. There's a button that will let you expand/collapse the extra replies that uses jQuery's slideToggle function. It's operating on an unordered list of tables, where each table contains the comment along with the user's name and some other info.
Here's the problem: While the tables are actually sliding up or down, the first table in the list looks like its width has been set to auto, so it shrinks. Once it's done sliding, the formatting looks fine; it's just during the actual sliding that this happens. I'm assuming it's being set to 'display:block' or something during the slide but I don't know that for sure.
Is there a way to control what the display type is during the animation?
//this is what happens when you click the 'View all X replies' or 'Hide replies' button
$(".expandOverflow").click(function()
{
$(".overflowlist" + overflowListTarget).slideToggle(16000/*, function(){$(this).css('display', 'inline');}*/);
});

Resources