Skip to content

Commit

Permalink
feat(android): add flag to ListView to ignore recycling
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed Jul 26, 2023
1 parent 322b78d commit fe68051
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
public class ListViewAdapter extends TiRecyclerViewAdapter<ListViewHolder, ListItemProxy>
{
private static final String TAG = "ListViewAdapter";
public boolean allowRecycling = true;

private final TreeMap<String, LinkedList<ListItemProxy>> recyclableItemsMap = new TreeMap<>();

Expand Down Expand Up @@ -98,6 +99,7 @@ public void onBindViewHolder(@NonNull ListViewHolder holder, int position)

// Update ListViewHolder with new model data.
holder.bind(item, selected);
holder.setIsRecyclable(allowRecycling);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy)

// Create list adapter.
this.adapter = new ListViewAdapter(getContext(), this.items);
this.adapter.allowRecycling = !proxy.getProperties().getBoolean("preventRecycling");
this.recyclerView.setAdapter(this.adapter);

// Create ItemTouchHelper for swipe-to-delete and move gestures.
Expand Down
11 changes: 10 additions & 1 deletion apidoc/Titanium/UI/ListView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ events:
summary: Fired when a list row has started moving.
description: |
This event can be used to change the UI once a new drag-and-drop interaction starts.
The event properties are available in Titanium SDK 12.0.0+
The event properties are available in Titanium SDK 12.0.0+
since: "11.1.0"
platforms: [android, iphone, ipad, macos]
properties:
Expand Down Expand Up @@ -1121,6 +1121,15 @@ properties:
since: "5.4.0"
platforms: [iphone, ipad, macos]

- name: preventRecycling
description: |
If set to `true` the ListItems will keep the values. Use this only if needed e.g. when you have TextFields
or Switches in your ItemTemplate.
type: Boolean
default: false
platforms: [android]
since: "12.2.0"

- name: rowSeparatorInsets
summary: The insets for list view cells (applies to all cells).
description: |
Expand Down

0 comments on commit fe68051

Please sign in to comment.