forked from JimmyDaddy/react-native-image-marker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
130 lines (121 loc) · 2.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* @Author: JimmyDaddy
* @Date: 2017-09-14 10:40:09
* @Last Modified by: JimmyDaddy
* @Last Modified time: 2018-04-08 17:46:14
* @Description
* @flow
*/
import { NativeModules } from 'react-native'
const { ImageMarker } = NativeModules
export type Position = $Enum<{
'topLeft': string,
'topCenter': string,
'topRight': string,
'bottomLeft': string,
'bottomCenter': string ,
'bottomRight': string,
'center': string
}>;
type TextMarkOption = {
// image src, local image
src: string,
text: string,
// if you set position you don't need to set X and Y
X?: number,
Y?: number,
// eg. '#aacc22'
color: string,
fontName: string,
fontSize: number,
// scale image
scale: number,
// image quality
quality: number,
position?: Position
}
type ImageMarkOption = {
// image src, local image
src: string,
markerSrc: string,
X?: number,
Y?: number,
// marker scale
markerScale: number,
// image scale
scale: number,
quality: number,
position?: Position
}
export default class Marker {
static markText(option: TextMarkOption) {
const {
src,
text,
X,
Y,
color,
fontName,
fontSize,
scale,
quality,
position
} = option
if (!position) {
return ImageMarker.addText(
src,
text,
X,
Y,
color,
fontName,
fontSize,
scale,
quality
)
} else {
return ImageMarker.addTextByPostion(
src,
text,
position,
color,
fontName,
fontSize,
scale,
quality
)
}
}
static markImage(option: ImageMarkOption) {
const {
src,
markerSrc,
X,
Y,
markerScale,
scale,
quality,
position
} = option
if (!position) {
return ImageMarker.markWithImage(
src,
markerSrc,
X,
Y,
scale,
markerScale,
quality
)
} else {
return ImageMarker.markWithImageByPosition(
src,
markerSrc,
position,
scale,
markerScale,
quality
)
}
}
}