Skip to content

Commit

Permalink
refactor: path code
Browse files Browse the repository at this point in the history
  • Loading branch information
WadhahEssam committed Jan 9, 2024
1 parent 3844e52 commit e8f2b8c
Showing 1 changed file with 11 additions and 32 deletions.
43 changes: 11 additions & 32 deletions src/SvgPath.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ import { Platform, View } from 'react-native';
import { Defs, LinearGradient, Stop } from 'react-native-svg';
import ActivePoint from './ActivePoint';
import EndPoint from './EndPoint';
import {
createNewPath,
getIndexOfTheNearestXPoint,
PathObject,
useForceReRender,
} from './utils';
import { createNewPath, getIndexOfTheNearestXPoint, PathObject } from './utils';
import { DataPoint, ExtraConfig, Line } from './types';
import { ACTIVE_POINT_CONFIG, END_POINT } from './defaults';
import { AnimatedG, AnimatedPath } from './AnimatedComponents';
Expand Down Expand Up @@ -148,10 +143,8 @@ const LineComponent = ({
return ACTIVE_POINT_CONFIG.color;
}, [line?.activePointConfig?.color, line?.lineColor, isLineColorGradient]);

const [isReadyToRenderBackground, setIsReadyToRenderBackground] =
React.useState(Platform.OS === 'android');
const [localPath, setLocalPath] = React.useState<PathObject>(
createNewPath({
const localCreateNewPath = () => {
return createNewPath({
data: line?.data || [],
allData,
endSpacing: extraConfig.endSpacing || 20,
Expand All @@ -162,17 +155,14 @@ const LineComponent = ({
curve: line.curve,
calculateChartYAxisMinMax:
extraConfig.calculateChartYAxisMinMax || undefined,
})
);

const forceRerender = useForceReRender();
});
};

// forcing a re-render after x ms to fix sharedValues not causing a rerender.
useEffect(() => {
setTimeout(() => {
forceRerender();
}, 1500);
}, [extraConfig]);
const [isReadyToRenderBackground, setIsReadyToRenderBackground] =
React.useState(Platform.OS === 'android');
const [localPath, setLocalPath] = React.useState<PathObject>(
localCreateNewPath()
);

const {
startAnimation,
Expand All @@ -186,18 +176,7 @@ const LineComponent = ({
});

useEffect(() => {
const path = createNewPath({
data: line?.data || [],
allData,
endSpacing: extraConfig.endSpacing || 20,
svgHeight,
svgWidth,
isFilled: line.fillColor !== undefined,
alwaysStartYAxisFromZero: extraConfig.alwaysStartYAxisFromZero || false,
curve: line.curve,
calculateChartYAxisMinMax:
extraConfig.calculateChartYAxisMinMax || undefined,
});
const path = localCreateNewPath();

if (extraConfig.animationConfig) {
startAnimation({
Expand Down

0 comments on commit e8f2b8c

Please sign in to comment.