Skip to content
Merged
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
214 changes: 105 additions & 109 deletions README.md

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

buildscript {
repositories {
jcenter()
google()
}
dependencies {
Expand All @@ -16,7 +15,6 @@ buildscript {
allprojects {
repositories {
mavenLocal()
jcenter()
google()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
Expand Down
31 changes: 18 additions & 13 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import {
ViewProperties,
ViewProps,
StyleProp,
ViewStyle
} from "react-native"
Expand Down Expand Up @@ -87,26 +87,31 @@ export interface SketchCanvasProps {
onPathsChange?: (pathsCount: number) => void
}

export class SketchCanvas extends React.Component<SketchCanvasProps & ViewProperties> {
export class SketchCanvas extends React.Component<SketchCanvasProps & ViewProps> {
clear(): void
undo(): number
addPath(data: Path): void
deletePath(id: number): void

/**
* @param imageType "png" or "jpg"
* @param includeImage Set to `true` to include the image loaded from `LocalSourceImage`
* @param includeText Set to `true` to include the text drawn from `Text`.
* @param cropToImageSize Set to `true` to crop output image to the image loaded from `LocalSourceImage`
* @param {imageType} imageType "png" or "jpg"
* @param {boolean} transparent
* @param {string} folder
* @param {string} filename
* @param {includeImage} includeImage Set to `true` to include the image loaded from `LocalSourceImage`
* @param {includeText} includeText Set to `true` to include the text drawn from `Text`.
* @param {boolean} cropToImageSize Set to `true` to crop output image to the image loaded from `LocalSourceImage`
*/
save(imageType: ImageType, transparent: boolean, folder: string, filename: string, includeImage: boolean, includeText: boolean, cropToImageSize: boolean): void
getPaths(): Path[]

/**
* @param imageType "png" or "jpg"
* @param includeImage Set to `true` to include the image loaded from `LocalSourceImage`
* @param includeText Set to `true` to include the text drawn from `Text`.
* @param cropToImageSize Set to `true` to crop output image to the image loaded from `LocalSourceImage`
* @param {imageType} imageType "png" or "jpg"
* @param {boolean} transparent
* @param {boolean} includeImage Set to `true` to include the image loaded from `LocalSourceImage`
* @param {boolean} includeText Set to `true` to include the text drawn from `Text`.
* @param {boolean} cropToImageSize Set to `true` to crop output image to the image loaded from `LocalSourceImage`
* @param {*} callback
*/
getBase64(imageType: ImageType, transparent: boolean, includeImage: boolean, includeText: boolean, cropToImageSize: boolean, callback: (error: any, result?: string) => void): void

Expand Down Expand Up @@ -156,15 +161,15 @@ export interface RNSketchCanvasProps {
text?: CanvasText[]
/**
* {
* path: string,
* directory: string,
* path: string,
* directory: string,
* mode: 'AspectFill' | 'AspectFit' | 'ScaleToFill'
* }
*/
localSourceImage?: LocalSourceImage
}

export default class RNSketchCanvas extends React.Component<RNSketchCanvasProps & ViewProperties> {
export default class RNSketchCanvas extends React.Component<RNSketchCanvasProps & ViewProps> {
clear(): void
undo(): number
addPath(data: Path): void
Expand Down
13 changes: 4 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'
import ReactNative, {
View,
Text,
TouchableOpacity,
FlatList,
ViewPropTypes,
} from 'react-native'
import { ViewPropTypes } from 'deprecated-react-native-prop-types'
import { View, TouchableOpacity, FlatList } from 'react-native'
import SketchCanvas from './src/SketchCanvas'
import { requestPermissions } from './src/handlePermissions';

Expand Down Expand Up @@ -156,7 +151,7 @@ export default class RNSketchCanvas extends React.Component {
this._sketchCanvas.save(p.imageType, p.transparent, p.folder ? p.folder : '', p.filename, p.includeImage !== false, p.includeText !== false, p.cropToImageSize || false)
} else {
const date = new Date()
this._sketchCanvas.save('png', false, '',
this._sketchCanvas.save('png', false, '',
date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + ('0' + date.getDate()).slice(-2) + ' ' + ('0' + date.getHours()).slice(-2) + '-' + ('0' + date.getMinutes()).slice(-2) + '-' + ('0' + date.getSeconds()).slice(-2),
true, true, false)
}
Expand Down Expand Up @@ -282,4 +277,4 @@ RNSketchCanvas.CACHES = SketchCanvas.CACHES;

export {
SketchCanvas
}
}
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@terrylinla/react-native-sketch-canvas",
"name": "@sourcetoad/react-native-sketch-canvas",
"repository": {
"type": "git",
"url": "https://github.com/terrylinla/react-native-sketch-canvas"
"url": "https://github.com/sourcetoad/react-native-sketch-canvas"
},
"version": "0.8.0",
"version": "1.0.0",
"description": "react-native-sketch-canvas allows you to draw / sketch on both iOS and Android devices and sync the drawing data between users. Of course you can save as image.",
"author": "Terry Lin",
"main": "index.js",
Expand All @@ -19,5 +19,15 @@
"draw"
],
"nativePackage": true,
"license": "MIT"
}
"license": "MIT",
"peerDependencies": {
"react": "*",
"react-native": "*"
},
"dependencies": {
"@types/react": "^18.0.24",
"@types/react-native": "^0.70.6",
"deprecated-react-native-prop-types": "^2.3.0",
"prop-types": "^15.8.1"
}
}
2 changes: 1 addition & 1 deletion src/SketchCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import React from 'react'
import PropTypes from 'prop-types'
import { ViewPropTypes } from 'deprecated-react-native-prop-types'
import ReactNative, {
requireNativeComponent,
NativeModules,
UIManager,
PanResponder,
PixelRatio,
Platform,
ViewPropTypes,
processColor
} from 'react-native'
import { requestPermissions } from './handlePermissions';
Expand Down
7 changes: 3 additions & 4 deletions src/handlePermissions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PermissionsAndroid, Platform } from 'react-native';
import {PermissionsAndroid, Platform} from 'react-native';

export const requestPermissions = async (permissionDialogTitle, permissionDialogMessage) => {
if (Platform.OS === 'android') {
Expand All @@ -10,8 +10,7 @@ export const requestPermissions = async (permissionDialogTitle, permissionDialog
// On devices before SDK version 23, the permissions are automatically granted if they appear in the manifest,
// so check and request should always be true.
// https://github.com/facebook/react-native-website/blob/master/docs/permissionsandroid.md
const isAuthorized = Platform.Version >= 23 ? granted === PermissionsAndroid.RESULTS.GRANTED : granted === true;
return isAuthorized;
return Platform.Version >= 23 ? granted === PermissionsAndroid.RESULTS.GRANTED : granted === true;
}
return true;
}
}
Loading