Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: null checks #152

Merged
merged 1 commit into from Nov 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor, we can avoid all this indentation by returning early. Same for other checks

if(dataRows == null) {
  return;
}

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