paint_box_react_native 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/PaintBoxReactNative.podspec +20 -0
- package/README.md +161 -0
- package/android/build.gradle +70 -0
- package/android/gradle.properties +45 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/paintboxreactnative/NativeViewHandler.kt +26 -0
- package/android/src/main/java/com/paintboxreactnative/PaintBoxNativeView.kt +61 -0
- package/android/src/main/java/com/paintboxreactnative/PaintBoxNativeViewManager.kt +105 -0
- package/android/src/main/java/com/paintboxreactnative/PaintBoxReactNativeModule.kt +74 -0
- package/android/src/main/java/com/paintboxreactnative/PaintBoxReactNativePackage.kt +41 -0
- package/android/src/main/java/com/paintboxreactnative/dto/ColorDTO.kt +37 -0
- package/ios/PaintBoxReactNative.h +5 -0
- package/ios/PaintBoxReactNative.mm +21 -0
- package/lib/module/IPaintEditor.js +7 -0
- package/lib/module/IPaintEditor.js.map +1 -0
- package/lib/module/NativePaintBoxReactNative.js +5 -0
- package/lib/module/NativePaintBoxReactNative.js.map +1 -0
- package/lib/module/PaintBoxContext.js +50 -0
- package/lib/module/PaintBoxContext.js.map +1 -0
- package/lib/module/PaintBoxRNView.js +90 -0
- package/lib/module/PaintBoxRNView.js.map +1 -0
- package/lib/module/PaintBoxViewNativeComponent.ts +63 -0
- package/lib/module/PaintEditor.js +121 -0
- package/lib/module/PaintEditor.js.map +1 -0
- package/lib/module/dto/BaseDTO.js +8 -0
- package/lib/module/dto/BaseDTO.js.map +1 -0
- package/lib/module/dto/ColorDTO.js +33 -0
- package/lib/module/dto/ColorDTO.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +2 -0
- package/lib/module/model/Color.js +12 -0
- package/lib/module/model/Color.js.map +1 -0
- package/lib/module/model/MimeType.js +12 -0
- package/lib/module/model/MimeType.js.map +1 -0
- package/lib/module/model/PaintMode.js +11 -0
- package/lib/module/model/PaintMode.js.map +1 -0
- package/lib/module/model/index.js +6 -0
- package/lib/module/model/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/IPaintEditor.d.ts +18 -0
- package/lib/typescript/src/IPaintEditor.d.ts.map +1 -0
- package/lib/typescript/src/NativePaintBoxReactNative.d.ts +11 -0
- package/lib/typescript/src/NativePaintBoxReactNative.d.ts.map +1 -0
- package/lib/typescript/src/PaintBoxContext.d.ts +18 -0
- package/lib/typescript/src/PaintBoxContext.d.ts.map +1 -0
- package/lib/typescript/src/PaintBoxRNView.d.ts +11 -0
- package/lib/typescript/src/PaintBoxRNView.d.ts.map +1 -0
- package/lib/typescript/src/PaintBoxViewNativeComponent.d.ts +24 -0
- package/lib/typescript/src/PaintBoxViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/PaintEditor.d.ts +22 -0
- package/lib/typescript/src/PaintEditor.d.ts.map +1 -0
- package/lib/typescript/src/dto/BaseDTO.d.ts +5 -0
- package/lib/typescript/src/dto/BaseDTO.d.ts.map +1 -0
- package/lib/typescript/src/dto/ColorDTO.d.ts +19 -0
- package/lib/typescript/src/dto/ColorDTO.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +5 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/model/Color.d.ts +8 -0
- package/lib/typescript/src/model/Color.d.ts.map +1 -0
- package/lib/typescript/src/model/MimeType.d.ts +9 -0
- package/lib/typescript/src/model/MimeType.d.ts.map +1 -0
- package/lib/typescript/src/model/PaintMode.d.ts +8 -0
- package/lib/typescript/src/model/PaintMode.d.ts.map +1 -0
- package/lib/typescript/src/model/index.d.ts +4 -0
- package/lib/typescript/src/model/index.d.ts.map +1 -0
- package/package.json +175 -0
- package/src/IPaintEditor.ts +32 -0
- package/src/NativePaintBoxReactNative.ts +20 -0
- package/src/PaintBoxContext.ts +67 -0
- package/src/PaintBoxRNView.tsx +98 -0
- package/src/PaintBoxViewNativeComponent.ts +63 -0
- package/src/PaintEditor.ts +152 -0
- package/src/dto/BaseDTO.ts +7 -0
- package/src/dto/ColorDTO.ts +44 -0
- package/src/index.ts +5 -0
- package/src/index.tsx +3 -0
- package/src/model/Color.ts +13 -0
- package/src/model/MimeType.ts +8 -0
- package/src/model/PaintMode.ts +7 -0
- package/src/model/index.ts +3 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PaintEditor.d.ts","sourceRoot":"","sources":["../../../src/PaintEditor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAY,KAAK,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAIrD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,qBAAa,WAAY,YAAW,YAAY;IAC9C,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC;IAEvB,IAAI,IAAI,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,IAAI,GAAG,SAAS;IAOvD,IAAI;IAOJ,IAAI;IAOJ,KAAK;IAOL,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAOpD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAchE,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAa5B,SAAS,CAAC,KAAK,EAAE,OAAO;IAOxB,YAAY,CAAC,SAAS,EAAE,SAAS;IAO3B,YAAY,IAAI,OAAO,CAAC,SAAS,CAAC;IAmBxC,cAAc,CAAC,WAAW,EAAE,KAAK;IAW3B,cAAc,IAAI,OAAO,CAAC,KAAK,CAAC;IActC,aAAa,CAAC,IAAI,EAAE,MAAM;IAO1B,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;CAYjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseDTO.d.ts","sourceRoot":"","sources":["../../../../src/dto/BaseDTO.ts"],"names":[],"mappings":"AAAA,8BAAsB,OAAO;IAC3B,QAAQ,CAAC,MAAM,IAAI,IAAI;IAEvB,YAAY;CAGb"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseDTO } from './BaseDTO';
|
|
2
|
+
import { Color } from '../model';
|
|
3
|
+
export declare class ColorDTO extends BaseDTO {
|
|
4
|
+
red: number;
|
|
5
|
+
green: number;
|
|
6
|
+
blue: number;
|
|
7
|
+
alpha?: number;
|
|
8
|
+
constructor(red: number, green: number, blue: number, alpha?: number);
|
|
9
|
+
static fromDataModel(color: Color): ColorDTO;
|
|
10
|
+
static fromJSON(json: string): ColorDTO;
|
|
11
|
+
toDataModel(): Color;
|
|
12
|
+
toJSON(): {
|
|
13
|
+
red: number;
|
|
14
|
+
green: number;
|
|
15
|
+
blue: number;
|
|
16
|
+
alpha: number | undefined;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=ColorDTO.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColorDTO.d.ts","sourceRoot":"","sources":["../../../../src/dto/ColorDTO.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,qBAAa,QAAS,SAAQ,OAAO;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAS;gBAEX,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;IAQpE,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK;IAIjC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM;IAU5B,WAAW,IAAI,KAAK;IAIpB,MAAM;;;;;;CAQP"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { PaintEditor } from './PaintEditor';
|
|
2
|
+
export { PaintBoxRNView } from './PaintBoxRNView';
|
|
3
|
+
export { default as PaintBoxView } from './PaintBoxViewNativeComponent';
|
|
4
|
+
export { type PaintBoxRef } from './PaintBoxViewNativeComponent';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,+BAA+B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Color.d.ts","sourceRoot":"","sources":["../../../../src/model/Color.ts"],"names":[],"mappings":"AAAA,qBAAa,KAAK;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAS;gBAEX,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAMrE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MimeType.d.ts","sourceRoot":"","sources":["../../../../src/model/MimeType.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IAClB,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PaintMode.d.ts","sourceRoot":"","sources":["../../../../src/model/PaintMode.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACnB,GAAG,QAAQ;IACX,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,MAAM,WAAW;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/model/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "paint_box_react_native",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "--",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.ts",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"*.podspec",
|
|
22
|
+
"react-native.config.js",
|
|
23
|
+
"!ios/build",
|
|
24
|
+
"!android/build",
|
|
25
|
+
"!android/gradle",
|
|
26
|
+
"!android/gradlew",
|
|
27
|
+
"!android/gradlew.bat",
|
|
28
|
+
"!android/local.properties",
|
|
29
|
+
"!**/__tests__",
|
|
30
|
+
"!**/__fixtures__",
|
|
31
|
+
"!**/__mocks__",
|
|
32
|
+
"!**/.*"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"example": "yarn workspace paint_box_react_native-example",
|
|
36
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
37
|
+
"prepare": "bob build",
|
|
38
|
+
"typecheck": "tsc",
|
|
39
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
40
|
+
"test": "jest",
|
|
41
|
+
"release": "release-it --only-version"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"react-native",
|
|
45
|
+
"ios",
|
|
46
|
+
"android"
|
|
47
|
+
],
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/sinemavci/paint_box_react_native.git"
|
|
51
|
+
},
|
|
52
|
+
"author": "sinem.avci <sinemaavci@gmail.com> (https://github.com/sinemavci)",
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/sinemavci/paint_box_react_native/issues"
|
|
56
|
+
},
|
|
57
|
+
"homepage": "https://github.com/sinemavci/paint_box_react_native#readme",
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"registry": "https://registry.npmjs.org/"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
63
|
+
"@eslint/compat": "^1.3.2",
|
|
64
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
65
|
+
"@eslint/js": "^9.35.0",
|
|
66
|
+
"@react-native-community/cli": "latest",
|
|
67
|
+
"@react-native/babel-preset": "0.83.0",
|
|
68
|
+
"@react-native/eslint-config": "0.83.0",
|
|
69
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
70
|
+
"@types/jest": "^29.5.14",
|
|
71
|
+
"@types/react": "^19.2.0",
|
|
72
|
+
"@types/react-native-vector-icons": "^6.4.18",
|
|
73
|
+
"commitlint": "^19.8.1",
|
|
74
|
+
"del-cli": "^6.0.0",
|
|
75
|
+
"eslint": "^9.35.0",
|
|
76
|
+
"eslint-config-prettier": "^10.1.8",
|
|
77
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
78
|
+
"jest": "^29.7.0",
|
|
79
|
+
"lefthook": "^2.0.3",
|
|
80
|
+
"prettier": "^2.8.8",
|
|
81
|
+
"react": "19.2.0",
|
|
82
|
+
"react-native": "0.83.0",
|
|
83
|
+
"react-native-builder-bob": "^0.40.13",
|
|
84
|
+
"release-it": "^19.0.4",
|
|
85
|
+
"turbo": "^2.5.6",
|
|
86
|
+
"typescript": "^5.9.2"
|
|
87
|
+
},
|
|
88
|
+
"peerDependencies": {
|
|
89
|
+
"react": "*",
|
|
90
|
+
"react-native": "*"
|
|
91
|
+
},
|
|
92
|
+
"workspaces": [
|
|
93
|
+
"example"
|
|
94
|
+
],
|
|
95
|
+
"packageManager": "yarn@4.11.0",
|
|
96
|
+
"react-native-builder-bob": {
|
|
97
|
+
"source": "src",
|
|
98
|
+
"output": "lib",
|
|
99
|
+
"targets": [
|
|
100
|
+
[
|
|
101
|
+
"module",
|
|
102
|
+
{
|
|
103
|
+
"esm": true
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
[
|
|
107
|
+
"typescript",
|
|
108
|
+
{
|
|
109
|
+
"project": "tsconfig.build.json"
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
"codegenConfig": {
|
|
115
|
+
"name": "PaintBoxReactNativeSpec",
|
|
116
|
+
"type": "all",
|
|
117
|
+
"jsSrcsDir": "src",
|
|
118
|
+
"android": {
|
|
119
|
+
"javaPackageName": "com.paintboxreactnative"
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"prettier": {
|
|
123
|
+
"quoteProps": "consistent",
|
|
124
|
+
"singleQuote": true,
|
|
125
|
+
"tabWidth": 2,
|
|
126
|
+
"trailingComma": "es5",
|
|
127
|
+
"useTabs": false
|
|
128
|
+
},
|
|
129
|
+
"jest": {
|
|
130
|
+
"preset": "react-native",
|
|
131
|
+
"modulePathIgnorePatterns": [
|
|
132
|
+
"<rootDir>/example/node_modules",
|
|
133
|
+
"<rootDir>/lib/"
|
|
134
|
+
]
|
|
135
|
+
},
|
|
136
|
+
"commitlint": {
|
|
137
|
+
"extends": [
|
|
138
|
+
"@commitlint/config-conventional"
|
|
139
|
+
]
|
|
140
|
+
},
|
|
141
|
+
"release-it": {
|
|
142
|
+
"git": {
|
|
143
|
+
"commitMessage": "chore: release ${version}",
|
|
144
|
+
"tagName": "v${version}"
|
|
145
|
+
},
|
|
146
|
+
"npm": {
|
|
147
|
+
"publish": true
|
|
148
|
+
},
|
|
149
|
+
"github": {
|
|
150
|
+
"release": true
|
|
151
|
+
},
|
|
152
|
+
"plugins": {
|
|
153
|
+
"@release-it/conventional-changelog": {
|
|
154
|
+
"preset": {
|
|
155
|
+
"name": "angular"
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
"create-react-native-library": {
|
|
161
|
+
"type": "turbo-module",
|
|
162
|
+
"languages": "kotlin-objc",
|
|
163
|
+
"tools": [
|
|
164
|
+
"eslint",
|
|
165
|
+
"jest",
|
|
166
|
+
"lefthook",
|
|
167
|
+
"release-it"
|
|
168
|
+
],
|
|
169
|
+
"version": "0.57.0"
|
|
170
|
+
},
|
|
171
|
+
"dependencies": {
|
|
172
|
+
"react-native-uuid": "^2.0.3",
|
|
173
|
+
"react-native-vector-icons": "^10.3.0"
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Color, PaintMode } from './model';
|
|
2
|
+
import uuid from 'react-native-uuid';
|
|
3
|
+
|
|
4
|
+
export abstract class IPaintEditor {
|
|
5
|
+
id: string | undefined = uuid.v4();
|
|
6
|
+
|
|
7
|
+
abstract undo(): void;
|
|
8
|
+
|
|
9
|
+
abstract redo(): void;
|
|
10
|
+
|
|
11
|
+
abstract reset(): void;
|
|
12
|
+
|
|
13
|
+
abstract import(path: string, width?: number, height?: number): void;
|
|
14
|
+
|
|
15
|
+
abstract export(path: string, fileName: string, mimeType: string): void;
|
|
16
|
+
|
|
17
|
+
abstract isEnable(): Promise<boolean>;
|
|
18
|
+
|
|
19
|
+
abstract setEnable(value: boolean): void;
|
|
20
|
+
|
|
21
|
+
abstract setPaintMode(paintMode: PaintMode): void;
|
|
22
|
+
|
|
23
|
+
abstract getPaintMode(): Promise<PaintMode>;
|
|
24
|
+
|
|
25
|
+
abstract setStrokeColor(strokeColor: Color): void;
|
|
26
|
+
|
|
27
|
+
abstract getStrokeColor(): Promise<Color>;
|
|
28
|
+
|
|
29
|
+
abstract setStrokeSize(size: number): void;
|
|
30
|
+
|
|
31
|
+
abstract getStrokeSize(): Promise<number>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TurboModuleRegistry, type TurboModule } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export interface Spec extends TurboModule {
|
|
4
|
+
isEnable(viewTag: number | null): Promise<boolean>;
|
|
5
|
+
|
|
6
|
+
getPaintMode(viewTag: number | null): Promise<string>;
|
|
7
|
+
|
|
8
|
+
getStrokeColor(viewTag: number | null): Promise<string>;
|
|
9
|
+
|
|
10
|
+
getStrokeSize(viewTag: number | null): Promise<number>;
|
|
11
|
+
|
|
12
|
+
export: (
|
|
13
|
+
viewTag: number | null,
|
|
14
|
+
path: string,
|
|
15
|
+
fileName: string,
|
|
16
|
+
mimeType: string,
|
|
17
|
+
) => Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('PaintBoxReactNative');
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { IPaintEditor } from './IPaintEditor';
|
|
2
|
+
import type { PaintEditor } from './PaintEditor';
|
|
3
|
+
|
|
4
|
+
export type PaintBoxContextModel = {
|
|
5
|
+
ref?: React.RefObject<any> | null;
|
|
6
|
+
controller?: IPaintEditor;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export class PaintBoxContext {
|
|
10
|
+
private static instance: PaintBoxContext;
|
|
11
|
+
listOfRef: Array<PaintBoxContextModel> = [];
|
|
12
|
+
|
|
13
|
+
private constructor() {}
|
|
14
|
+
|
|
15
|
+
public static getInstance(): PaintBoxContext {
|
|
16
|
+
if (!PaintBoxContext.instance) {
|
|
17
|
+
PaintBoxContext.instance = new PaintBoxContext();
|
|
18
|
+
}
|
|
19
|
+
return PaintBoxContext.instance;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getRef(controller?: PaintEditor) {
|
|
23
|
+
if (this.listOfRef.length > 1) {
|
|
24
|
+
if (controller) {
|
|
25
|
+
return this.foundedRef(controller);
|
|
26
|
+
} else {
|
|
27
|
+
throw new Error('Ref model must be required!');
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
if (controller) {
|
|
31
|
+
return this.foundedRef(controller);
|
|
32
|
+
} else {
|
|
33
|
+
return this.listOfRef[0]?.ref;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
addRef(ref?: PaintBoxContextModel) {
|
|
39
|
+
if (ref) {
|
|
40
|
+
this.listOfRef.push(ref);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async clearRefs() {
|
|
45
|
+
this.listOfRef = [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
clearRef(ref: IPaintEditor) {
|
|
49
|
+
const foundedRef = this.foundedRef(ref);
|
|
50
|
+
if (!foundedRef) {
|
|
51
|
+
this.listOfRef = this.listOfRef.filter(
|
|
52
|
+
(model) => ref.id === model.controller?.id
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private foundedRef(refModel: IPaintEditor) {
|
|
58
|
+
const foundedRef = this.listOfRef.find(
|
|
59
|
+
(value) => value?.controller === refModel
|
|
60
|
+
)?.ref;
|
|
61
|
+
if (foundedRef) {
|
|
62
|
+
return foundedRef;
|
|
63
|
+
} else {
|
|
64
|
+
throw new Error('No map found with this id or ref!');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import PaintBoxView from './PaintBoxViewNativeComponent';
|
|
2
|
+
import { StatusBar, StyleSheet, View, type ViewProps } from 'react-native';
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { PaintBoxContext } from './PaintBoxContext';
|
|
5
|
+
import type { IPaintEditor } from './IPaintEditor';
|
|
6
|
+
|
|
7
|
+
export type PaintBoxViewProps = {
|
|
8
|
+
paintEditor: IPaintEditor;
|
|
9
|
+
style?: ViewProps;
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
onPaintBoxReady?: () => void;
|
|
12
|
+
childrenPosition?: 'topRight' | 'topLeft' | 'bottomRight' | 'bottomLeft';
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const PaintBoxRNView: React.FC<PaintBoxViewProps> = ({
|
|
16
|
+
children,
|
|
17
|
+
style,
|
|
18
|
+
childrenPosition,
|
|
19
|
+
paintEditor,
|
|
20
|
+
onPaintBoxReady,
|
|
21
|
+
}: PaintBoxViewProps) => {
|
|
22
|
+
const ref = useRef<React.ElementRef<typeof PaintBoxView>>(null);
|
|
23
|
+
const statusBarHeight = StatusBar.currentHeight;
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
PaintBoxContext.getInstance().addRef({
|
|
27
|
+
ref: ref,
|
|
28
|
+
controller: paintEditor,
|
|
29
|
+
});
|
|
30
|
+
return () => {
|
|
31
|
+
PaintBoxContext.getInstance().clearRef(paintEditor);
|
|
32
|
+
};
|
|
33
|
+
}, [paintEditor]);
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<View style={[styles.root, style]}>
|
|
37
|
+
<View
|
|
38
|
+
style={
|
|
39
|
+
childrenPosition === 'topLeft'
|
|
40
|
+
? // eslint-disable-next-line react-native/no-inline-styles
|
|
41
|
+
{
|
|
42
|
+
position: 'absolute',
|
|
43
|
+
zIndex: 1,
|
|
44
|
+
top: statusBarHeight,
|
|
45
|
+
left: 12,
|
|
46
|
+
}
|
|
47
|
+
: childrenPosition === 'topRight'
|
|
48
|
+
? // eslint-disable-next-line react-native/no-inline-styles
|
|
49
|
+
{
|
|
50
|
+
position: 'absolute',
|
|
51
|
+
zIndex: 1,
|
|
52
|
+
top: statusBarHeight,
|
|
53
|
+
right: 12,
|
|
54
|
+
}
|
|
55
|
+
: childrenPosition === 'bottomLeft'
|
|
56
|
+
? styles.childrenBottomLeft
|
|
57
|
+
: styles.childrenBottomRight
|
|
58
|
+
}
|
|
59
|
+
>
|
|
60
|
+
{children}
|
|
61
|
+
</View>
|
|
62
|
+
{/* eslint-disable-next-line react-native/no-inline-styles */}
|
|
63
|
+
<PaintBoxView ref={ref} style={{ flex: 1 }} onPaintBoxReady={(result) => {
|
|
64
|
+
if (result.nativeEvent.result === true) {
|
|
65
|
+
onPaintBoxReady?.();
|
|
66
|
+
}
|
|
67
|
+
}} />
|
|
68
|
+
</View>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const styles = StyleSheet.create({
|
|
73
|
+
root: {
|
|
74
|
+
position: 'relative',
|
|
75
|
+
flex: 1,
|
|
76
|
+
height: 'auto',
|
|
77
|
+
},
|
|
78
|
+
childrenTopLeft: { position: 'absolute', zIndex: 1, top: 12, left: 12 },
|
|
79
|
+
childrenTopRight: {
|
|
80
|
+
position: 'absolute',
|
|
81
|
+
zIndex: 1,
|
|
82
|
+
right: 6,
|
|
83
|
+
},
|
|
84
|
+
childrenBottomRight: {
|
|
85
|
+
position: 'absolute',
|
|
86
|
+
zIndex: 1,
|
|
87
|
+
right: 6,
|
|
88
|
+
},
|
|
89
|
+
childrenBottomLeft: {
|
|
90
|
+
position: 'absolute',
|
|
91
|
+
zIndex: 1,
|
|
92
|
+
left: 6,
|
|
93
|
+
},
|
|
94
|
+
matchParent: {
|
|
95
|
+
width: '100%',
|
|
96
|
+
height: '100%',
|
|
97
|
+
},
|
|
98
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ViewProps,
|
|
3
|
+
codegenNativeCommands,
|
|
4
|
+
type HostComponent,
|
|
5
|
+
} from 'react-native';
|
|
6
|
+
import { codegenNativeComponent } from 'react-native';
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import type { DirectEventHandler, Double, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
9
|
+
|
|
10
|
+
type PaintBoxReadyEvent = {
|
|
11
|
+
result : boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface NativeProps extends ViewProps {
|
|
15
|
+
onPaintBoxReady?: DirectEventHandler<PaintBoxReadyEvent>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type PaintBoxHostComponent = HostComponent<NativeProps>;
|
|
19
|
+
|
|
20
|
+
export type PaintBoxRef = React.ElementRef<PaintBoxHostComponent>;
|
|
21
|
+
|
|
22
|
+
interface NativeCommands {
|
|
23
|
+
undo: (viewRef: React.ElementRef<PaintBoxHostComponent>) => void;
|
|
24
|
+
redo: (viewRef: React.ElementRef<PaintBoxHostComponent>) => void;
|
|
25
|
+
reset: (viewRef: React.ElementRef<PaintBoxHostComponent>) => void;
|
|
26
|
+
importImage: (
|
|
27
|
+
viewRef: React.ElementRef<PaintBoxHostComponent>,
|
|
28
|
+
path: string,
|
|
29
|
+
width: Double,
|
|
30
|
+
height: Double
|
|
31
|
+
) => void;
|
|
32
|
+
setEnable: (
|
|
33
|
+
viewRef: React.ElementRef<PaintBoxHostComponent>,
|
|
34
|
+
enable: boolean
|
|
35
|
+
) => void;
|
|
36
|
+
setPaintMode: (
|
|
37
|
+
viewRef: React.ElementRef<PaintBoxHostComponent>,
|
|
38
|
+
paintMode: string
|
|
39
|
+
) => void;
|
|
40
|
+
setStrokeColor: (
|
|
41
|
+
viewRef: React.ElementRef<PaintBoxHostComponent>,
|
|
42
|
+
color: string
|
|
43
|
+
) => void;
|
|
44
|
+
setStrokeSize: (
|
|
45
|
+
viewRef: React.ElementRef<PaintBoxHostComponent>,
|
|
46
|
+
size: Double
|
|
47
|
+
) => void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const Commands = codegenNativeCommands<NativeCommands>({
|
|
51
|
+
supportedCommands: [
|
|
52
|
+
'undo',
|
|
53
|
+
'redo',
|
|
54
|
+
'reset',
|
|
55
|
+
'importImage',
|
|
56
|
+
'setEnable',
|
|
57
|
+
'setPaintMode',
|
|
58
|
+
'setStrokeColor',
|
|
59
|
+
'setStrokeSize',
|
|
60
|
+
],
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export default codegenNativeComponent<NativeProps>('PaintBoxView');
|