Skip to content

Unable to draw anything on Canvas. #70

Description

@mhumza37dev

On what kind of device are you using this library?

  • Android
  • iOS
  • Web

Environment

- OS:macOS (Monterey)
- react-native:0.66.0
- @benjeau/react-native-draw:0.7.0

Current Behavior

I have followed every installation steps mentioned in the docs, still not been able to draw anything on the canvas.
Everytime i start dragging to draw a shape or line it shows me a dot where i start to drag from and then the dot vanishes.

I have also put gesture handler import on top or app.js and index.js.

@BenJeau can you help me out ?

screen-20220726-064108.mp4

Expected Behavior

I need to be able to draw on Canvas.

Steps To Reproduce

I just simple installed the package following the documentation and sarted the project from the example project.
That's all.

Anything else?

Here is my Component :

import React, {useRef, useState} from 'react';
import {Animated, StyleSheet, View} from 'react-native';
import {Canvas, CanvasRef, DrawingTool} from '@benjeau/react-native-draw';

import {
BrushProperties,
CanvasControls,
DEFAULT_COLORS,
} from '@benjeau/react-native-draw-extras';
import {height, SIZES, width} from '../constants';

export default React.forwardRef((props, ref) => {
// const canvasRef = useRef(null);
console.log('props ======= >>>>>> ', props);
const [color, setColor] = useState(DEFAULT_COLORS[0][0][0]);
const [thickness, setThickness] = useState(5);
const [opacity, setOpacity] = useState(1);
const [tool, setTool] = useState(DrawingTool.Brush);
const [visibleBrushProperties, setVisibleBrushProperties] = useState(false);

const handleUndo = () => {
ref.current?.undo();
};

const handleClear = () => {
ref.current?.clear();
};

const handleToggleEraser = () => {
setTool(prev =>
prev === DrawingTool.Brush ? DrawingTool.Eraser : DrawingTool.Brush,
);
};

const [overlayOpacity] = useState(new Animated.Value(0));

const handleToggleBrushProperties = () => {
if (!visibleBrushProperties) {
setVisibleBrushProperties(true);

  Animated.timing(overlayOpacity, {
    toValue: 1,
    duration: 350,
    useNativeDriver: true,
  }).start();
} else {
  Animated.timing(overlayOpacity, {
    toValue: 0,
    duration: 350,
    useNativeDriver: true,
  }).start(() => {
    setVisibleBrushProperties(false);
  });
}

};

return (
<>
<Canvas
ref={ref}
height={height * 0.8}
width={width * 0.97}
color={color}
thickness={thickness}
opacity={opacity}
tool={tool}
style={{
borderBottomWidth: StyleSheet.hairlineWidth,
borderColor: '#ccc',
alignSelf: 'center',
}}
/>

{!props.toolsVisible && (
<CanvasControls
onUndo={handleUndo}
onClear={handleClear}
onToggleEraser={handleToggleEraser}
onToggleBrushProperties={handleToggleBrushProperties}
tool={tool}
color={color}
opacity={opacity}
thickness={thickness}
buttonStyle={{elevation: 0}}
/>
)}
{!props.toolsVisible && visibleBrushProperties && (
<BrushProperties
color={color}
thickness={thickness}
opacity={opacity}
onColorChange={setColor}
onThicknessChange={setThickness}
onOpacityChange={setOpacity}
style={{
position: 'absolute',
bottom: 80,
left: 0,
right: 0,
padding: SIZES.fifteen,
backgroundColor: '#15',
borderTopEndRadius: SIZES.fifteen,
borderTopStartRadius: SIZES.fifteen,
paddingTop: SIZES.twenty,
borderWidth: StyleSheet.hairlineWidth,
borderBottomWidth: 0,
borderTopColor: '#ccc',
opacity: overlayOpacity,
}}
/>
)}

</>
);
});

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions