From 7f99da1232b8880f9facc75764001db7c6546423 Mon Sep 17 00:00:00 2001 From: Wadah Esam Date: Tue, 14 Nov 2023 01:45:48 +0300 Subject: [PATCH] fix: another attempt to fix gradient line color on android --- src/LineChart.tsx | 1 - src/SvgPath.tsx | 96 +++++++++++++++++++++++++---------------------- 2 files changed, 51 insertions(+), 46 deletions(-) diff --git a/src/LineChart.tsx b/src/LineChart.tsx index cf4f54e..5b98c0d 100644 --- a/src/LineChart.tsx +++ b/src/LineChart.tsx @@ -150,7 +150,6 @@ function LineChart({ svgWidth={svgWidth} activeTouch={activeTouch} activeTouchX={activeTouchX} - backgroundColor={backgroundColor} extraConfig={extraConfig} initialActivePoint={extraConfig?.initialActivePoint} endSpacing={extraConfig?.endSpacing} diff --git a/src/SvgPath.tsx b/src/SvgPath.tsx index 4926254..7214999 100644 --- a/src/SvgPath.tsx +++ b/src/SvgPath.tsx @@ -1,5 +1,10 @@ /* eslint-disable react/no-array-index-key */ -import React, { useCallback, useEffect } from 'react'; +import React, { + JSXElementConstructor, + ReactElement, + useCallback, + useEffect, +} from 'react'; import { interpolate, SharedValue, @@ -26,7 +31,6 @@ const SvgPath = ({ svgWidth, activeTouchX, activeTouch, - backgroundColor, extraConfig, onPointChange, endSpacing, @@ -37,7 +41,6 @@ const SvgPath = ({ svgWidth: number; activeTouchX: SharedValue; activeTouch: SharedValue; - backgroundColor?: string; extraConfig: ExtraConfig; endSpacing?: number; initialActivePoint?: number; @@ -99,7 +102,6 @@ const SvgPath = ({ svgWidth={svgWidth} activeIndex={activeIndex} activeTouch={activeTouch} - backgroundColor={backgroundColor} identifier={`${index}`} extraConfig={extraConfig} onPointChange={index === 0 ? onPointChange : undefined} @@ -120,7 +122,6 @@ const LineComponent = ({ svgWidth, activeTouch, activeIndex, - backgroundColor, identifier, extraConfig, onPointChange, @@ -131,7 +132,6 @@ const LineComponent = ({ svgWidth: number; activeTouch: SharedValue; activeIndex: SharedValue; - backgroundColor?: string; identifier: string; extraConfig: ExtraConfig; onPointChange?: (point?: DataPoint) => void; @@ -199,52 +199,58 @@ const LineComponent = ({ allData, ]); - if (localPath === undefined) { - return null; - } - const getBackgroundIdentifier = () => { + return `${identifier}`; + }; + + const getStopPoints = useCallback(() => { if (isLineColorGradient) { - return `${identifier}gradient`; + const colors = line.lineColor as string[]; + return colors.map((color, index) => { + const offset = (index / (colors.length - 1)) * 100; + + return ( + + ); + }); } - return `${identifier}solid`; - }; + + return ( + + ); + }, [line.lineColor]); + + if (localPath === undefined) { + return null; + } return ( <> - {!isLineColorGradient && ( - - - - - - )} - - {isLineColorGradient && ( - - - - - )} + + { + getStopPoints() as ReactElement< + any, + string | JSXElementConstructor + >[] + } +