import React from 'react'; import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'; import { DEFAULT_BRUSH_PREVIEW, DEFAULT_DELETE_BUTTON_COLOR, DEFAULT_OTHER_BUTTONS_COLOR, DEFAULT_TOOL, } from './constants'; import { DrawingTool } from './types'; import BrushPreview, { BrushPreviewProps } from './BrushPreview'; import Button from './Button'; import { Brush, Delete, Eraser, Palette, Undo } from './icons'; export interface CanvasControlsProps extends BrushPreviewProps { /** * Callback when the clear button is pressed */ onClear?: () => void; /** * Callback when the undo button is pressed */ onUndo?: () => void; /** * Callback when the eraser button is pressed */ onToggleEraser?: () => void; /** * Callback when the brush properties button is pressed */ onToggleBrushProperties?: () => void; /** * Override the style of the buttons */ buttonStyle?: StyleProp; /** * Initial tool of the canvas * @default DEFAULT_TOOL */ tool?: DrawingTool; /** * Delete button color * @default DEFAULT_DELETE_BUTTON_COLOR */ deleteButtonColor?: string; /** * Other buttons color (undo and eraser mode toggle) * @default DEFAULT_OTHER_BUTTONS_COLOR */ otherButtonsColor?: string; } /** * Bottom section of the canvas, allowing the user to change the brush * properties, clear the canvas, undo strokes. * * The buttons will be visible if the corresponding callback is provided. */ const CanvasControls: React.FC = ({ onClear, onUndo, onToggleEraser, onToggleBrushProperties, buttonStyle, tool = DEFAULT_TOOL, deleteButtonColor = DEFAULT_DELETE_BUTTON_COLOR, otherButtonsColor = DEFAULT_OTHER_BUTTONS_COLOR, color, thickness, opacity, brushPreview = DEFAULT_BRUSH_PREVIEW, }) => ( {onClear && ( )} {onUndo && ( )} {onToggleEraser && ( )} {onToggleBrushProperties && color && ( )} ); const styles = StyleSheet.create({ container: { height: 80, width: '100%', justifyContent: 'center', }, content: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', marginHorizontal: 15, }, buttonsContainer: { flexDirection: 'row', justifyContent: 'space-between', }, endButton: { marginLeft: 10, }, }); export default CanvasControls;