Skip to content

Commit

Permalink
chore(identify-languages): init module
Browse files Browse the repository at this point in the history
  • Loading branch information
a7medev committed Oct 16, 2021
1 parent 6792afb commit 6d30ee3
Show file tree
Hide file tree
Showing 72 changed files with 10,043 additions and 0 deletions.
42 changes: 42 additions & 0 deletions identify-languages/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# OSX
#
.DS_Store

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml

# BUCK
buck-out/
\.buckd/
*.keystore
34 changes: 34 additions & 0 deletions identify-languages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# @react-native-ml-kit/identify-languages

React Native On-Device Identifying Languages w/ Google ML Kit

> **⚠ WARNING: Don't use this in production.**
> This package is still in alpha release, so it's not recommended to use it in production until it's fully stable, although using it for testing perposes is helpful.
## Getting started

`npm install @react-native-ml-kit/identify-languages --save`

### Linking

#### React Native > 0.59

[CLI autolink feature](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md) links the module while building the app.

#### React Native <= 0.59

`react-native link @react-native-ml-kit/identify-languages`

### Installing Pods

On iOS, use CocoaPods to add the native RNMLKitIdentifyLanguages to your project:

`npx pod-install`

## Usage

```javascript
import IdentifyLanguages from '@react-native-ml-kit/identify-languages';

// TODO: add usage examples
```
27 changes: 27 additions & 0 deletions identify-languages/RNMLKitIdentifyLanguages.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# RNMLKitIdentifyLanguages.podspec

require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))

Pod::Spec.new do |s|
s.name = "RNMLKitIdentifyLanguages"
s.version = package["version"]
s.summary = package["description"]
s.homepage = "https://github.com/a7med-mahmoud/react-native-ml-kit"
# brief license entry:
s.license = "MIT"
# optional - use expanded license entry instead:
# s.license = { :type => "MIT", :file => "LICENSE" }
s.authors = { "Ahmed Mahmoud" => "[email protected]" }
s.platforms = { :ios => "9.0" }
s.source = { :git => "https://github.com/a7med-mahmoud/RNMLKitIdentifyLanguages.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,c,cc,cpp,m,mm,swift}"
s.requires_arc = true

s.dependency "React"
# ...
# s.dependency "..."
end

14 changes: 14 additions & 0 deletions identify-languages/android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
README
======

If you want to publish the lib as a maven dependency, follow these steps before publishing a new version to npm:

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
2. Be sure to have a `local.properties` file in this folder that points to the Android SDK and NDK
```
ndk.dir=/Users/{username}/Library/Android/sdk/ndk-bundle
sdk.dir=/Users/{username}/Library/Android/sdk
```
3. Delete the `maven` folder
4. Run `./gradlew installArchives`
5. Verify that latest set of generated files is in the maven folder with the correct version number
148 changes: 148 additions & 0 deletions identify-languages/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// android/build.gradle

// based on:
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
// previous location:
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle
// previous location:
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle

// These defaults should reflect the SDK versions used by
// the minimum React Native version supported.
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 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
// module dependency in an application project.
// ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
if (project == rootProject) {
repositories {
google()
}
dependencies {
// This should reflect the Gradle plugin version used by
// the minimum React Native version supported.
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
}

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"
}
lintOptions {
abortOnError false
}
}

repositories {
// ref: https://www.baeldung.com/maven-local-repository
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
// Android JSC is installed from npm
url "$rootDir/../node_modules/jsc-android/dist"
}
google()
}

dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
}

def configureReactNativePom(def pom) {
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)

pom.project {
name packageJson.title
artifactId packageJson.name
version = packageJson.version
group = "com.rnmlkit.identifylanguages"
description packageJson.description
url packageJson.repository.baseUrl

licenses {
license {
name packageJson.license
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
distribution 'repo'
}
}

developers {
developer {
id packageJson.author.username
name packageJson.author.name
}
}
}
}

afterEvaluate { project ->
// some Gradle build hooks ref:
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.bootClasspath)
classpath += files(project.getConfigurations().getByName('compile').asList())
include '**/*.java'
}

task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
classifier = 'javadoc'
from androidJavadoc.destinationDir
}

task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
include '**/*.java'
}

android.libraryVariants.all { variant ->
def name = variant.name.capitalize()
def javaCompileTask = variant.javaCompileProvider.get()

task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
from javaCompileTask.destinationDir
}
}

artifacts {
archives androidSourcesJar
archives androidJavadocJar
}

task installArchives(type: Upload) {
configuration = configurations.archives
repositories.mavenDeployer {
// Deploy to react-native-event-bridge/maven, ready to publish to npm
repository url: "file://${projectDir}/../android/maven"
configureReactNativePom pom
}
}
}
6 changes: 6 additions & 0 deletions identify-languages/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!-- AndroidManifest.xml -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rnmlkit.identifylanguages">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// IdentifyLanguagesModule.java

package com.rnmlkit.identifylanguages;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;

public class IdentifyLanguagesModule extends ReactContextBaseJavaModule {

private final ReactApplicationContext reactContext;

public IdentifyLanguagesModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}

@Override
public String getName() {
return "IdentifyLanguages";
}

@ReactMethod
public void sampleMethod(String stringArgument, int numberArgument, Callback callback) {
// TODO: Implement some actually useful functionality
callback.invoke("Received numberArgument: " + numberArgument + " stringArgument: " + stringArgument);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// IdentifyLanguagesPackage.java

package com.rnmlkit.identifylanguages;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

public class IdentifyLanguagesPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(new IdentifyLanguagesModule(reactContext));
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
6 changes: 6 additions & 0 deletions identify-languages/example/.buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

[android]
target = Google Inc.:Google APIs:23

[maven_repositories]
central = https://repo1.maven.org/maven2
3 changes: 3 additions & 0 deletions identify-languages/example/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Windows files
[*.bat]
end_of_line = crlf
4 changes: 4 additions & 0 deletions identify-languages/example/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '@react-native-community',
};
Loading

0 comments on commit 6d30ee3

Please sign in to comment.