Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add shouldCancelWhenOutside parameter in Canva.tsx #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/react-native-draw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ https://user-images.githubusercontent.com/22248828/152837922-757d3a13-1d35-409a-
### Canvas

| name | description | type | default |
| ----------------------- | ----------------------------------------------------------------------------------------- | ---------------------------------------------- | ----------------------------- |
|-------------------------|-------------------------------------------------------------------------------------------| ---------------------------------------------- |-------------------------------|
| `color` | Color of the brush strokes | `string` | - (required) |
| `thickness` | Thickness of the brush strokes | `number` | - (required) |
| `opacity` | Opacity of the brush strokes | `number` | - (required) |
Expand All @@ -220,6 +220,7 @@ https://user-images.githubusercontent.com/22248828/152837922-757d3a13-1d35-409a-
| `tool` | Initial tool of the canvas | `brush` or `eraser` | `brush` |
| `combineWithLatestPath` | Combine current path with the last path if it's the same color, thickness, and opacity | `boolean` | `false` |
| `enabled` | Allows for the canvas to be drawn on, put to false if you want to disable/lock the canvas | `boolean` | `true` |
| `shouldCancelWhenOutside`| When true, drawing will cancel if the touch moves outside of the view | `boolean` | `false` |

### SimplifyOptions

Expand Down
9 changes: 8 additions & 1 deletion packages/react-native-draw/src/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ export interface CanvasProps {
* @default true
*/
enabled?: boolean;

/**
* when true, drawing will cancel the gesture if the touch moves outside of the view
* @default false
*/
shouldCancelWhenOutside?: boolean;
}

export interface SimplifyOptions {
Expand Down Expand Up @@ -219,6 +225,7 @@ const Canvas = forwardRef<CanvasRef, CanvasProps>(
tool = DEFAULT_TOOL,
combineWithLatestPath = false,
enabled = true,
shouldCancelWhenOutside = false,
},
ref
) => {
Expand Down Expand Up @@ -435,7 +442,7 @@ const Canvas = forwardRef<CanvasRef, CanvasProps>(
top: 0,
left: 0,
})
.shouldCancelWhenOutside(true)
.shouldCancelWhenOutside(shouldCancelWhenOutside)
.enabled(enabled);

return (
Expand Down