Skip to content

Commit

Permalink
fix: null checks (#152)
Browse files Browse the repository at this point in the history
Co-authored-by: Vittorio Cellucci <vel@qlik.com>
  • Loading branch information
2 people authored and enell committed Feb 9, 2023
1 parent 6063455 commit b721ebd
Showing 1 changed file with 33 additions and 26 deletions.
Expand Up @@ -44,29 +44,28 @@ public String getName() {
@Override
@NonNull
public View createViewInstance(ThemedReactContext reactContext) {
TableView table = new TableView(reactContext);
return table;
return new TableView(reactContext);
}

private boolean isAllFetched() {
return cols != null && rows != null;
}

private List<DataRow> processRows(TableView tableView, List<DataColumn> dataColumns) {
private void processRows(TableView tableView, List<DataColumn> dataColumns) {
ReadableArray dataRows = rows.getArray("rows");
boolean resetData = rows.getBoolean("reset");
RowFactory factory = new RowFactory(dataRows, dataColumns);
List<DataRow> transformedRows = factory.getRows();
tableView.setRows(transformedRows, resetData);
return transformedRows;
if(dataRows != null) {
boolean resetData = rows.getBoolean("reset");
RowFactory factory = new RowFactory(dataRows, dataColumns);
List<DataRow> transformedRows = factory.getRows();
tableView.setRows(transformedRows, resetData);
}
}

private List<DataColumn> processColumns(TableView tableView) {
String totalsLabel = null, totalsPosition = null;
ReadableArray totalsRows = null;

ReadableArray columns = cols.getArray("header");
ReadableArray footer = cols.getArray("footer");
ReadableMap totals = cols.getMap("totals");

if(totals != null) {
Expand All @@ -77,9 +76,11 @@ private List<DataColumn> processColumns(TableView tableView) {
}

List<DataColumn> dataColumns = new ArrayList<>();
for(int i = 0; i < columns.size(); i++) {
DataColumn column = new DataColumn(columns.getMap(i), i);
dataColumns.add(column);
if(columns != null) {
for (int i = 0; i < columns.size(); i++) {
DataColumn column = new DataColumn(columns.getMap(i), i);
dataColumns.add(column);
}
}

return dataColumns;
Expand Down Expand Up @@ -117,9 +118,11 @@ public void setFreezeFirstColumn(View view, Boolean isFreezeFirstColumn) {

@ReactProp(name = "cols")
public void setCols(View view, @Nullable ReadableMap source) {
cols = source;
TableView tableView = (TableView) (view);
initializeWhenReady(tableView);
if(source != null) {
cols = source;
TableView tableView = (TableView) (view);
initializeWhenReady(tableView);
}
}

@ReactProp(name = "isDataView")
Expand All @@ -132,23 +135,27 @@ public void setDataView(View view, boolean isDataView) {

@ReactProp(name = "rows")
public void setRows(View view, @Nullable ReadableMap source) {
TableView tableView = (TableView) (view);
rows = source;
boolean resetData = rows.getBoolean("reset");
if(source != null) {
TableView tableView = (TableView) (view);
rows = source;
boolean resetData = rows.getBoolean("reset");

if(resetData) {
initializeWhenReady(tableView);
return;
}
if (resetData) {
initializeWhenReady(tableView);
return;
}

processRows(tableView, tableView.getColumns());
processRows(tableView, tableView.getColumns());
}
}

@ReactProp(name = "size")
public void setSize(View view, @Nullable ReadableMap source) {
TableView tableView = (TableView) view;
dataSize = new DataSize(source);
tableView.setDataSize(dataSize);
if(source != null) {
TableView tableView = (TableView) view;
dataSize = new DataSize(source);
tableView.setDataSize(dataSize);
}
}

@ReactProp(name = "containerWidth")
Expand Down

0 comments on commit b721ebd

Please sign in to comment.