Skip to content

Instantly share code, notes, and snippets.

@sturmenta
Created October 11, 2022 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturmenta/c23697ac7fb5d6b0cc763616f25051dc to your computer and use it in GitHub Desktop.
Save sturmenta/c23697ac7fb5d6b0cc763616f25051dc to your computer and use it in GitHub Desktop.
react-native progress indicator
import React from 'react';
import {useTheme} from '@react-navigation/native';
import {ProgressChart} from 'react-native-chart-kit';
import {MyThemeInterfaceColors, getPercentageInHex} from '_utils';
import {useComponentTrackTrace} from '_hooks';
interface ShowProgressProps {
progress: number;
height?: number;
width?: number;
}
export const ShowProgress: React.FC<ShowProgressProps> = ({
progress,
height = 50,
width = 50,
}: ShowProgressProps) => {
useComponentTrackTrace('Component_ShowProgress');
const colors = useTheme().colors as unknown as MyThemeInterfaceColors;
return (
<ProgressChart
data={{data: [progress]}}
width={width}
height={height}
strokeWidth={6}
radius={20}
chartConfig={{
backgroundGradientFromOpacity: 0,
backgroundGradientToOpacity: 0,
color: (opacity = 1) =>
colors.primary + getPercentageInHex(opacity * 100),
}}
hideLegend={true}
/>
);
};
@sturmenta
Copy link
Author

use: <ShowProgress progress={0.4} />

Screen Shot 2022-10-11 at 05 29 42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment