Skip to content

Commit

Permalink
[TIMOB-15999] Android add support for animated parameter in scrollToItem
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalduggal committed Apr 17, 2014
1 parent 9acd6b2 commit b0476cd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,22 @@ public int handleSectionCount () {
}

@Kroll.method
public void scrollToItem(int sectionIndex, int itemIndex) {
public void scrollToItem(int sectionIndex, int itemIndex, @SuppressWarnings("rawtypes") @Kroll.argument(optional=true)HashMap options) {
boolean animated = true;
if ( (options != null) && (options instanceof HashMap<?, ?>) ) {
@SuppressWarnings("unchecked")
KrollDict animationargs = new KrollDict(options);
if (animationargs.containsKeyAndNotNull(TiC.PROPERTY_ANIMATED)) {
animated = TiConvert.toBoolean(animationargs.get(TiC.PROPERTY_ANIMATED), true);
}
}
if (TiApplication.isUIThread()) {
handleScrollToItem(sectionIndex, itemIndex);
handleScrollToItem(sectionIndex, itemIndex, animated);
} else {
KrollDict d = new KrollDict();
d.put("itemIndex", itemIndex);
d.put("sectionIndex", sectionIndex);
d.put(TiC.PROPERTY_ANIMATED, Boolean.valueOf(animated));
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SCROLL_TO_ITEM), d);
}
}
Expand Down Expand Up @@ -187,7 +196,8 @@ public boolean handleMessage(final Message msg) {
KrollDict data = (KrollDict) result.getArg();
int sectionIndex = data.getInt("sectionIndex");
int itemIndex = data.getInt("itemIndex");
handleScrollToItem(sectionIndex, itemIndex);
boolean animated = data.getBoolean(TiC.PROPERTY_ANIMATED);
handleScrollToItem(sectionIndex, itemIndex, animated);
result.setResult(null);
return true;
}
Expand Down Expand Up @@ -224,10 +234,10 @@ public boolean handleMessage(final Message msg) {
return super.handleMessage(msg);
}
}
private void handleScrollToItem(int sectionIndex, int itemIndex) {
private void handleScrollToItem(int sectionIndex, int itemIndex, boolean animated) {
TiUIView listView = peekView();
if (listView != null) {
((TiListView) listView).scrollToItem(sectionIndex, itemIndex);
((TiListView) listView).scrollToItem(sectionIndex, itemIndex, animated);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,10 +800,21 @@ private int findItemPosition(int sectionIndex, int sectionItemIndex) {
return position;
}

public void scrollToItem(int sectionIndex, int sectionItemIndex) {
int position = findItemPosition(sectionIndex, sectionItemIndex);
protected void scrollToItem(int sectionIndex, int sectionItemIndex, boolean animated) {
final int position = findItemPosition(sectionIndex, sectionItemIndex);
if (position > -1) {
listView.smoothScrollToPosition(position + 1);
if (animated) {
listView.smoothScrollToPosition(position + 1);
} else {
listView.post(new Runnable()
{
@Override
public void run()
{
listView.setSelection(position + 1);
}
});
}
}
}

Expand Down

0 comments on commit b0476cd

Please sign in to comment.