Skip to content

Commit

Permalink
fix(android): do not use holder for layout status
Browse files Browse the repository at this point in the history
  • Loading branch information
garymathews authored and ewanharris committed Sep 10, 2021
1 parent 60e33ff commit 5c3b9d5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ public void scrollToIndex(int index, @Kroll.argument(optional = true) KrollDict

// This is a workaround for when `EDITING` mode is set, as it recreates the TableView.
// We need to listen for when it has updated before scrolling.
if (row.getHolder() == null) {
if (!tableView.getHasLaidOutChildren()) {
tableView.addOnLayoutChangeListener(new View.OnLayoutChangeListener()
{
@Override
Expand Down Expand Up @@ -829,7 +829,7 @@ public void selectRow(int index)

// This is a workaround for when `EDITING` mode is set, as it recreates the TableView.
// We need to listen for when it has updated before testing visibility/scrolling.
if (row.getHolder() == null) {
if (!tableView.getHasLaidOutChildren()) {
tableView.addOnLayoutChangeListener(new View.OnLayoutChangeListener()
{
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ public void scrollToItem(int sectionIndex, int itemIndex, @Kroll.argument(option

// This is a workaround for when `EDITING` mode is set, as it recreates the ListView.
// We need to listen for when it has updated before scrolling.
if (item.getHolder() == null) {
if (!listView.getHasLaidOutChildren()) {
listView.addOnLayoutChangeListener(new View.OnLayoutChangeListener()
{
@Override
Expand Down Expand Up @@ -805,7 +805,7 @@ public void selectItem(int sectionIndex, int itemIndex)

// This is a workaround for when `EDITING` mode is set, as it recreates the ListView.
// We need to listen for when it has updated before testing visibility/scrolling.
if (item.getHolder() == null) {
if (!listView.getHasLaidOutChildren()) {
listView.addOnLayoutChangeListener(new View.OnLayoutChangeListener()
{
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,16 @@ public ListViewAdapter getAdapter()
return this.adapter;
}

/**
* Get status of child layouts.
*
* @return Boolean to determine if child layouts are processed.
*/
public boolean getHasLaidOutChildren()
{
return this.hasLaidOutChildren;
}

/**
* Get linear layout manager.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class TiTableView extends TiSwipeRefreshLayout implements OnSearchChangeL
private final List<TableViewRowProxy> rows = new ArrayList<>(CACHE_SIZE);
private final List<KrollDict> selectedRows = new ArrayList<>();

private boolean hasLaidOutChildren = false;
private SelectionTracker tracker;
private boolean isScrolling = false;
private int scrollOffsetX = 0;
Expand All @@ -77,7 +78,17 @@ public TiTableView(TableViewProxy proxy)
this.recyclerView.setFocusable(true);
this.recyclerView.setFocusableInTouchMode(true);
this.recyclerView.setBackgroundColor(Color.TRANSPARENT);
this.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
this.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()) {
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)
{
super.onLayoutChildren(recycler, state);

if (!hasLaidOutChildren) {
hasLaidOutChildren = true;
}
}
});

// Add listener to fire scroll events.
this.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener()
Expand Down Expand Up @@ -384,6 +395,16 @@ public TableViewAdapter getAdapter()
return this.adapter;
}

/**
* Get status of child layouts.
*
* @return Boolean to determine if child layouts are processed.
*/
public boolean getHasLaidOutChildren()
{
return this.hasLaidOutChildren;
}

/**
* Get linear layout manager.
*
Expand Down

0 comments on commit 5c3b9d5

Please sign in to comment.