diff --git a/harmony/lottie/src/main/ets/LottieAnimationView.ets b/harmony/lottie/src/main/ets/LottieAnimationView.ets index 1ccc5efe..6fd4bebe 100644 --- a/harmony/lottie/src/main/ets/LottieAnimationView.ets +++ b/harmony/lottie/src/main/ets/LottieAnimationView.ets @@ -252,16 +252,35 @@ export struct LottieAnimationView { const layersData: Array = this.jsonData?.layers ?? []; const colorFiltersData: Array = (this.descriptorWrapper.props.colorFilters ?? []) as Array; + for (const item of colorFiltersData) { - const index: number = layersData.findIndex((layersItem: layersItem) => layersItem?.nm === item?.keypath); - const color: Array = this.getColorByColorFilters(item); - const isIndex: boolean = index !== (-1); - const isColor: boolean = color.length === 3; - if (isIndex && isColor) { - this.animateItem?.changeColor(color, index + 1); - this.logger.debug('colorFilters success:', item?.keypath); - } else { - this.logger.error('colorFilters fail:not find keyPath', item?.keypath); + // 添加空值检查 + if (!item || typeof item.keypath !== 'string') { + this.logger.error('colorFilters fail: invalid item or keypath', item); + continue; + } + + try { + const index: number = layersData.findIndex((layersItem: layersItem) => { + // 添加空值检查 + if (!layersItem || typeof layersItem?.nm !== 'string') { + return false; + } + return layersItem?.nm === item?.keypath; + }); + + const color: Array = this.getColorByColorFilters(item); + const isIndex: boolean = index !== (-1); + const isColor: boolean = color && color.length === 3; + + if (isIndex && isColor) { + this.animateItem?.changeColor(color, index + 1); + this.logger.debug('colorFilters success:', item?.keypath); + } else { + this.logger.error('colorFilters fail:not find keyPath', item?.keypath); + } + } catch (error) { + this.logger.error('colorFilters error processing item: ', error); } } }