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:
parent
37d2df9eea
commit
4eeebf6118
@ -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,6 +61,7 @@ class FlowAdapter extends RecyclerView.Adapter<FlowAdapter.DoricViewHolder> {
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) {
|
||||
try {
|
||||
JSValue jsValue = getItemModel(position);
|
||||
boolean fullSpan = this.loadMore && position >= this.itemCount;
|
||||
if (jsValue != null && jsValue.isObject()) {
|
||||
@ -90,6 +90,9 @@ class FlowAdapter extends RecyclerView.Adapter<FlowAdapter.DoricViewHolder> {
|
||||
&& !TextUtils.isEmpty(this.flowLayoutNode.onLoadMoreFuncId)) {
|
||||
callLoadMore();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
flowLayoutNode.getDoricContext().getDriver().getRegistry().onException(flowLayoutNode.getDoricContext(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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,6 +59,7 @@ class HorizontalListAdapter extends RecyclerView.Adapter<HorizontalListAdapter.D
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) {
|
||||
try {
|
||||
JSValue jsValue = getItemModel(position);
|
||||
if (jsValue != null && jsValue.isObject()) {
|
||||
JSObject jsObject = jsValue.asObject();
|
||||
@ -71,6 +72,9 @@ class HorizontalListAdapter extends RecyclerView.Adapter<HorizontalListAdapter.D
|
||||
&& !TextUtils.isEmpty(this.horizontalListNode.onLoadMoreFuncId)) {
|
||||
callLoadMore();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
horizontalListNode.getDoricContext().getDriver().getRegistry().onException(horizontalListNode.getDoricContext(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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,6 +59,7 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) {
|
||||
try {
|
||||
JSValue jsValue = getItemModel(position);
|
||||
if (jsValue != null && jsValue.isObject()) {
|
||||
JSObject jsObject = jsValue.asObject();
|
||||
@ -71,6 +72,9 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
|
||||
&& !TextUtils.isEmpty(this.listNode.onLoadMoreFuncId)) {
|
||||
callLoadMore();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
listNode.getDoricContext().getDriver().getRegistry().onException(listNode.getDoricContext(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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,6 +60,7 @@ class SlideAdapter extends RecyclerView.Adapter<SlideAdapter.DoricViewHolder> {
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) {
|
||||
try {
|
||||
JSValue jsValue = getItemModel(position);
|
||||
if (jsValue != null && jsValue.isObject()) {
|
||||
JSObject jsObject = jsValue.asObject();
|
||||
@ -68,6 +68,9 @@ class SlideAdapter extends RecyclerView.Adapter<SlideAdapter.DoricViewHolder> {
|
||||
holder.slideItemNode.reset();
|
||||
holder.slideItemNode.blend(jsObject.getProperty("props").asObject());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sliderNode.getDoricContext().getDriver().getRegistry().onException(sliderNode.getDoricContext(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -459,6 +459,7 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe
|
||||
}
|
||||
|
||||
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
@try {
|
||||
NSUInteger position = (NSUInteger) indexPath.row;
|
||||
NSDictionary *model = [self itemModelAt:position];
|
||||
NSDictionary *props = model[@"props"];
|
||||
@ -494,6 +495,10 @@ - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collection
|
||||
[node requestLayout];
|
||||
[self callItem:position size:node.view.frame.size];
|
||||
return cell;
|
||||
} @catch (NSException *exception) {
|
||||
[self.doricContext.driver.registry onException:exception inContext:self.doricContext];
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSIndexPath *)collectionView:(UICollectionView *)collectionView targetIndexPathForMoveFromItemAtIndexPath:(NSIndexPath *)currentIndexPath toProposedIndexPath:(NSIndexPath *)proposedIndexPath {
|
||||
|
@ -240,6 +240,7 @@ - (void)callLoadMore {
|
||||
}
|
||||
|
||||
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
@try {
|
||||
NSUInteger position = (NSUInteger) indexPath.row;
|
||||
NSDictionary *model = [self itemModelAt:position];
|
||||
NSDictionary *props = model[@"props"];
|
||||
@ -271,6 +272,10 @@ - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collection
|
||||
[node requestLayout];
|
||||
[self callItem:position width:node.view.width];
|
||||
return cell;
|
||||
} @catch (NSException *exception) {
|
||||
[self.doricContext.driver.registry onException:exception inContext:self.doricContext];
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
|
||||
|
@ -242,6 +242,7 @@ - (void)callLoadMore {
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
@try {
|
||||
NSUInteger position = (NSUInteger) indexPath.row;
|
||||
NSDictionary *model = [self itemModelAt:position];
|
||||
NSDictionary *props = model[@"props"];
|
||||
@ -273,6 +274,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
|
||||
[node requestLayout];
|
||||
[self callItem:position height:node.view.height];
|
||||
return cell;
|
||||
} @catch (NSException *exception) {
|
||||
[self.doricContext.driver.registry onException:exception inContext:self.doricContext];
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
|
@ -177,6 +177,7 @@ - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectio
|
||||
}
|
||||
|
||||
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
@try {
|
||||
NSUInteger position = (NSUInteger) indexPath.row;
|
||||
NSDictionary *model = [self itemModelAt:position];
|
||||
NSDictionary *props = model[@"props"];
|
||||
@ -195,6 +196,10 @@ - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collection
|
||||
[node.view.doricLayout apply:CGSizeMake(collectionView.width, collectionView.height)];
|
||||
[node requestLayout];
|
||||
return cell;
|
||||
} @catch (NSException *exception) {
|
||||
[self.doricContext.driver.registry onException:exception inContext:self.doricContext];
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
|
Reference in New Issue
Block a user