rn-pdf-king 1.2.0 → 1.3.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.
@@ -15,180 +15,188 @@ import kotlinx.coroutines.launch
15
15
  import kotlinx.coroutines.withContext
16
16
 
17
17
  class RnPdfKingModule : Module() {
18
- private val FILE_PICKER_REQUEST_CODE = 4242
19
-
20
- override fun definition() = ModuleDefinition {
21
- Name("RnPdfKing")
22
-
23
- // Events
24
- Events("onPdfLoadStarted", "onPdfLoadSuccess", "onPdfLoadError")
25
-
26
- OnCreate {
27
- val context = appContext.reactContext
28
- if (context != null) {
29
- PdfKingManager.initialize(context)
30
- val pdfKing = PdfKingManager.getInstance()
31
- pdfKing.onFileLoadStarted = {
32
- this@RnPdfKingModule.sendEvent("onPdfLoadStarted", mapOf())
33
- }
34
- pdfKing.onFileLoadSuccess = { filePath, fileName, pageCount ->
35
- this@RnPdfKingModule.sendEvent("onPdfLoadSuccess", mapOf(
36
- "filePath" to filePath,
37
- "fileName" to fileName,
38
- "pageCount" to pageCount
39
- ))
40
- }
41
- pdfKing.onUnsupportedFile = {
42
- this@RnPdfKingModule.sendEvent("onPdfLoadError", mapOf("message" to "Unsupported or corrupt PDF file"))
43
- }
44
- }
45
-
46
- // Check for initial intent
47
- appContext.currentActivity?.intent?.let { intent ->
48
- if (intent.action == Intent.ACTION_VIEW) {
49
- val uri = intent.data
50
- if (uri != null) {
51
- CoroutineScope(Dispatchers.Main).launch {
52
- PdfKingManager.getInstance().handleUriSelection(uri)
53
- }
54
- }
55
- }
56
- }
57
- }
18
+ private val FILE_PICKER_REQUEST_CODE = 4242
19
+
20
+ override fun definition() = ModuleDefinition {
21
+ Name("RnPdfKing")
22
+
23
+ // Events
24
+ Events("onPdfLoadStarted", "onPdfLoadSuccess", "onPdfLoadError")
25
+
26
+ OnCreate {
27
+ val context = appContext.reactContext
28
+ if (context != null) {
29
+ PdfKingManager.initialize(context)
30
+ val pdfKing = PdfKingManager.getInstance()
31
+ pdfKing.onFileLoadStarted = {
32
+ this@RnPdfKingModule.sendEvent("onPdfLoadStarted", mapOf())
33
+ }
34
+ pdfKing.onFileLoadSuccess = { filePath, fileName, pageCount ->
35
+ this@RnPdfKingModule.sendEvent(
36
+ "onPdfLoadSuccess", mapOf(
37
+ "filePath" to filePath,
38
+ "fileName" to fileName,
39
+ "pageCount" to pageCount
40
+ )
41
+ )
42
+ }
43
+ pdfKing.onUnsupportedFile = {
44
+ this@RnPdfKingModule.sendEvent(
45
+ "onPdfLoadError",
46
+ mapOf("message" to "Unsupported or corrupt PDF file")
47
+ )
48
+ }
49
+ }
58
50
 
59
- OnNewIntent { intent ->
60
- if (intent.action == Intent.ACTION_VIEW) {
61
- val uri = intent.data
62
- if (uri != null) {
63
- CoroutineScope(Dispatchers.Main).launch {
64
- PdfKingManager.getInstance().handleUriSelection(uri)
51
+ // Check for initial intent
52
+ appContext.currentActivity?.intent?.let { intent ->
53
+ if (intent.action == Intent.ACTION_VIEW) {
54
+ val uri = intent.data
55
+ if (uri != null) {
56
+ CoroutineScope(Dispatchers.Main).launch {
57
+ PdfKingManager.getInstance().handleUriSelection(uri)
58
+ }
59
+ }
65
60
  }
66
61
  }
67
62
  }
68
- }
69
-
70
- AsyncFunction("checkInitialIntent") {
71
- appContext.currentActivity?.intent?.let { intent ->
63
+
64
+ OnNewIntent { intent ->
72
65
  if (intent.action == Intent.ACTION_VIEW) {
73
66
  val uri = intent.data
74
67
  if (uri != null) {
75
68
  CoroutineScope(Dispatchers.Main).launch {
76
69
  PdfKingManager.getInstance().handleUriSelection(uri)
77
70
  }
78
- return@AsyncFunction true
79
71
  }
80
72
  }
81
73
  }
82
- return@AsyncFunction false
83
- }
84
74
 
85
- OnActivityResult { _, payload ->
86
- if (payload.requestCode == FILE_PICKER_REQUEST_CODE && payload.resultCode == Activity.RESULT_OK) {
87
- val uri = payload.data?.data
88
- if (uri != null) {
89
- CoroutineScope(Dispatchers.Main).launch {
90
- PdfKingManager.getInstance().handleUriSelection(uri)
75
+ AsyncFunction("checkInitialIntent") {
76
+ appContext.currentActivity?.intent?.let { intent ->
77
+ if (intent.action == Intent.ACTION_VIEW) {
78
+ val uri = intent.data
79
+ if (uri != null) {
80
+ CoroutineScope(Dispatchers.Main).launch {
81
+ PdfKingManager.getInstance().handleUriSelection(uri)
82
+ }
83
+ return@AsyncFunction true
84
+ }
91
85
  }
92
86
  }
87
+ return@AsyncFunction false
93
88
  }
94
- }
95
89
 
96
- AsyncFunction("pickFile") {
97
- val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
98
- type = "application/pdf"
99
- addCategory(Intent.CATEGORY_OPENABLE)
100
- }
101
- appContext.currentActivity?.startActivityForResult(intent, FILE_PICKER_REQUEST_CODE)
102
- }
103
-
104
- AsyncFunction("loadPdf") { path: String ->
105
- val file = File(path)
106
- if (file.exists()) {
107
- CoroutineScope(Dispatchers.IO).launch {
108
- try {
109
- val pdfKing = PdfKingManager.getInstance()
110
- withContext(Dispatchers.Main) {
111
- pdfKing.onFileLoadStarted?.invoke()
112
- }
113
- pdfKing.loadPdf(file)
114
- val count = pdfKing.getPageCountSync()
115
-
116
- withContext(Dispatchers.Main) {
117
- pdfKing.onFileLoadSuccess?.invoke(path, file.name, count)
118
- }
119
- } catch (e: Exception) {
120
- this@RnPdfKingModule.sendEvent("onPdfLoadError", mapOf("message" to (e.message ?: "Unknown error")))
121
- }
122
- }
123
- } else {
124
- this@RnPdfKingModule.sendEvent("onPdfLoadError", mapOf("message" to "File does not exist"))
90
+ OnActivityResult { _, payload ->
91
+ if (payload.requestCode == FILE_PICKER_REQUEST_CODE && payload.resultCode == Activity.RESULT_OK) {
92
+ val uri = payload.data?.data
93
+ if (uri != null) {
94
+ CoroutineScope(Dispatchers.Main).launch {
95
+ PdfKingManager.getInstance().handleUriSelection(uri)
96
+ }
97
+ }
98
+ }
125
99
  }
126
- }
127
100
 
128
- AsyncFunction("getPageBitmapBase64") { pageNo: Int, promise: Promise ->
129
- CoroutineScope(Dispatchers.IO).launch {
130
- try {
131
- val result = PdfKingManager.getInstance().getPageBitmapBase64(pageNo)
132
- promise.resolve(result)
133
- } catch (e: Exception) {
134
- promise.reject("ERR_BITMAP", e.message, e)
101
+ AsyncFunction("pickFile") {
102
+ val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
103
+ type = "application/pdf"
104
+ addCategory(Intent.CATEGORY_OPENABLE)
135
105
  }
106
+ appContext.currentActivity?.startActivityForResult(intent, FILE_PICKER_REQUEST_CODE)
136
107
  }
137
- }
138
108
 
139
- AsyncFunction("getTextChars") { pageNo: Int, promise: Promise ->
140
- CoroutineScope(Dispatchers.IO).launch {
141
- try {
142
- val result = PdfKingManager.getInstance().getPageText(pageNo)
143
- promise.resolve(result)
144
- } catch (e: Exception) {
145
- promise.reject("ERR_TEXT", e.message, e)
109
+ AsyncFunction("loadPdf") { path: String ->
110
+ val file = File(path)
111
+ if (file.exists()) {
112
+ CoroutineScope(Dispatchers.IO).launch {
113
+ try {
114
+ val pdfKing = PdfKingManager.getInstance()
115
+ withContext(Dispatchers.Main) {
116
+ pdfKing.onFileLoadStarted?.invoke()
117
+ }
118
+ pdfKing.loadPdf(file)
119
+ val count = pdfKing.getPageCountSync()
120
+
121
+ withContext(Dispatchers.Main) {
122
+ pdfKing.onFileLoadSuccess?.invoke(path, file.name, count)
123
+ }
124
+ } catch (e: Exception) {
125
+ this@RnPdfKingModule.sendEvent(
126
+ "onPdfLoadError",
127
+ mapOf("message" to (e.message ?: "Unknown error"))
128
+ )
129
+ }
130
+ }
131
+ } else {
132
+ this@RnPdfKingModule.sendEvent("onPdfLoadError", mapOf("message" to "File does not exist"))
146
133
  }
147
134
  }
148
- }
149
135
 
150
- View(RnPdfKingView::class) {
151
- Prop("pageNo") { view: RnPdfKingView, pageNo: Int ->
152
- view.setPage(pageNo)
153
- }
154
-
155
- Prop("mode") { view: RnPdfKingView, mode: String ->
156
- view.setMode(mode)
157
- }
158
-
159
- Prop("pdfWidth") { view: RnPdfKingView, width: Int ->
160
- view.setPdfWidth(width)
161
- }
162
-
163
- Prop("pdfHeight") { view: RnPdfKingView, height: Int ->
164
- view.setPdfHeight(height)
165
- }
166
-
167
- Prop("preDefinedHighlights") { view: RnPdfKingView, highlights: List<Map<String, Any>> ->
168
- view.setHighlights(highlights)
169
- }
170
-
171
- Prop("preDefinedDottedHighlights") { view: RnPdfKingView, highlights: List<Map<String, Any>> ->
172
- view.setDottedHighlights(highlights)
173
- }
174
-
175
- AsyncFunction("clearSelection") { view: expo.modules.kotlin.views.ExpoView ->
176
- (view as? RnPdfKingView)?.clearSelection()
177
- }
178
-
179
- Prop("handleColor") { view: RnPdfKingView, color: Int ->
180
- view.setHandleColor(color)
181
- }
182
-
183
- Prop("selectionColor") { view: RnPdfKingView, color: Int ->
184
- view.setSelectionColor(color)
185
- }
186
-
187
- Prop("selectionEnabled") { view: RnPdfKingView, enabled: Boolean ->
188
- view.setSelectionEnabled(enabled)
189
- }
190
-
191
- Events("onSelectionChanged", "onSelectionStarted", "onSelectionEnded", "onPreDefinedHighlightClick")
136
+ AsyncFunction("getPageBitmapBase64") { pageNo: Int, promise: Promise ->
137
+ CoroutineScope(Dispatchers.IO).launch {
138
+ try {
139
+ val result = PdfKingManager.getInstance().getPageBitmapBase64(pageNo)
140
+ promise.resolve(result)
141
+ } catch (e: Exception) {
142
+ promise.reject("ERR_BITMAP", e.message, e)
143
+ }
144
+ }
145
+ }
146
+
147
+ AsyncFunction("getTextChars") { pageNo: Int, promise: Promise ->
148
+ CoroutineScope(Dispatchers.IO).launch {
149
+ try {
150
+ val result = PdfKingManager.getInstance().getPageText(pageNo)
151
+ promise.resolve(result)
152
+ } catch (e: Exception) {
153
+ promise.reject("ERR_TEXT", e.message, e)
154
+ }
155
+ }
156
+ }
157
+
158
+ View(RnPdfKingView::class) {
159
+ Prop("pageNo") { view: RnPdfKingView, pageNo: Int ->
160
+ view.setPage(pageNo)
161
+ }
162
+
163
+ Prop("mode") { view: RnPdfKingView, mode: String ->
164
+ view.setMode(mode)
165
+ }
166
+
167
+ Prop("pdfWidth") { view: RnPdfKingView, width: Int ->
168
+ view.setPdfWidth(width)
169
+ }
170
+
171
+ Prop("pdfHeight") { view: RnPdfKingView, height: Int ->
172
+ view.setPdfHeight(height)
173
+ }
174
+
175
+ Prop("preDefinedHighlights") { view: RnPdfKingView, highlights: List<Map<String, Any>> ->
176
+ view.setHighlights(highlights)
177
+ }
178
+
179
+ Prop("preDefinedDottedHighlights") { view: RnPdfKingView, highlights: List<Map<String, Any>> ->
180
+ view.setDottedHighlights(highlights)
181
+ }
182
+
183
+ AsyncFunction("clearSelection") { view: RnPdfKingView ->
184
+ view.clearSelection()
185
+ }
186
+
187
+ Prop("handleColor") { view: RnPdfKingView, color: Int ->
188
+ view.setHandleColor(color)
189
+ }
190
+
191
+ Prop("selectionColor") { view: RnPdfKingView, color: Int ->
192
+ view.setSelectionColor(color)
193
+ }
194
+
195
+ Prop("selectionEnabled") { view: RnPdfKingView, enabled: Boolean ->
196
+ view.setSelectionEnabled(enabled)
197
+ }
198
+
199
+ Events("onSelectionChanged", "onSelectionStarted", "onSelectionEnded", "onPreDefinedHighlightClick")
200
+ }
192
201
  }
193
- }
194
202
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-pdf-king",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "The one and only best pdf library that efficiently handle 1000 page pdf with memeory mangement , easy selection , very customizable and allow pdf to edit",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",