Skip to content

Conversation

@coolsoftwaretyler
Copy link
Contributor

@coolsoftwaretyler coolsoftwaretyler commented Nov 18, 2025

This PR will supersede #221 - it rebases against main, which includes important fixes for Expo 53+, and fixes Android builds from the prior PR.

Closes #210

It also implements fixes for the feedback we gave: updates the types to reflect the Google API more closely, reverts image picker changes.

Android

text-recognition-android-works.mp4

iOS

text-recognition-ios-works.MP4

@changeset-bot
Copy link

changeset-bot bot commented Nov 18, 2025

🦋 Changeset detected

Latest commit: 055879a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@infinitered/react-native-mlkit-text-recognition Minor
example-app Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coolsoftwaretyler coolsoftwaretyler marked this pull request as ready for review November 24, 2025 15:21
@coolsoftwaretyler coolsoftwaretyler changed the title Tw/feat text recognition feat: add text recognition module Nov 24, 2025
Comment on lines 16 to 38
suspend fun getInputImage(
imagePath: String
): InputImage {
try {
val bitmap = BitmapFactory.decodeStream(withContext(Dispatchers.IO) {
URL(imagePath).openStream()
})

return InputImage.fromBitmap(bitmap, 0)
} catch (e: Exception) {
throw Exception("RNMLKitTextRecognition: Could not load image from $imagePath", e)
}
}

class RNMLKitTextRecognitionModule : Module() {
override fun definition() = ModuleDefinition {
Name("RNMLKitTextRecognition")

AsyncFunction("recognizeText") { imagePath: String, promise: Promise ->
runBlocking {
val recognizer = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS)

val image: InputImage = getInputImage(imagePath)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, the build.gradle pulls in implementation project(path: ':infinitered-react-native-mlkit-core')

I might have missed it, but I don't believe the core image/label classes are being used it at all. I would expect to see some import form

import red.infinite.reactnativemlkit.core....

Compared to the Swift code (in most modules, not just this one) it seems like we don't construct the RNMLKitImage the same way.

Anyway, I'm not sure it's wrong, just opening it up for discussion:

  1. Should we be using the MLKitCore reusables here? Are they needed or give any benefit?
  2. If not, can be get away with cleaning up the build.gradle dependency?
  3. Also if not, is there feature parity between ios/android with the returned data (it certainly seems to have it).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good point - I think this module followed image labeling, which doesn't use the shared utilities either. We should use those for consistency, IMO. I'll push an update.

I think the end result is roughly the same without it, but it would be good to get all these libraries working the same. I'll also file an issue to migrate image labeling

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@frankcalise frankcalise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last change we missed! Can you update the root README to list the module and point to what would be the new doc page that will be hosted?

Copy link
Collaborator

@frankcalise frankcalise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 🚢

@coolsoftwaretyler coolsoftwaretyler merged commit 21f3109 into main Nov 25, 2025
5 checks passed
@coolsoftwaretyler coolsoftwaretyler deleted the tw/feat-text-recognition branch November 25, 2025 17:05
@coolsoftwaretyler
Copy link
Contributor Author

@all-contributors please add @dccarmo for code and documentation

@allcontributors
Copy link
Contributor

@coolsoftwaretyler

I've put up a pull request to add @dccarmo! 🎉

@coolsoftwaretyler
Copy link
Contributor Author

@all-contributors please add @coolsoftwaretyler for code and documentation

@allcontributors
Copy link
Contributor

@coolsoftwaretyler

I've put up a pull request to add @coolsoftwaretyler! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add basic OCR feature

4 participants