Skip to content

Commit

Permalink
fix(android): include totalItemCount and visibleItemCount properties
Browse files Browse the repository at this point in the history
  • Loading branch information
garymathews authored and sgtcoolguy committed Jan 19, 2021
1 parent b7609ff commit d1079c3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy)
{
super.onScrolled(recyclerView, dx, dy);

if (dx == 0 && dy == 0) {

// Not scrolled, skip.
return;
}

if (!isScrolling) {
isScrolling = true;
proxy.fireSyncEvent(TiC.EVENT_SCROLLSTART, generateScrollPayload());
Expand Down Expand Up @@ -269,6 +275,11 @@ public KrollDict generateScrollPayload()
final int firstVisibleSectionIndex = proxy.getIndexOfSection(firstVisibleSection);
payload.put(TiC.PROPERTY_FIRST_VISIBLE_SECTION_INDEX, firstVisibleSectionIndex);

// Define visible item count.
final int visibleItemCount =
layoutManager.findLastVisibleItemPosition() - layoutManager.findFirstVisibleItemPosition();
payload.put(TiC.PROPERTY_VISIBLE_ITEM_COUNT, visibleItemCount);

return payload;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class TiTableView extends TiSwipeRefreshLayout implements OnSearchChangeL
private int scrollOffsetX = 0;
private int scrollOffsetY = 0;

private int totalRowCount;

public TiTableView(TableViewProxy proxy)
{
super(proxy.getActivity());
Expand Down Expand Up @@ -106,6 +108,12 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy)
{
super.onScrolled(recyclerView, dx, dy);

if (dx == 0 && dy == 0) {

// Not scrolled, skip.
return;
}

isScrolling = true;

// Update scroll offsets.
Expand Down Expand Up @@ -260,6 +268,14 @@ public KrollDict generateScrollPayload()
final int firstVisibleIndex = firstVisibleProxy.getIndexInSection();
payload.put(TiC.PROPERTY_FIRST_VISIBLE_ITEM, firstVisibleIndex);

// Define visible item count.
final int visibleItemCount =
layoutManager.findLastVisibleItemPosition() - layoutManager.findFirstVisibleItemPosition();
payload.put(TiC.PROPERTY_VISIBLE_ITEM_COUNT, visibleItemCount);

// Define total item count.
payload.put(TiC.PROPERTY_TOTAL_ITEM_COUNT, totalRowCount);

// Obtain scroll offset for content.
final KrollDict contentOffset = new KrollDict();
final TiDimension scrollOffsetXDimension = new TiDimension(scrollOffsetX, TiDimension.TYPE_WIDTH);
Expand Down Expand Up @@ -524,6 +540,7 @@ public void updateModels()
// Update row index, ignoring placeholder entries.
row.index = i++;
}
totalRowCount = i;

final Activity activity = TiApplication.getAppCurrentActivity();
final View previousFocus = activity != null ? activity.getCurrentFocus() : null;
Expand Down
10 changes: 10 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -3361,6 +3361,11 @@ public class TiC
*/
public static final String PROPERTY_TOP = "top";

/**
* @module.api
*/
public static final String PROPERTY_TOTAL_ITEM_COUNT = "totalItemCount";

/**
* @module.api
*/
Expand Down Expand Up @@ -3501,6 +3506,11 @@ public class TiC
*/
public static final String PROPERTY_VISIBILITY = "visibility";

/**
* @module.api
*/
public static final String PROPERTY_VISIBLE_ITEM_COUNT = "visibleItemCount";

/**
* @module.api
*/
Expand Down

0 comments on commit d1079c3

Please sign in to comment.