From 98f2d29cee469b34f86d9c886eaae7b8c51f00f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Thu, 8 Jul 2021 09:48:24 +0800 Subject: [PATCH] fix crash when looped slider with item count zero --- .../src/main/java/pub/doric/shader/slider/SlideAdapter.java | 6 +++--- doric-iOS/Pod/Classes/Shader/DoricSliderNode.m | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/shader/slider/SlideAdapter.java b/doric-android/doric/src/main/java/pub/doric/shader/slider/SlideAdapter.java index e2e06638..45ad3ad5 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/slider/SlideAdapter.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/slider/SlideAdapter.java @@ -62,7 +62,7 @@ class SlideAdapter extends RecyclerView.Adapter { @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 { @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 { @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(); } diff --git a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m index 3e3ddcae..6f8d3867 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m @@ -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;