react-native-text-reader 1.1.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.
@@ -119,29 +119,24 @@ class TextReaderModule(reactContext: ReactApplicationContext) :
119
119
  }
120
120
  }
121
121
 
122
- @ReactMethod
123
122
  fun read(url: String, options: ReadableMap?, promise: Promise) {
124
123
  try {
125
124
  val script = options?.getString("script")
126
125
 
127
126
  val image = getInputImage(reactApplicationContext, url)
128
-
129
127
  val options = getScriptTextRecognizerOptions(script)
130
128
 
131
129
  val recognizer: TextRecognizer = TextRecognition.getClient(options)
132
130
 
133
131
  recognizer.process(image)
134
132
  .addOnSuccessListener { visionText ->
135
- val result = Arguments.createMap()
136
- result.putString("text", visionText.text)
137
-
138
- val blocksArray = Arguments.createArray()
133
+ val linesArray = Arguments.createArray()
139
134
  visionText.textBlocks.forEach { block ->
140
- blocksArray.pushMap(blockToMap(block))
135
+ block.lines.forEach { line ->
136
+ linesArray.pushString(line.text)
137
+ }
141
138
  }
142
- result.putArray("blocks", blocksArray)
143
-
144
- promise.resolve(result)
139
+ promise.resolve(linesArray)
145
140
  }
146
141
  .addOnFailureListener { e ->
147
142
  e.printStackTrace()
@@ -33,6 +33,11 @@ class TextReader: NSObject {
33
33
  self.handleTextRecognitionResult(request: request, threshold: threshold, error: error, resolve: resolve, reject: reject)
34
34
  }
35
35
 
36
+ if #available(iOS 16.0, *) {
37
+ ocrRequest.automaticallyDetectsLanguage = true
38
+ }
39
+ ocrRequest.recognitionLevel = .accurate
40
+
36
41
  try requestHandler.perform([ocrRequest])
37
42
  } catch {
38
43
  reject("ERR_IMAGE_LOADING", "Failed to load or process the image: \(error.localizedDescription)", nil)
@@ -51,7 +56,7 @@ class TextReader: NSObject {
51
56
  }
52
57
 
53
58
  if observations.isEmpty {
54
- reject("ERR_NO_TEXT_FOUND", "No text found in the image.", nil)
59
+ resolve([])
55
60
  return
56
61
  }
57
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-text-reader",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "A React Native library for OCR (Optical Character Recognition) using Vision Framework on iOS and Firebase ML Kit on Android.",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",