fix crash when looped slider with item count zero

This commit is contained in:
王劲鹏 2021-07-08 09:48:24 +08:00 committed by osborn
parent e6595d5c51
commit 98f2d29cee
2 changed files with 4 additions and 4 deletions

View File

@ -62,7 +62,7 @@ class SlideAdapter extends RecyclerView.Adapter<SlideAdapter.DoricViewHolder> {
@Override
public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) {
JSValue jsValue = getItemModel(position);
if (jsValue.isObject()) {
if (jsValue != null && jsValue.isObject()) {
JSObject jsObject = jsValue.asObject();
holder.slideItemNode.setId(jsObject.getProperty("id").asString().value());
holder.slideItemNode.blend(jsObject.getProperty("props").asObject());
@ -71,7 +71,7 @@ class SlideAdapter extends RecyclerView.Adapter<SlideAdapter.DoricViewHolder> {
@Override
public int getItemCount() {
if (loop) {
if (loop && itemCount > 0) {
return itemCount + 2;
} else {
return itemCount;
@ -81,7 +81,7 @@ class SlideAdapter extends RecyclerView.Adapter<SlideAdapter.DoricViewHolder> {
@Override
public int getItemViewType(int position) {
JSValue value = getItemModel(position);
if (value.isObject()) {
if (value != null && value.isObject()) {
if (value.asObject().getProperty("identifier").isString()) {
return value.asObject().getProperty("identifier").asString().value().hashCode();
}

View File

@ -121,7 +121,7 @@ - (void)blendView:(UICollectionView *)view forPropName:(NSString *)name propValu
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (self.loop) {
if (self.loop && self.itemCount > 0) {
return self.itemCount + 2;
} else {
return self.itemCount;