Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
root: true,
extends: ['@react-native'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/no-shadow': ['error'],
'no-shadow': 'off',
'no-undef': 'off',
},
},
],
};
16 changes: 15 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,18 @@ buck-out/
*.keystore

# Tesseract
*.traineddata
*.traineddata

# Compiled TypeScript
/lib
*.d.ts

# Coverage
coverage/

# ESLint cache
.eslintcache

# Temporary folders
tmp/
temp/
11 changes: 11 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
arrowParens: 'avoid',
bracketSameLine: true,
bracketSpacing: false,
singleQuote: true,
trailingComma: 'all',
semi: true,
printWidth: 100,
tabWidth: 2,
useTabs: false,
};
106 changes: 106 additions & 0 deletions SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Development Setup Guide

This document describes how to set up the development environment for react-native-tesseract-ocr.

## Phase 1 Modernization Complete ✅

The following modernizations have been completed:

### Dependencies Updated
- React Native: `0.61.5` → `0.76.0+`
- React: `^16.9.0` → `^18.2.0`
- Android SDK: `28` → `34`
- Gradle: `3.4.1` → `8.2.0`
- Added TypeScript support
- Added modern development tools (ESLint, Prettier, Jest)

### Build System Modernized
- Updated Android build configuration
- Removed deprecated jcenter repository
- Added namespace to Android library
- Updated iOS deployment target to 12.0+
- Added Java 11 compatibility

### TypeScript Support Added
- Complete TypeScript rewrite of JavaScript code
- Type definitions for all APIs
- Modern build system with TypeScript compilation
- Backwards compatibility maintained via index.js wrapper

## Setup Instructions

### Prerequisites
- Node.js 18+
- React Native development environment
- Android Studio with SDK 34
- Xcode 15+ (for iOS development)

### Installation for Development

1. **Install dependencies:**
```bash
npm install
```

2. **Build TypeScript:**
```bash
npm run build
```

3. **Run type checking:**
```bash
npm run typecheck
```

4. **Run linting:**
```bash
npm run lint
```

5. **Format code:**
```bash
npm run format
```

### For End Users

To use this modernized library in your React Native project:

```bash
npm install react-native-tesseract-ocr@latest
```

**Minimum Requirements:**
- React Native 0.74.0+
- React 18.0.0+
- iOS 12.0+
- Android API 21+

## Breaking Changes from 2.x

- Minimum React Native version: 0.74+
- Minimum iOS version: 12.0+
- Minimum Android API: 21+
- Node.js 18+ required for development

## What's Next

Phase 2 will focus on:
- Complete iOS implementation (currently only stub)
- New Architecture support (TurboModules & Fabric)
- Performance optimizations
- Bug fixes for data path and custom language issues

## Testing the Build

After running `npm install` in a project with React Native 0.76+:

```typescript
import TesseractOcr, { LANG_ENGLISH } from 'react-native-tesseract-ocr';

// Basic usage (Android only currently)
const text = await TesseractOcr.recognize('/path/to/image.jpg', LANG_ENGLISH);
console.log('Recognized text:', text);
```

Note: iOS implementation is still a placeholder and will be completed in Phase 2.
27 changes: 16 additions & 11 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@
// original location:
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle

def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_TARGET_SDK_VERSION = 28
def DEFAULT_COMPILE_SDK_VERSION = 34
def DEFAULT_BUILD_TOOLS_VERSION = '34.0.0'
def DEFAULT_MIN_SDK_VERSION = 21
def DEFAULT_TARGET_SDK_VERSION = 34

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

apply plugin: 'com.android.library'
apply plugin: 'maven'

buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
Expand All @@ -30,29 +27,37 @@ buildscript {
if (project == rootProject) {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.android.tools.build:gradle:8.2.0'
}
}
}

apply plugin: 'com.android.library'
apply plugin: 'maven'

android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName "1.0"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

lintOptions {
abortOnError false
}

namespace "com.reactlibrary"
}

repositories {
Expand All @@ -67,7 +72,7 @@ repositories {
url "$rootDir/../node_modules/jsc-android/dist"
}
google()
jcenter()
mavenCentral()
}

