Skip to content

Commit

Permalink
feat(android): implement scrollToIndex animation support
Browse files Browse the repository at this point in the history
  • Loading branch information
garymathews authored and ewanharris committed Aug 16, 2021
1 parent 53f8bff commit 2c542b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -665,12 +665,18 @@ public void releaseViews()
public void scrollToIndex(int index, @Kroll.argument(optional = true) KrollDict animation)
{
final TiTableView tableView = getTableView();
final boolean animated = animation != null && animation.optBoolean(TiC.PROPERTY_ANIMATED, true);

if (tableView != null) {
final RecyclerView recyclerView = tableView.getRecyclerView();

if (recyclerView != null) {
recyclerView.scrollToPosition(tableView.getAdapterIndex(index));

if (animated) {
recyclerView.smoothScrollToPosition(tableView.getAdapterIndex(index));
} else {
recyclerView.scrollToPosition(tableView.getAdapterIndex(index));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,10 @@ public void replaceSectionAt(int index, ListSectionProxy section,
* @param itemIndex Index of item in section.
*/
@Kroll.method
public void scrollToItem(int sectionIndex, int itemIndex)
public void scrollToItem(int sectionIndex, int itemIndex, @Kroll.argument(optional = true) KrollDict animation)
{
final TiListView listView = getListView();
final boolean animated = animation != null && animation.optBoolean(TiC.PROPERTY_ANIMATED, true);

if (listView != null) {
final ListSectionProxy section = getSectionByIndex(sectionIndex);
Expand All @@ -629,7 +630,12 @@ public void scrollToItem(int sectionIndex, int itemIndex)
final ListItemProxy item = section.getListItemAt(itemIndex);

if (item != null) {
listView.getRecyclerView().smoothScrollToPosition(listView.getAdapterIndex(item.index));

if (animated) {
listView.getRecyclerView().smoothScrollToPosition(listView.getAdapterIndex(item.index));
} else {
listView.getRecyclerView().scrollToPosition(listView.getAdapterIndex(item.index));
}
}
}
}
Expand All @@ -644,7 +650,7 @@ public void scrollToItem(int sectionIndex, int itemIndex)
@Kroll.method
public void selectItem(int sectionIndex, int itemIndex)
{
scrollToItem(sectionIndex, itemIndex);
scrollToItem(sectionIndex, itemIndex, null);

final TiListView listView = getListView();

Expand Down

0 comments on commit 2c542b8

Please sign in to comment.