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,152 @@
|
|
|
1
|
+
import { IPaintEditor } from './IPaintEditor';
|
|
2
|
+
import { PaintBoxContext } from './PaintBoxContext';
|
|
3
|
+
import { Commands, type PaintBoxRef } from './PaintBoxViewNativeComponent';
|
|
4
|
+
import { Color, MimeType, PaintMode } from './model';
|
|
5
|
+
import { ColorDTO } from './dto/ColorDTO';
|
|
6
|
+
import NativePaintBoxReactNative from './NativePaintBoxReactNative';
|
|
7
|
+
import { findNodeHandle } from 'react-native';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
|
|
10
|
+
export class PaintEditor implements IPaintEditor {
|
|
11
|
+
id: string | undefined;
|
|
12
|
+
|
|
13
|
+
_ref(): React.RefObject<PaintBoxRef> | null | undefined {
|
|
14
|
+
return PaintBoxContext.getInstance().getRef(this) as
|
|
15
|
+
| React.RefObject<PaintBoxRef>
|
|
16
|
+
| null
|
|
17
|
+
| undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
undo() {
|
|
21
|
+
const refObj = this._ref();
|
|
22
|
+
if (refObj?.current) {
|
|
23
|
+
Commands.undo(refObj.current);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
redo() {
|
|
28
|
+
const refObj = this._ref();
|
|
29
|
+
if (refObj?.current) {
|
|
30
|
+
Commands.redo(refObj.current);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
reset() {
|
|
35
|
+
const refObj = this._ref();
|
|
36
|
+
if (refObj?.current) {
|
|
37
|
+
Commands.reset(refObj.current);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
import(path: string, width?: number, height?: number) {
|
|
42
|
+
const refObj = this._ref();
|
|
43
|
+
if (refObj?.current) {
|
|
44
|
+
Commands.importImage(refObj?.current, path, width ?? -1, height ?? -1);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export(path: string, fileName: string, mimeType: MimeType): void {
|
|
49
|
+
const refObj = this._ref();
|
|
50
|
+
if (refObj?.current) {
|
|
51
|
+
const viewTag = findNodeHandle(refObj.current);
|
|
52
|
+
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
NativePaintBoxReactNative.export(viewTag, path, fileName, mimeType);
|
|
55
|
+
} else {
|
|
56
|
+
throw new Error(
|
|
57
|
+
'Reference not found! Please ensure that the paint box has been created.'
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
isEnable(): Promise<boolean> {
|
|
63
|
+
const refObj = this._ref();
|
|
64
|
+
if (refObj?.current) {
|
|
65
|
+
const viewTag = findNodeHandle(refObj.current);
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
return NativePaintBoxReactNative.isEnable(viewTag);
|
|
68
|
+
} else {
|
|
69
|
+
throw new Error(
|
|
70
|
+
'Reference not found! Please ensure that the paint box has been created.'
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
setEnable(value: boolean) {
|
|
76
|
+
const refObj = this._ref();
|
|
77
|
+
if (refObj?.current) {
|
|
78
|
+
Commands.setEnable(refObj?.current, value);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
setPaintMode(paintMode: PaintMode) {
|
|
83
|
+
const refObj = this._ref();
|
|
84
|
+
if (refObj?.current) {
|
|
85
|
+
Commands.setPaintMode(refObj?.current, paintMode);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async getPaintMode(): Promise<PaintMode> {
|
|
90
|
+
const refObj = this._ref();
|
|
91
|
+
if (refObj?.current) {
|
|
92
|
+
const viewTag = findNodeHandle(refObj.current);
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
const response = await NativePaintBoxReactNative.getPaintMode(viewTag);
|
|
95
|
+
const paintMode = Object.values(PaintMode).find((it) => it === response);
|
|
96
|
+
if (paintMode) {
|
|
97
|
+
return Promise.resolve(paintMode);
|
|
98
|
+
} else {
|
|
99
|
+
return Promise.reject(undefined);
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
throw new Error(
|
|
103
|
+
'Reference not found! Please ensure that the paint box has been created.'
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
setStrokeColor(strokeColor: Color) {
|
|
109
|
+
const refObj = this._ref();
|
|
110
|
+
console.log("heree:", JSON.stringify(ColorDTO.fromDataModel(strokeColor).toJSON()));
|
|
111
|
+
if (refObj?.current) {
|
|
112
|
+
Commands.setStrokeColor(
|
|
113
|
+
refObj?.current,
|
|
114
|
+
JSON.stringify(ColorDTO.fromDataModel(strokeColor).toJSON())
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async getStrokeColor(): Promise<Color> {
|
|
120
|
+
const refObj = this._ref();
|
|
121
|
+
if (refObj?.current) {
|
|
122
|
+
const viewTag = findNodeHandle(refObj.current);
|
|
123
|
+
// @ts-ignore
|
|
124
|
+
const response = await NativePaintBoxReactNative.getStrokeColor(viewTag);
|
|
125
|
+
return Promise.resolve(ColorDTO.fromJSON(response).toDataModel());
|
|
126
|
+
} else {
|
|
127
|
+
throw new Error(
|
|
128
|
+
'Reference not found! Please ensure that the paint box has been created.'
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
setStrokeSize(size: number) {
|
|
134
|
+
const refObj = this._ref();
|
|
135
|
+
if (refObj?.current) {
|
|
136
|
+
Commands.setStrokeSize(refObj?.current, size);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
getStrokeSize(): Promise<number> {
|
|
141
|
+
const refObj = this._ref();
|
|
142
|
+
if (refObj?.current) {
|
|
143
|
+
const viewTag = findNodeHandle(refObj.current);
|
|
144
|
+
// @ts-ignore
|
|
145
|
+
return NativePaintBoxReactNative.getStrokeSize(viewTag);
|
|
146
|
+
} else {
|
|
147
|
+
throw new Error(
|
|
148
|
+
'Reference not found! Please ensure that the paint box has been created.'
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BaseDTO } from './BaseDTO';
|
|
2
|
+
import { Color } from '../model';
|
|
3
|
+
|
|
4
|
+
export class ColorDTO extends BaseDTO {
|
|
5
|
+
red: number;
|
|
6
|
+
green: number;
|
|
7
|
+
blue: number;
|
|
8
|
+
alpha?: number = 255.0;
|
|
9
|
+
|
|
10
|
+
constructor(red: number, green: number, blue: number, alpha?: number) {
|
|
11
|
+
super();
|
|
12
|
+
this.red = red;
|
|
13
|
+
this.green = green;
|
|
14
|
+
this.blue = blue;
|
|
15
|
+
this.alpha = alpha;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static fromDataModel(color: Color) {
|
|
19
|
+
return new ColorDTO(color.red, color.green, color.blue, color.alpha);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static fromJSON(json: string) {
|
|
23
|
+
const parsedJson = JSON.parse(json);
|
|
24
|
+
return new ColorDTO(
|
|
25
|
+
parsedJson.red,
|
|
26
|
+
parsedJson.green,
|
|
27
|
+
parsedJson.blue,
|
|
28
|
+
parsedJson.alpha
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
toDataModel(): Color {
|
|
33
|
+
return new Color(this.red, this.green, this.blue, this.alpha);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
toJSON() {
|
|
37
|
+
return {
|
|
38
|
+
red: this.red,
|
|
39
|
+
green: this.green,
|
|
40
|
+
blue: this.blue,
|
|
41
|
+
alpha: this.alpha,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { PaintEditor } from './PaintEditor';
|
|
2
|
+
export { PaintBoxRNView } from './PaintBoxRNView';
|
|
3
|
+
//export { Commands } from './PaintBoxViewNativeComponent';
|
|
4
|
+
export { default as PaintBoxView } from './PaintBoxViewNativeComponent';
|
|
5
|
+
export { type PaintBoxRef } from './PaintBoxViewNativeComponent';
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class Color {
|
|
2
|
+
red: number;
|
|
3
|
+
green: number;
|
|
4
|
+
blue: number;
|
|
5
|
+
alpha?: number = 255.0;
|
|
6
|
+
|
|
7
|
+
constructor(red: number, green: number, blue: number, alpha?: number) {
|
|
8
|
+
this.red = red;
|
|
9
|
+
this.green = green;
|
|
10
|
+
this.blue = blue;
|
|
11
|
+
this.alpha = alpha ?? 255.0;
|
|
12
|
+
}
|
|
13
|
+
}
|