Skip to content

Commit f0deb8c

Browse files
committed
chore(text-recognition): init module
1 parent e12740a commit f0deb8c

File tree

75 files changed

+10108
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+10108
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ React Native On-Device Machine Learning w/ Google ML Kit
99
| [Image Labeling](./image-labeling) |||
1010
| [Identify Languages](./identify-languages) |||
1111
| [Face Detection](./face-detection) |||
12-
| Text Recognition |||
12+
| [Text Recognition](./text-recognition) |||
1313
| Barcode Scanning |||
1414
| Object Detection and Tracking |||
1515
| Translate Text |||

text-recognition/.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# node.js
6+
#
7+
node_modules/
8+
npm-debug.log
9+
yarn-error.log
10+
11+
# Xcode
12+
#
13+
build/
14+
*.pbxuser
15+
!default.pbxuser
16+
*.mode1v3
17+
!default.mode1v3
18+
*.mode2v3
19+
!default.mode2v3
20+
*.perspectivev3
21+
!default.perspectivev3
22+
xcuserdata
23+
*.xccheckout
24+
*.moved-aside
25+
DerivedData
26+
*.hmap
27+
*.ipa
28+
*.xcuserstate
29+
project.xcworkspace
30+
31+
# Android/IntelliJ
32+
#
33+
build/
34+
.idea
35+
.gradle
36+
local.properties
37+
*.iml
38+
39+
# BUCK
40+
buck-out/
41+
\.buckd/
42+
*.keystore