dependencies {
Expand Down
4 changes: 2 additions & 2 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.reactlibrary">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest>
64 changes: 3 additions & 61 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,4 @@
import { useEffect } from "react";
import { NativeModules, DeviceEventEmitter } from "react-native";
// Backwards compatibility wrapper
// This file provides compatibility for projects that haven't migrated to the new TypeScript version

export const LANG_AFRIKAANS = "afr";
export const LANG_AMHARIC = "amh";
export const LANG_ARABIC = "ara";
export const LANG_ASSAMESE = "asm";
export const LANG_AZERBAIJANI = "aze";
export const LANG_BELARUSIAN = "bel";
export const LANG_BOSNIAN = "bos";
export const LANG_BULGARIAN = "bul";
export const LANG_CHINESE_SIMPLIFIED = "chi_sim";
export const LANG_CHINESE_TRADITIONAL = "chi_tra";
export const LANG_CROATIAN = "hrv";
export const LANG_CUSTOM = "custom";
export const LANG_DANISH = "dan";
export const LANG_ENGLISH = "eng";
export const LANG_ESTONIAN = "est";
export const LANG_FRENCH = "fra";
export const LANG_GALICIAN = "glg";
export const LANG_GERMAN = "deu";
export const LANG_HEBREW = "heb";
export const LANG_HUNGARIAN = "hun";
export const LANG_ICELANDIC = "isl";
export const LANG_INDONESIAN = "ind";
export const LANG_IRISH = "gle";
export const LANG_ITALIAN = "ita";
export const LANG_JAPANESE = "jpn";
export const LANG_KOREAN = "kor";
export const LANG_LATIN = "lat";
export const LANG_LITHUANIAN = "lit";
export const LANG_NEPALI = "nep";
export const LANG_NORWEGIAN = "nor";
export const LANG_PERSIAN = "fas";
export const LANG_POLISH = "pol";
export const LANG_PORTUGUESE = "por";
export const LANG_RUSSIAN = "rus";
export const LANG_SERBIAN = "srp";
export const LANG_SLOVAK = "slk";
export const LANG_SPANISH = "spa";
export const LANG_SWEDISH = "swe";
export const LANG_TURKISH = "tur";
export const LANG_UKRAINIAN = "ukr";
export const LANG_VIETNAMESE = "vie";
export const LEVEL_BLOCK = "block";
export const LEVEL_LINE = "line";
export const LEVEL_PARAGRAPH = "paragraph";
export const LEVEL_SYMBOL = "symbol";
export const LEVEL_WORD = "word";

export function useEventListener(eventType, listener) {
useEffect(() => {
const subscription = DeviceEventEmitter.addListener(eventType, listener);
return () => {
subscription.remove();
};
});
}

const { TesseractOcr } = NativeModules;

export default TesseractOcr;
module.exports = require('./lib/index');
54 changes: 42 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@
"name": "react-native-tesseract-ocr",
"version": "2.0.3",
"description": "Tesseract OCR wrapper for React Native",
"main": "index.js",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"source": "src/index.ts",
"files": [
"README.md",
"android",
"index.js",
"lib",
"ios",
"src",
"react-native-tesseract-ocr.podspec"
],
"scripts": {
"build": "tsc",
"prepublishOnly": "npm run build",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,md}\"",
"typecheck": "tsc --noEmit",
"cz": "git-cz",
"release": "standard-version",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest",
"prepare": "husky install"
},
"repository": {
"type": "git",
Expand All @@ -38,17 +49,36 @@
"licenseFilename": "LICENSE",
"readmeFilename": "README.md",
"peerDependencies": {
"react": "^16.8.1",
"react-native": ">=0.60.0-rc.0 <1.0.x"
"react": ">=18.0.0",
"react-native": ">=0.74.0"
},
"devDependencies": {
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"cz-conventional-changelog": "^3.1.0",
"husky": "^4.2.5",
"react": "^16.9.0",
"react-native": "^0.61.5",
"standard-version": "^8.0.2"
"@commitlint/cli": "^18.4.0",
"@commitlint/config-conventional": "^18.4.0",
"@react-native/babel-preset": "^0.76.0",
"@react-native/codegen": "^0.76.0",
"@react-native/eslint-config": "^0.76.0",
"@react-native/metro-config": "^0.76.0",
"@react-native/typescript-config": "^0.76.0",
"@types/react": "^18.2.45",
"@types/react-native": "^0.73.0",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.55.0",
"husky": "^8.0.3",
"prettier": "^3.1.1",
"react": "^18.2.0",
"react-native": "^0.76.0",
"standard-version": "^9.5.0",
"typescript": "^5.3.3",
"jest": "^29.7.0",
"@testing-library/react-native": "^12.4.2",
"@testing-library/jest-native": "^5.4.3"
},
"jest": {
"preset": "react-native",
"setupFilesAfterEnv": ["@testing-library/jest-native/extend-expect"],
"testEnvironment": "node",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"]
},
"husky": {
"hooks": {
Expand Down
Loading