0.2.2 • Published 2 years ago

@benjeau/react-native-draw-extras v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@benjeau/react-native-draw-extras

NPM badge CircleCI Status Platform badge

Extra components to complement @benjeau/react-native-draw:

  • CanvasControls
    • Clear drawing
    • Undo last path
    • Includes the BrushPreview component
    • Toggle between drawing and erasing
    • Toggle visibility of BrushProperties
  • BrushPreview
    • Displays an SVG preview of the stroke (color, thickness, opacity)
  • BrushProperties
    • Includes the ColorPicker component
    • Slider to change brush opacity
    • Slider to change brush size
  • ColorPicker
    • Grid of color where the user can select a color

Installation

npm install @benjeau/react-native-draw-extras
# or
yarn add @benjeau/react-native-draw-extras

Also, you need to install @react-native-community/slider and react-native-svg, and follow their installation instructions.

Example

Please see the example Expo application showcasing the components

Props

CanvasControls

Contains all the props of BrushProperties and the following:

namedescriptiontypedefault
onClearCallback when the clear button is pressed() => void-
onUndoCallback when the undo button is pressed() => void-
onToggleEraserCallback when the eraser button is pressed() => void-
onToggleBrushPropertiesCallback when the brush properties button is pressed() => void-
buttonStyleOverride the style of the buttonsStyleProp<ViewStyle>-
toolInitial tool of the canvasbrush or eraser-
deleteButtonColorDelete button colorstring#81090A
otherButtonsColorOther buttons color (undo and eraser mode toggle)string#DDD

BrushPreview

namedescriptiontypedefault
colorColor of the brush strokesstring- (required)
thicknessThickness of the brush strokesnumber- (required)
opacityOpacity of the brush strokesnumber- (required)
brushPreviewBrush preview preset, for different kinds of previewsstroke or dot or none- (required)

BrushProperties

Contains all the props of ColorPicker and the following:

namedescriptiontypedefault
thicknessThickness of the brush strokesnumber3
opacityOpacity of the brush strokesnumber1
onThicknessChangeCallback when brush size is changed via the slider(newThickness: number) => void-
onOpacityChangeCallback when brush opacity is changed via the slider(newOpacity: number) => void-
opacityStepStep value of the opacity slider, should be between 0 and 1number0.1
thicknessMinMinimum value of the thickness slidernumber5
thicknessMaxMaximum value of the thickness slidernumber35
thicknessStepStep value of the thickness slider, should be between props.thicknessMin and props.thicknessMaxnumber1
sliderColorSlider colorstring#000
styleStyle of the containerStyleProp<ViewStyle>-

ColorPicker

namedescriptiontypedefault
colorBrush color, one from the colors providedstring- (required)
onColorChangeCallback when a color is selected(newColor: string) => void- (required)
colorsColor picker colors, specifying the color picker sections each containing rows of colors. First array defines the sections, second one defines the rows, and the last one defines the columns.string[][][]DEFAULT_COLORS
styleStyle of the containerStyleProp<ViewStyle>-

Helper functions

  • If you want to know if a color is bright or not, isBright() is available to detect if a HEX color is bright or dark.

Contributing

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

License

MIT