From c6e88c81aa5c1d3528071f380193fc24572151e9 Mon Sep 17 00:00:00 2001 From: wangyingjun01 Date: Mon, 13 Oct 2025 17:28:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=A9=BA=E5=80=BC=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=EF=BC=8C=E4=BF=AE=E5=A4=8DhandleColorFilters=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E9=87=8C=E7=9A=84item=3F.keypath=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E9=9D=9E=E6=B3=95=E5=80=BC=EF=BC=8C=E5=AF=BC=E8=87=B4=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E9=97=AA=E9=80=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyingjun01 --- .../src/main/ets/LottieAnimationView.ets | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) 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); } } }