Skip to content

Commit

Permalink
feat(md-3608): remove alternating colors (#81)
Browse files Browse the repository at this point in the history
* feat: remove alternating colors

* feat: data view support & isDim crash fix
  • Loading branch information
gruskal committed Sep 19, 2022
1 parent e2a2afe commit c64f09a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Expand Up @@ -24,6 +24,7 @@
public class DataProvider extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final int VIEW_TYPE_ITEM = 0;
private final int VIEW_TYPE_LOADING = 1;
boolean isDataView = false;
List<DataRow> rows = null;
List<DataColumn> dataColumns = null;
Set<SimpleViewHolder> cachedViewHolders = new HashSet<>();
Expand Down Expand Up @@ -151,8 +152,10 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
if(viewHolder instanceof SimpleViewHolder) {
SimpleViewHolder holder = (SimpleViewHolder) viewHolder;
int color = position % 2 == 0 ? Color.WHITE : 0xFFF7F7F7;
holder.setBackGroundColor(color);
if (this.isDataView) {
int color = position % 2 == 0 ? Color.WHITE : 0xFFF7F7F7;
holder.setBackGroundColor(color);
}
holder.setData(rows.get(position));
cachedViewHolders.add(holder);
}
Expand All @@ -163,6 +166,9 @@ public int getItemCount() {
return rows.size();
}

public void setDataView(boolean isDataView) {
this.isDataView = isDataView;
}
public void setRows(List<DataRow> data, boolean resetData) {
if (this.rows == null || resetData) {
int prevSize = 0;
Expand Down
Expand Up @@ -81,6 +81,12 @@ public void setCols(View view, @Nullable ReadableMap source) {

}

@ReactProp(name = "isDataView")
public void setDataView(View view, boolean isDataView) {
TableView tableView = getTableViewFrom(view);
tableView.setDataView(isDataView);
}

@ReactProp(name = "rows")
public void setRows(View view, @Nullable ReadableMap rows) {
TableView tableView = getTableViewFrom(view);
Expand Down
Expand Up @@ -100,6 +100,10 @@ public void setDataColumns(List<DataColumn> cols) {
}
}

public void setDataView(boolean isDataView) {
dataProvider.setDataView(isDataView);
}

public void setRows(List<DataRow> rows, boolean resetData) {
dataProvider.setRows(rows, resetData);
if (this.recyclerView != null) {
Expand Down

0 comments on commit c64f09a

Please sign in to comment.