1.1.0 • Published 1 year ago

@wz-mobile/rn-gauge v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

rn-gauge Known Vulnerabilities CodeQL semantic-release: angular

🍩 React Native Beautiful Gauge ✨

Performant, customizable, beautiful jauge component based on skia engine 🚀

alt text

Preview

Installation

yarn add @wz-mobile/rn-gauge

Get Started

import { Gauge } from '@wz-mobile/rn-gauge';

<Gauge
  emptyColor="#C1C1C1"
  colors={['cyan', 'magenta', 'yellow', 'red', 'white']}
  sweepAngle={250}
  strokeWidth={10}
  fillProgress={60}
  renderLabel={Label}
  size={200}
  thickness={60}
/>;

Features

  • Gradient Colors
  • Sweep Angle resizeable
  • Built on top of Skia
  • Written in TypeScript
  • Smooth Animated effect
  • Use your own needle component

Props

NameTypeDefault valueDescription
strokeWidthnumberThe external stroke width of the gauge
thicknessnumber50Gauge thickness
colors (required)string[]Colors filling the gauge progress
stepsnumber[]Steps as string array to display steps on the gauge
emptyColor (required)stringColor to display the empty part of the gauge
renderStep(props: { getX: GetAxisValue; getY: GetAxisValue; step: number; index: number; radius: number; rotationAngle: number; }) => ElementRender step function
fillProgress (required)numberThe progress value of the gauge.
sweepAngle (required)number250Sweep angle of gauge, default is 250 ( how wide is the gauge )
renderNeedle(params: { getNeedleStyle: GetNeedleStyle; }) => ReactNodeRender prop for needle component, default is null
renderLabel (required)() => ReactNodeMethod to render the label center of the gauge
size (required)numberSize given to the component
canvasStyleStyleProp<ViewStyle>Custom Canvas style
shadowPropsAnimatedProps<ShadowProps>Shadow props if wanted, could provide nice shadow effects
springConfigSpringConfigSpring config for fill progress animation
showGaugeCenterbooleanShow gauge center

Use your own needle component

This sample shows you how to use a custom needle component, it's recommended to set showGaugeCenter to true to fine tune the parameters passed to getNeedleStyle function.

const SimpleNeedle: GaugeProps['renderNeedle'] = ({ getNeedleStyle }) => (
  <>
    <Animated.View style={[getNeedleStyle(80, 80, 14.5, 0, -7.6)]}>
      <AnimatedImage
        style={{ width: 80, height: 80 }}
        resizeMode="contain"
        source={SimpleNeedleImage}
      />
    </Animated.View>
  </>
);

What is sweepAngle ?

alt text

Highly customizable

To Do

  • RTL Support

Full Sample

You can check full sample in App.tsx located in the example folder for more details about implementation.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT