Skip to content

Commit cf9d964

Browse files
author
MTCaptcha
committed
Initial commit for MT Captcha React Native lib
1 parent 69ddbf0 commit cf9d964

File tree

97 files changed

+23914
-2
lines changed

Some content is hidden

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

97 files changed

+23914
-2
lines changed

LICENSE

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
MIT License
22

33
Copyright (c) 2023 MTCaptcha
4-
54
Permission is hereby granted, free of charge, to any person obtaining a copy
65
of this software and associated documentation files (the "Software"), to deal
76
in the Software without restriction, including without limitation the rights

README.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
1-
# react-native-mtcaptcha
1+
# react-native-mtcaptcha
2+
3+
MTCaptcha library for React Native library
4+
5+
## Installation
6+
7+
```sh
8+
npm install react-native-mtcaptcha
9+
```
10+
11+
## Usage
12+
13+
```js
14+
import { MTCaptcha } from 'react-native-mtcaptcha';
15+
16+
17+
```
18+
19+
## Contributing
20+
21+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
22+
23+
## License
24+
25+
MIT
26+
27+
---
28+
29+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)

android/CMakeLists.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 3.4.1)
2+
3+
set (CMAKE_VERBOSE_MAKEFILE ON)
4+
set (CMAKE_CXX_STANDARD 11)
5+
6+
add_library(cpp
7+
SHARED
8+
../cpp/react-native-mtcaptcha.cpp
9+
cpp-adapter.cpp
10+
)
11+
12+
# Specifies a path to native header files.
13+
include_directories(
14+
../cpp
15+
)

android/build.gradle

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
buildscript {
2+
repositories {
3+
google()
4+
mavenCentral()
5+
}
6+
7+
dependencies {
8+
classpath "com.android.tools.build:gradle:7.2.1"
9+
}
10+
}
11+
12+
def isNewArchitectureEnabled() {
13+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
14+
}
15+
16+
apply plugin: "com.android.library"
17+
18+
if (isNewArchitectureEnabled()) {
19+
apply plugin: "com.facebook.react"
20+
}
21+
22+
def getExtOrDefault(name) {
23+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Mtcaptcha_" + name]
24+
}
25+
26+
def getExtOrIntegerDefault(name) {
27+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Mtcaptcha_" + name]).toInteger()
28+
}
29+
30+
def supportsNamespace() {
31+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
32+
def major = parsed[0].toInteger()
33+
def minor = parsed[1].toInteger()
34+
35+
// Namespace support was added in 7.3.0
36+
return (major == 7 && minor >= 3) || major >= 8
37+
}
38+
39+
android {
40+
if (supportsNamespace()) {
41+
namespace "com.mtcaptcha"
42+
43+
sourceSets {
44+
main {
45+
manifest.srcFile "src/main/AndroidManifestNew.xml"
46+
}
47+
}
48+
}
49+
50+
ndkVersion getExtOrDefault("ndkVersion")
51+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
52+
53+
defaultConfig {
54+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
55+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
56+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
57+
58+
externalNativeBuild {
59+
cmake {
60+
cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
61+
abiFilters "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
62+
}
63+
}
64+
}
65+
66+
externalNativeBuild {
67+
cmake {
68+
path "CMakeLists.txt"
69+
}
70+
}
71+
72+
buildFeatures {
73+
buildConfig true
74+
}
75+
76+
buildTypes {
77+
release {
78+
minifyEnabled false
79+
}
80+
}
81+
82+
lintOptions {
83+
disable "GradleCompatible"
84+
}
85+
86+
compileOptions {
87+
sourceCompatibility JavaVersion.VERSION_1_8
88+
targetCompatibility JavaVersion.VERSION_1_8
89+
}
90+
91+
sourceSets {
92+
main {
93+
if (isNewArchitectureEnabled()) {
94+
java.srcDirs += [
95+
"src/newarch",
96+
// This is needed to build Kotlin project with NewArch enabled
97+
"${project.buildDir}/generated/source/codegen/java"
98+
]
99+
} else {
100+
java.srcDirs += ["src/oldarch"]
101+
}
102+
}
103+
}
104+
}
105+
106+
repositories {
107+
mavenCentral()
108+
google()
109+
}
110+
111+
112+
dependencies {
113+
// For < 0.71, this will be from the local maven repo
114+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
115+
//noinspection GradleDynamicVersion
116+
implementation "com.facebook.react:react-native:+"
117+
}
118+
119+
if (isNewArchitectureEnabled()) {
120+
react {
121+
jsRootDir = file("../src/")
122+
libraryName = "Mtcaptcha"
123+
codegenJavaPackageName = "com.mtcaptcha"
124+
}
125+
}

android/cpp-adapter.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <jni.h>
2+
#include "react-native-mtcaptcha.h"
3+
4+
extern "C"
5+
JNIEXPORT jdouble JNICALL
6+
Java_com_mtcaptcha_MtcaptchaModule_nativeMultiply(JNIEnv *env, jclass type, jdouble a, jdouble b) {
7+
return mtcaptcha::multiply(a, b);
8+
}

android/gradle.properties

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Mtcaptcha_kotlinVersion=1.7.0
2+
Mtcaptcha_minSdkVersion=21
3+
Mtcaptcha_targetSdkVersion=31
4+
Mtcaptcha_compileSdkVersion=31
5+
Mtcaptcha_ndkversion=21.4.7075529

android/src/main/AndroidManifest.xml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.mtcaptcha">
3+
</manifest>
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.mtcaptcha;
2+
3+
import androidx.annotation.NonNull;
4+
5+
import com.facebook.react.bridge.Promise;
6+
import com.facebook.react.bridge.ReactApplicationContext;
7+
import com.facebook.react.bridge.ReactMethod;
8+
9+
public class MtcaptchaModule extends MtcaptchaSpec {
10+
public static final String NAME = "Mtcaptcha";
11+
12+
MtcaptchaModule(ReactApplicationContext context) {
13+
super(context);
14+
}
15+
16+
@Override
17+
@NonNull
18+
public String getName() {
19+
return NAME;
20+
}
21+
22+
static {
23+
System.loadLibrary("cpp");
24+
}
25+
26+
public static native double nativeMultiply(double a, double b);
27+
28+
// Example method
29+
// See https://reactnative.dev/docs/native-modules-android
30+
@ReactMethod
31+
public void multiply(double a, double b, Promise promise) {
32+
promise.resolve(nativeMultiply(a, b));
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.mtcaptcha;
2+
3+
import androidx.annotation.Nullable;
4+
5+
import com.facebook.react.bridge.NativeModule;
6+
import com.facebook.react.bridge.ReactApplicationContext;
7+
import com.facebook.react.module.model.ReactModuleInfo;
8+
import com.facebook.react.module.model.ReactModuleInfoProvider;
9+
import com.facebook.react.TurboReactPackage;
10+
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
14+
public class MtcaptchaPackage extends TurboReactPackage {
15+
16+
@Nullable
17+
@Override
18+
public NativeModule getModule(String name, ReactApplicationContext reactContext) {
19+
if (name.equals(MtcaptchaModule.NAME)) {
20+
return new MtcaptchaModule(reactContext);
21+
} else {
22+
return null;
23+
}
24+
}
25+
26+
@Override
27+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
28+
return () -> {
29+
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
30+
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
31+
moduleInfos.put(
32+
MtcaptchaModule.NAME,
33+
new ReactModuleInfo(
34+
MtcaptchaModule.NAME,
35+
MtcaptchaModule.NAME,
36+
false, // canOverrideExistingModule
37+
false, // needsEagerInit
38+
true, // hasConstants
39+
false, // isCxxModule
40+
isTurboModule // isTurboModule
41+
));
42+
return moduleInfos;
43+
};
44+
}
45+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.mtcaptcha;
2+
3+
import com.facebook.react.bridge.ReactApplicationContext;
4+
5+
abstract class MtcaptchaSpec extends NativeMtcaptchaSpec {
6+
MtcaptchaSpec(ReactApplicationContext context) {
7+
super(context);
8+
}
9+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.mtcaptcha;
2+
3+
import com.facebook.react.bridge.ReactApplicationContext;
4+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
5+
import com.facebook.react.bridge.Promise;
6+
7+
abstract class MtcaptchaSpec extends ReactContextBaseJavaModule {
8+
MtcaptchaSpec(ReactApplicationContext context) {
9+
super(context);
10+
}
11+
12+
public abstract void multiply(double a, double b, Promise promise);
13+
}

babel.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: ['module:metro-react-native-babel-preset'],
3+
};

cpp/react-native-mtcaptcha.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "react-native-mtcaptcha.h"
2+
3+
namespace mtcaptcha {
4+
double multiply(double a, double b) {
5+
return a * b;
6+
}
7+
}

cpp/react-native-mtcaptcha.h

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef MTCAPTCHA_H
2+
#define MTCAPTCHA_H
3+
4+
namespace mtcaptcha {
5+
double multiply(double a, double b);
6+
}
7+
8+
#endif /* MTCAPTCHA_H */

example/.bundle/config

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BUNDLE_PATH: "vendor/bundle"
2+
BUNDLE_FORCE_RUBY_PLATFORM: 1

example/.watchmanconfig

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

example/Gemfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
source 'https://rubygems.org'
2+
3+
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
4+
ruby ">= 2.6.10"
5+
6+
gem 'cocoapods', '~> 1.13'
7+
gem 'activesupport', '>= 6.1.7.3', '< 7.1.0'

0 commit comments

Comments
 (0)