Feature/fix npe exception (#566)
* android: add exception catch for list flowlayout scroller type * iOS: add exception catch for list flowlayout scroller type
This commit is contained in:
@@ -20,16 +20,15 @@ import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSArray;
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSNull;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||
import pub.doric.async.AsyncResult;
|
||||
import pub.doric.shader.ViewNode;
|
||||
|
||||
@@ -62,33 +61,37 @@ class FlowAdapter extends RecyclerView.Adapter<FlowAdapter.DoricViewHolder> {
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) {
|
||||
JSValue jsValue = getItemModel(position);
|
||||
boolean fullSpan = this.loadMore && position >= this.itemCount;
|
||||
if (jsValue != null && jsValue.isObject()) {
|
||||
JSObject jsObject = jsValue.asObject();
|
||||
holder.flowLayoutItemNode.setId(jsObject.getProperty("id").asString().value());
|
||||
JSObject props = jsObject.getProperty("props").asObject();
|
||||
holder.flowLayoutItemNode.reset();
|
||||
holder.flowLayoutItemNode.blend(props);
|
||||
JSValue fullSpanValue = props.getProperty("fullSpan");
|
||||
if (fullSpanValue.isBoolean()) {
|
||||
fullSpan = fullSpanValue.asBoolean().value();
|
||||
try {
|
||||
JSValue jsValue = getItemModel(position);
|
||||
boolean fullSpan = this.loadMore && position >= this.itemCount;
|
||||
if (jsValue != null && jsValue.isObject()) {
|
||||
JSObject jsObject = jsValue.asObject();
|
||||
holder.flowLayoutItemNode.setId(jsObject.getProperty("id").asString().value());
|
||||
JSObject props = jsObject.getProperty("props").asObject();
|
||||
holder.flowLayoutItemNode.reset();
|
||||
holder.flowLayoutItemNode.blend(props);
|
||||
JSValue fullSpanValue = props.getProperty("fullSpan");
|
||||
if (fullSpanValue.isBoolean()) {
|
||||
fullSpan = fullSpanValue.asBoolean().value();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
|
||||
((StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams()).setFullSpan(fullSpan);
|
||||
} else if (fullSpan) {
|
||||
StaggeredGridLayoutManager.LayoutParams layoutParams = new StaggeredGridLayoutManager.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
holder.itemView.getLayoutParams().height
|
||||
);
|
||||
layoutParams.setFullSpan(true);
|
||||
holder.itemView.setLayoutParams(layoutParams);
|
||||
}
|
||||
if (this.loadMore
|
||||
&& position >= this.itemCount
|
||||
&& !TextUtils.isEmpty(this.flowLayoutNode.onLoadMoreFuncId)) {
|
||||
callLoadMore();
|
||||
if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
|
||||
((StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams()).setFullSpan(fullSpan);
|
||||
} else if (fullSpan) {
|
||||
StaggeredGridLayoutManager.LayoutParams layoutParams = new StaggeredGridLayoutManager.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
holder.itemView.getLayoutParams().height
|
||||
);
|
||||
layoutParams.setFullSpan(true);
|
||||
holder.itemView.setLayoutParams(layoutParams);
|
||||
}
|
||||
if (this.loadMore
|
||||
&& position >= this.itemCount
|
||||
&& !TextUtils.isEmpty(this.flowLayoutNode.onLoadMoreFuncId)) {
|
||||
callLoadMore();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
flowLayoutNode.getDoricContext().getDriver().getRegistry().onException(flowLayoutNode.getDoricContext(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -21,15 +21,14 @@ import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSArray;
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSNull;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import pub.doric.async.AsyncResult;
|
||||
import pub.doric.shader.ViewNode;
|
||||
|
||||
@@ -49,6 +48,7 @@ class HorizontalListAdapter extends RecyclerView.Adapter<HorizontalListAdapter.D
|
||||
int itemCount = 0;
|
||||
int loadAnchor = -1;
|
||||
boolean loadMore = false;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public DoricViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
@@ -59,17 +59,21 @@ class HorizontalListAdapter extends RecyclerView.Adapter<HorizontalListAdapter.D
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) {
|
||||
JSValue jsValue = getItemModel(position);
|
||||
if (jsValue != null && jsValue.isObject()) {
|
||||
JSObject jsObject = jsValue.asObject();
|
||||
holder.horizontalListItemNode.setId(jsObject.getProperty("id").asString().value());
|
||||
holder.horizontalListItemNode.reset();
|
||||
holder.horizontalListItemNode.blend(jsObject.getProperty("props").asObject());
|
||||
}
|
||||
if (this.loadMore
|
||||
&& position >= this.itemCount
|
||||
&& !TextUtils.isEmpty(this.horizontalListNode.onLoadMoreFuncId)) {
|
||||
callLoadMore();
|
||||
try {
|
||||
JSValue jsValue = getItemModel(position);
|
||||
if (jsValue != null && jsValue.isObject()) {
|
||||
JSObject jsObject = jsValue.asObject();
|
||||
holder.horizontalListItemNode.setId(jsObject.getProperty("id").asString().value());
|
||||
holder.horizontalListItemNode.reset();
|
||||
holder.horizontalListItemNode.blend(jsObject.getProperty("props").asObject());
|
||||
}
|
||||
if (this.loadMore
|
||||
&& position >= this.itemCount
|
||||
&& !TextUtils.isEmpty(this.horizontalListNode.onLoadMoreFuncId)) {
|
||||
callLoadMore();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
horizontalListNode.getDoricContext().getDriver().getRegistry().onException(horizontalListNode.getDoricContext(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -21,15 +21,14 @@ import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSArray;
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSNull;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import pub.doric.async.AsyncResult;
|
||||
import pub.doric.shader.ViewNode;
|
||||
|
||||
@@ -49,6 +48,7 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
|
||||
int itemCount = 0;
|
||||
int loadAnchor = -1;
|
||||
boolean loadMore = false;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public DoricViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
@@ -59,17 +59,21 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) {
|
||||
JSValue jsValue = getItemModel(position);
|
||||
if (jsValue != null && jsValue.isObject()) {
|
||||
JSObject jsObject = jsValue.asObject();
|
||||
holder.listItemNode.setId(jsObject.getProperty("id").asString().value());
|
||||
holder.listItemNode.reset();
|
||||
holder.listItemNode.blend(jsObject.getProperty("props").asObject());
|
||||
}
|
||||
if (this.loadMore
|
||||
&& position >= this.itemCount
|
||||
&& !TextUtils.isEmpty(this.listNode.onLoadMoreFuncId)) {
|
||||
callLoadMore();
|
||||
try {
|
||||
JSValue jsValue = getItemModel(position);
|
||||
if (jsValue != null && jsValue.isObject()) {
|
||||
JSObject jsObject = jsValue.asObject();
|
||||
holder.listItemNode.setId(jsObject.getProperty("id").asString().value());
|
||||
holder.listItemNode.reset();
|
||||
holder.listItemNode.blend(jsObject.getProperty("props").asObject());
|
||||
}
|
||||
if (this.loadMore
|
||||
&& position >= this.itemCount
|
||||
&& !TextUtils.isEmpty(this.listNode.onLoadMoreFuncId)) {
|
||||
callLoadMore();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
listNode.getDoricContext().getDriver().getRegistry().onException(listNode.getDoricContext(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -20,15 +20,14 @@ import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSArray;
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSNull;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import pub.doric.async.AsyncResult;
|
||||
import pub.doric.shader.ViewNode;
|
||||
|
||||
@@ -61,12 +60,16 @@ class SlideAdapter extends RecyclerView.Adapter<SlideAdapter.DoricViewHolder> {
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) {
|
||||
JSValue jsValue = getItemModel(position);
|
||||
if (jsValue != null && jsValue.isObject()) {
|
||||
JSObject jsObject = jsValue.asObject();
|
||||
holder.slideItemNode.setId(jsObject.getProperty("id").asString().value());
|
||||
holder.slideItemNode.reset();
|
||||
holder.slideItemNode.blend(jsObject.getProperty("props").asObject());
|
||||
try {
|
||||
JSValue jsValue = getItemModel(position);
|
||||
if (jsValue != null && jsValue.isObject()) {
|
||||
JSObject jsObject = jsValue.asObject();
|
||||
holder.slideItemNode.setId(jsObject.getProperty("id").asString().value());
|
||||
holder.slideItemNode.reset();
|
||||
holder.slideItemNode.blend(jsObject.getProperty("props").asObject());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sliderNode.getDoricContext().getDriver().getRegistry().onException(sliderNode.getDoricContext(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user