text-recognition/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# @react-native-ml-kit/text-recognition
2+
3+
## Getting started
4+
5+
`$ npm install @react-native-ml-kit/text-recognition --save`
6+
7+
### Mostly automatic installation
8+
9+
`$ react-native link @react-native-ml-kit/text-recognition`
10+
11+
## Usage
12+
13+
```javascript
14+
import TextRecognition from '@react-native-ml-kit/text-recognition';
15+
16+
// TODO: What to do with the module?
17+
TextRecognition;
18+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# RNMLKitTextRecognition.podspec
2+
3+
require "json"
4+
5+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
6+
7+
Pod::Spec.new do |s|
8+
s.name = "RNMLKitTextRecognition"
9+
s.version = package["version"]
10+
s.summary = package["description"]
11+
s.homepage = "https://github.com/a7med-mahmoud/react-native-ml-kit"
12+
# brief license entry:
13+
s.license = "MIT"
14+
# optional - use expanded license entry instead:
15+
# s.license = { :type => "MIT", :file => "LICENSE" }
16+
s.authors = { "Ahmed Mahmoud" => "[email protected]" }
17+
s.platforms = { :ios => "9.0" }
18+
s.source = { :git => "https://github.com/a7med-mahmoud/react-native-ml-kit.git", :tag => "#{s.version}" }
19+
20+
s.source_files = "ios/**/*.{h,c,cc,cpp,m,mm,swift}"
21+
s.requires_arc = true
22+
23+
s.dependency "React"
24+
# ...
25+
# s.dependency "..."
26+
end
27+

text-recognition/android/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.iml
2+
gradle/
3+
gradlew
4+
gradlew.bat

text-recognition/android/.npmignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.iml
2+
.DS_Store
3+
.gradle/
4+
.idea/
5+
.npmignore
6+
build/
7+
gradle/
8+
gradlew
9+
gradlew.bat
10+
local.properties

text-recognition/android/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
README
2+
======
3+
4+
If you want to publish the lib as a maven dependency, follow these steps before publishing a new version to npm:
5+
6+
1. Be sure to have the Android [SDK](https://developer.android.com/studio/index.html) and [NDK](https://developer.android.com/ndk/guides/index.html) installed
7+
2. Be sure to have a `local.properties` file in this folder that points to the Android SDK and NDK
8+
```
9+
ndk.dir=/Users/{username}/Library/Android/sdk/ndk-bundle
10+
sdk.dir=/Users/{username}/Library/Android/sdk
11+
```
12+
3. Delete the `maven` folder
13+
4. Run `./gradlew installArchives`
14+
5. Verify that latest set of generated files is in the maven folder with the correct version number

text-recognition/android/build.gradle

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// android/build.gradle
2+
3+
// based on:
4+
//
5+
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
6+
// previous location:
7+
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle
8+
//
9+
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle
10+
// previous location:
11+
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle
12+
13+
// These defaults should reflect the SDK versions used by
14+
// the minimum React Native version supported.
15+
def DEFAULT_COMPILE_SDK_VERSION = 28
16+
def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
17+
def DEFAULT_MIN_SDK_VERSION = 16
18+
def DEFAULT_TARGET_SDK_VERSION = 28
19+
20+
def safeExtGet(prop, fallback) {
21+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
22+
}
23+
24+
apply plugin: 'com.android.library'
25+
apply plugin: 'maven'
26+
27+
buildscript {
28+
// The Android Gradle plugin is only required when opening the android folder stand-alone.
29+
// This avoids unnecessary downloads and potential conflicts when the library is included as a
30+
// module dependency in an application project.
31+
// ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
32+
if (project == rootProject) {
33+
repositories {
34+
google()
35+
}
36+
dependencies {
37+
// This should reflect the Gradle plugin version used by
38+
// the minimum React Native version supported.
39+
classpath 'com.android.tools.build:gradle:3.4.1'
40+
}
41+
}
42+
}
43+
44+
android {
45+
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
46+
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
47+
defaultConfig {
48+
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
49+
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
50+
versionCode 1
51+
versionName "1.0"
52+
}
53+
lintOptions {
54+
abortOnError false
55+
}
56+
}
57+
58+
repositories {
59+
// ref: https://www.baeldung.com/maven-local-repository
60+
mavenLocal()
61+
maven {
62+
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
63+
url "$rootDir/../node_modules/react-native/android"
64+
}
65+
maven {
66+
// Android JSC is installed from npm
67+
url "$rootDir/../node_modules/jsc-android/dist"
68+
}
69+
google()
70+
}
71+
72+
dependencies {
73+
//noinspection GradleDynamicVersion
74+
implementation 'com.facebook.react:react-native:+' // From node_modules
75+
}
76+
77+
def configureReactNativePom(def pom) {
78+
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
79+
80+
pom.project {
81+
name packageJson.title
82+
artifactId packageJson.name
83+
version = packageJson.version
84+
group = "com.rnmlkit.textrecognition"
85+
description packageJson.description
86+
url packageJson.repository.baseUrl
87+
88+
licenses {
89+
license {
90+
name packageJson.license
91+
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
92+
distribution 'repo'
93+
}
94+
}
95+
96+
developers {
97+
developer {
98+
id packageJson.author.username
99+
name packageJson.author.name
100+
}
101+
}
102+
}
103+
}
104+
105+
afterEvaluate { project ->
106+
// some Gradle build hooks ref:
107+
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
108+
task androidJavadoc(type: Javadoc) {
109+
source = android.sourceSets.main.java.srcDirs
110+
classpath += files(android.bootClasspath)
111+
classpath += files(project.getConfigurations().getByName('compile').asList())
112+
include '**/*.java'
113+
}
114+
115+
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
116+
classifier = 'javadoc'
117+
from androidJavadoc.destinationDir
118+
}
119+
120+
task androidSourcesJar(type: Jar) {
121+
classifier = 'sources'
122+
from android.sourceSets.main.java.srcDirs
123+
include '**/*.java'
124+
}
125+
126+
android.libraryVariants.all { variant ->
127+
def name = variant.name.capitalize()
128+
def javaCompileTask = variant.javaCompileProvider.get()
129+
130+
task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
131+
from javaCompileTask.destinationDir
132+
}
133+
}
134+
135+
artifacts {
136+
archives androidSourcesJar
137+
archives androidJavadocJar
138+
}
139+
140+
task installArchives(type: Upload) {
141+
configuration = configurations.archives
142+
repositories.mavenDeployer {
143+
// Deploy to react-native-event-bridge/maven, ready to publish to npm
144+
repository url: "file://${projectDir}/../android/maven"
145+
configureReactNativePom pom
146+
}
147+
}
148+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!-- AndroidManifest.xml -->
2+
3+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
4+
package="com.rnmlkit.textrecognition">
5+
6+
</manifest>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// TextRecognitionModule.java
2+
3+
package com.rnmlkit.textrecognition;
4+
5+
import com.facebook.react.bridge.ReactApplicationContext;
6+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
7+
import com.facebook.react.bridge.ReactMethod;
8+
import com.facebook.react.bridge.Callback;
9+
10+
public class TextRecognitionModule extends ReactContextBaseJavaModule {
11+
12+
private final ReactApplicationContext reactContext;
13+
14+
public TextRecognitionModule(ReactApplicationContext reactContext) {
15+
super(reactContext);
16+
this.reactContext = reactContext;
17+
}
18+
19+
@Override
20+
public String getName() {
21+
return "TextRecognition";
22+
}
23+
24+
@ReactMethod
25+
public void sampleMethod(String stringArgument, int numberArgument, Callback callback) {
26+
// TODO: Implement some actually useful functionality
27+
callback.invoke("Received numberArgument: " + numberArgument + " stringArgument: " + stringArgument);
28+
}
29+
}

0 commit comments

Comments
 (0)