>()
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/android/src/main/java/com/reactnativeandroidsmsverification/AndroidSmsVerificationReceiver.kt:
--------------------------------------------------------------------------------
1 | package com.reactnativeandroidsmsverification
2 |
3 | import android.content.BroadcastReceiver
4 | import android.content.Context
5 | import android.content.Intent
6 | import android.os.Bundle
7 | import com.facebook.react.bridge.ReactApplicationContext
8 | import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
9 | import com.google.android.gms.auth.api.phone.SmsRetriever
10 | import com.google.android.gms.common.api.CommonStatusCodes
11 | import com.google.android.gms.common.api.Status
12 | import java.util.concurrent.TimeoutException
13 |
14 |
15 | class AndroidSmsVerificationReceiver(private val reactContext: ReactApplicationContext) : BroadcastReceiver() {
16 |
17 | override fun onReceive(p0: Context?, intent: Intent?) {
18 | if (intent != null && SmsRetriever.SMS_RETRIEVED_ACTION == intent.action) {
19 | val extras: Bundle? = intent.extras
20 | val status: Status = extras?.get(SmsRetriever.EXTRA_STATUS) as Status
21 | when (status.statusCode) {
22 | CommonStatusCodes.SUCCESS -> {
23 | val message = extras[SmsRetriever.EXTRA_SMS_MESSAGE] as String
24 |
25 | reactContext.getJSModule(RCTDeviceEventEmitter::class.java)
26 | .emit("onMessageReceived", message)
27 | }
28 |
29 | CommonStatusCodes.TIMEOUT -> {
30 | reactContext.getJSModule(RCTDeviceEventEmitter::class.java)
31 | .emit("onReceiverTimeout", "Receiver timeout")
32 | }
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: ['module:metro-react-native-babel-preset'],
3 | };
4 |
--------------------------------------------------------------------------------
/example/android/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | android
4 | Project android created by Buildship.
5 |
6 |
7 |
8 |
9 | org.eclipse.buildship.core.gradleprojectbuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.buildship.core.gradleprojectnature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/example/android/.settings/org.eclipse.buildship.core.prefs:
--------------------------------------------------------------------------------
1 | connection.project.dir=
2 | eclipse.preferences.version=1
3 |
--------------------------------------------------------------------------------
/example/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "com.android.application"
2 |
3 | import com.android.build.OutputFile
4 |
5 | /**
6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
7 | * and bundleReleaseJsAndAssets).
8 | * These basically call `react-native bundle` with the correct arguments during the Android build
9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
10 | * bundle directly from the development server. Below you can see all the possible configurations
11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the
12 | * `apply from: "../../node_modules/react-native/react.gradle"` line.
13 | *
14 | * project.ext.react = [
15 | * // the name of the generated asset file containing your JS bundle
16 | * bundleAssetName: "index.android.bundle",
17 | *
18 | * // the entry file for bundle generation
19 | * entryFile: "index.android.js",
20 | *
21 | * // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
22 | * bundleCommand: "ram-bundle",
23 | *
24 | * // whether to bundle JS and assets in debug mode
25 | * bundleInDebug: false,
26 | *
27 | * // whether to bundle JS and assets in release mode
28 | * bundleInRelease: true,
29 | *
30 | * // whether to bundle JS and assets in another build variant (if configured).
31 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
32 | * // The configuration property can be in the following formats
33 | * // 'bundleIn${productFlavor}${buildType}'
34 | * // 'bundleIn${buildType}'
35 | * // bundleInFreeDebug: true,
36 | * // bundleInPaidRelease: true,
37 | * // bundleInBeta: true,
38 | *
39 | * // whether to disable dev mode in custom build variants (by default only disabled in release)
40 | * // for AndroidSmsVerificationExample: to disable dev mode in the staging build type (if configured)
41 | * devDisabledInStaging: true,
42 | * // The configuration property can be in the following formats
43 | * // 'devDisabledIn${productFlavor}${buildType}'
44 | * // 'devDisabledIn${buildType}'
45 | *
46 | * // the root of your project, i.e. where "package.json" lives
47 | * root: "../../",
48 | *
49 | * // where to put the JS bundle asset in debug mode
50 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
51 | *
52 | * // where to put the JS bundle asset in release mode
53 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release",
54 | *
55 | * // where to put drawable resources / React Native assets, e.g. the ones you use via
56 | * // require('./image.png')), in debug mode
57 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
58 | *
59 | * // where to put drawable resources / React Native assets, e.g. the ones you use via
60 | * // require('./image.png')), in release mode
61 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
62 | *
63 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means
64 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
65 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle
66 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
67 | * // for AndroidSmsVerificationExample, you might want to remove it from here.
68 | * inputExcludes: ["android/**", "ios/**"],
69 | *
70 | * // override which node gets called and with what additional arguments
71 | * nodeExecutableAndArgs: ["node"],
72 | *
73 | * // supply additional arguments to the packager
74 | * extraPackagerArgs: []
75 | * ]
76 | */
77 |
78 | project.ext.react = [
79 | enableHermes: false, // clean and rebuild if changing
80 | ]
81 |
82 | apply from: "../../node_modules/react-native/react.gradle"
83 |
84 | /**
85 | * Set this to true to create two separate APKs instead of one:
86 | * - An APK that only works on ARM devices
87 | * - An APK that only works on x86 devices
88 | * The advantage is the size of the APK is reduced by about 4MB.
89 | * Upload all the APKs to the Play Store and people will download
90 | * the correct one based on the CPU architecture of their device.
91 | */
92 | def enableSeparateBuildPerCPUArchitecture = false
93 |
94 | /**
95 | * Run Proguard to shrink the Java bytecode in release builds.
96 | */
97 | def enableProguardInReleaseBuilds = false
98 |
99 | /**
100 | * The preferred build flavor of JavaScriptCore.
101 | *
102 | * For AndroidSmsVerificationExample, to use the international variant, you can use:
103 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
104 | *
105 | * The international variant includes ICU i18n library and necessary data
106 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
107 | * give correct results when using with locales other than en-US. Note that
108 | * this variant is about 6MiB larger per architecture than default.
109 | */
110 | def jscFlavor = 'org.webkit:android-jsc:+'
111 |
112 | /**
113 | * Whether to enable the Hermes VM.
114 | *
115 | * This should be set on project.ext.react and mirrored here. If it is not set
116 | * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
117 | * and the benefits of using Hermes will therefore be sharply reduced.
118 | */
119 | def enableHermes = project.ext.react.get("enableHermes", false);
120 |
121 | android {
122 | compileSdkVersion rootProject.ext.compileSdkVersion
123 |
124 | compileOptions {
125 | sourceCompatibility JavaVersion.VERSION_1_8
126 | targetCompatibility JavaVersion.VERSION_1_8
127 | }
128 |
129 | defaultConfig {
130 | applicationId "com.example.reactnativeandroidsmsverification"
131 | minSdkVersion rootProject.ext.minSdkVersion
132 | targetSdkVersion rootProject.ext.targetSdkVersion
133 | versionCode 1
134 | versionName "1.0"
135 | }
136 | splits {
137 | abi {
138 | reset()
139 | enable enableSeparateBuildPerCPUArchitecture
140 | universalApk false // If true, also generate a universal APK
141 | include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
142 | }
143 | }
144 | signingConfigs {
145 | debug {
146 | storeFile file('debug.keystore')
147 | storePassword 'android'
148 | keyAlias 'androiddebugkey'
149 | keyPassword 'android'
150 | }
151 | }
152 | buildTypes {
153 | debug {
154 | signingConfig signingConfigs.debug
155 | }
156 | release {
157 | // Caution! In production, you need to generate your own keystore file.
158 | // see https://facebook.github.io/react-native/docs/signed-apk-android.
159 | signingConfig signingConfigs.debug
160 | minifyEnabled enableProguardInReleaseBuilds
161 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
162 | }
163 | }
164 | // applicationVariants are e.g. debug, release
165 | applicationVariants.all { variant ->
166 | variant.outputs.each { output ->
167 | // For each separate APK per architecture, set a unique version code as described here:
168 | // https://developer.android.com/studio/build/configure-apk-splits.html
169 | def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
170 | def abi = output.getFilter(OutputFile.ABI)
171 | if (abi != null) { // null for the universal-debug, universal-release variants
172 | output.versionCodeOverride =
173 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
174 | }
175 |
176 | }
177 | }
178 |
179 | packagingOptions {
180 | pickFirst "lib/armeabi-v7a/libc++_shared.so"
181 | pickFirst "lib/arm64-v8a/libc++_shared.so"
182 | pickFirst "lib/x86/libc++_shared.so"
183 | pickFirst "lib/x86_64/libc++_shared.so"
184 | }
185 | }
186 |
187 | dependencies {
188 | implementation fileTree(dir: "libs", include: ["*.jar"])
189 | //noinspection GradleDynamicVersion
190 | implementation "com.facebook.react:react-native:+" // From node_modules
191 |
192 |
193 | implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
194 | debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
195 | exclude group:'com.facebook.fbjni'
196 | }
197 | debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
198 | exclude group:'com.facebook.flipper'
199 | }
200 | debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
201 | exclude group:'com.facebook.flipper'
202 | }
203 |
204 | if (enableHermes) {
205 | def hermesPath = "../../node_modules/hermes-engine/android/";
206 | debugImplementation files(hermesPath + "hermes-debug.aar")
207 | releaseImplementation files(hermesPath + "hermes-release.aar")
208 | } else {
209 | implementation jscFlavor
210 | }
211 |
212 | implementation project(':reactnativeandroidsmsverification')
213 | }
214 |
215 | // Run this once to be able to run the application with BUCK
216 | // puts all compile dependencies into folder libs for BUCK to use
217 | task copyDownloadableDepsToLibs(type: Copy) {
218 | from configurations.compile
219 | into 'libs'
220 | }
221 |
222 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
223 |
--------------------------------------------------------------------------------
/example/android/app/debug.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolfgio/react-native-android-sms-verification/a81c757ad8cefd5eb3db671a79190d520a51a240/example/android/app/debug.keystore
--------------------------------------------------------------------------------
/example/android/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
--------------------------------------------------------------------------------
/example/android/app/smshash.py:
--------------------------------------------------------------------------------
1 | import platform
2 | import os
3 | import sys
4 | import argparse
5 | import subprocess
6 | from subprocess import Popen, PIPE
7 | import base64
8 | from shutil import which
9 | try:
10 | import hashlib
11 | except ImportError:
12 | sys.exit("please install 'hashlib' module: pip install hashlib")
13 |
14 | #the parser
15 | cmd_parser = argparse.ArgumentParser(description="Computing app's hash string for Android SMS handling")
16 | cmd_parser.add_argument('keystore', type=str, help='Keystore file')
17 | cmd_parser.add_argument('alias', type=str, help='Keystore alias')
18 | cmd_parser.add_argument('keypass', type=str, help='Key password')
19 | cmd_parser.add_argument('appid', type=str, help='Package name of the Android app')
20 | args = cmd_parser.parse_args()
21 |
22 | __encoding_name__ = "iso-8859-1" # Latin 1
23 |
24 | def isWindows():
25 | return platform.system() == "Windows"
26 |
27 | def cmdExist(program):
28 | return which(program) is not None
29 |
30 | def exitWithError(error):
31 | print(error, file=sys.stderr)
32 | sys.exit()
33 |
34 | def call(cmd):
35 | cmd = subprocess.Popen(cmd, shell=True, universal_newlines=True, stdout=PIPE, stderr=PIPE, encoding=__encoding_name__)
36 | cmdResult = cmd.communicate()
37 | return (cmd.returncode, cmdResult[0], cmdResult[1])
38 |
39 | def getKeytoolCommand(withxxd = False):
40 | keytoolName = "keytool"
41 | if not cmdExist(keytoolName):
42 | exitWithError("Error: keytool command not found. Be sure the JDK is installed and available in the PATH")
43 |
44 | if withxxd:
45 | return keytoolName + " " + "-alias " + args.alias + " -exportcert -keystore " + args.keystore + " -storepass " + args.keypass + " | " + getxxdName() + " -p"
46 | else:
47 | return keytoolName + " " + "-alias " + args.alias + " -exportcert -keystore " + args.keystore + " -storepass " + args.keypass
48 |
49 | def getxxdName():
50 | xxdName = "xxd"
51 | if isWindows():
52 | xxdName = "xxd_w"
53 | if not cmdExist(xxdName):
54 | exitWithError("Error: " + xxdName + " not found. If you are on Windows, the program xxd_w.exe must be placed in the current folder")
55 | return xxdName
56 |
57 | def getSignature():
58 | keytoolCommand = getKeytoolCommand()
59 | returncode, out, err = call(keytoolCommand)
60 | if returncode != 0:
61 | print(out)
62 | print(err)
63 | exitWithError("keytool command failed. Please check the alias and the password are correct")
64 | return out
65 |
66 | def getHexSignature():
67 | keytoolWithxxd = getKeytoolCommand(True)
68 | returncode, out, err = call(keytoolWithxxd)
69 | if returncode != 0:
70 | print(out)
71 | print(err)
72 | exitWithError("keytool | xxd command failed")
73 | return out
74 |
75 | def removeWhitespaces(value):
76 | return "".join(value.split())
77 |
78 | def appendApplicationId(value):
79 | return args.appid + " " + value
80 |
81 | def computeSha256(value):
82 | m = hashlib.sha256()
83 | m.update(value.encode(__encoding_name__))
84 | return m.digest()
85 |
86 | def formatSignature(signature):
87 | signatureNoSpaces = removeWhitespaces(signature)
88 | return appendApplicationId(signatureNoSpaces)
89 |
90 | # Call getSignature() to check if the alias and password provided are correct: if not correct the program exits with error
91 | signature = getSignature()
92 | hexSignature = getHexSignature()
93 |
94 | formattedSignature = formatSignature(hexSignature)
95 | sha256 = computeSha256(formattedSignature)
96 | base64 = base64.b64encode(sha256)
97 |
98 | # The hash to use for the SMS is the first 11 chars
99 | print(base64.decode(__encoding_name__)[0:11])
--------------------------------------------------------------------------------
/example/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/android/app/src/debug/java/com/example/reactnativeandroidsmsverification/ReactNativeFlipper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the LICENSE file in the root
5 | * directory of this source tree.
6 | */
7 | package com.example.reactnativeandroidsmsverification;
8 |
9 | import android.content.Context;
10 | import com.facebook.flipper.android.AndroidFlipperClient;
11 | import com.facebook.flipper.android.utils.FlipperUtils;
12 | import com.facebook.flipper.core.FlipperClient;
13 | import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin;
14 | import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin;
15 | import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin;
16 | import com.facebook.flipper.plugins.inspector.DescriptorMapping;
17 | import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin;
18 | import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor;
19 | import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
20 | import com.facebook.flipper.plugins.react.ReactFlipperPlugin;
21 | import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin;
22 | import com.facebook.react.ReactInstanceManager;
23 | import com.facebook.react.bridge.ReactContext;
24 | import com.facebook.react.modules.network.NetworkingModule;
25 | import okhttp3.OkHttpClient;
26 |
27 | public class ReactNativeFlipper {
28 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
29 | if (FlipperUtils.shouldEnableFlipper(context)) {
30 | final FlipperClient client = AndroidFlipperClient.getInstance(context);
31 | client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()));
32 | client.addPlugin(new ReactFlipperPlugin());
33 | client.addPlugin(new DatabasesFlipperPlugin(context));
34 | client.addPlugin(new SharedPreferencesFlipperPlugin(context));
35 | client.addPlugin(CrashReporterPlugin.getInstance());
36 | NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
37 | NetworkingModule.setCustomClientBuilder(
38 | new NetworkingModule.CustomClientBuilder() {
39 | @Override
40 | public void apply(OkHttpClient.Builder builder) {
41 | builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
42 | }
43 | });
44 | client.addPlugin(networkFlipperPlugin);
45 | client.start();
46 | // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
47 | // Hence we run if after all native modules have been initialized
48 | ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
49 | if (reactContext == null) {
50 | reactInstanceManager.addReactInstanceEventListener(
51 | new ReactInstanceManager.ReactInstanceEventListener() {
52 | @Override
53 | public void onReactContextInitialized(ReactContext reactContext) {
54 | reactInstanceManager.removeReactInstanceEventListener(this);
55 | reactContext.runOnNativeModulesQueueThread(
56 | new Runnable() {
57 | @Override
58 | public void run() {
59 | client.addPlugin(new FrescoFlipperPlugin());
60 | }
61 | });
62 | }
63 | });
64 | } else {
65 | client.addPlugin(new FrescoFlipperPlugin());
66 | }
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/example/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
13 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/example/android/app/src/main/java/com/example/reactnativeandroidsmsverification/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.reactnativeandroidsmsverification;
2 |
3 | import com.facebook.react.ReactActivity;
4 |
5 | public class MainActivity extends ReactActivity {
6 |
7 | /**
8 | * Returns the name of the main component registered from JavaScript. This is used to schedule
9 | * rendering of the component.
10 | */
11 | @Override
12 | protected String getMainComponentName() {
13 | return "AndroidSmsVerificationExample";
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/example/android/app/src/main/java/com/example/reactnativeandroidsmsverification/MainApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.reactnativeandroidsmsverification;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 | import com.facebook.react.PackageList;
6 | import com.facebook.react.ReactApplication;
7 | import com.facebook.react.ReactNativeHost;
8 | import com.facebook.react.ReactPackage;
9 | import com.facebook.react.ReactInstanceManager;
10 | import com.facebook.soloader.SoLoader;
11 | import java.lang.reflect.InvocationTargetException;
12 | import java.util.List;
13 |
14 | import com.reactnativeandroidsmsverification.AndroidSmsVerificationPackage;
15 |
16 | public class MainApplication extends Application implements ReactApplication {
17 |
18 | private final ReactNativeHost mReactNativeHost =
19 | new ReactNativeHost(this) {
20 | @Override
21 | public boolean getUseDeveloperSupport() {
22 | return BuildConfig.DEBUG;
23 | }
24 |
25 | @Override
26 | protected List getPackages() {
27 | @SuppressWarnings("UnnecessaryLocalVariable")
28 | List packages = new PackageList(this).getPackages();
29 | // Packages that cannot be autolinked yet can be added manually here, for AndroidSmsVerificationExample:
30 | // packages.add(new MyReactNativePackage());
31 | packages.add(new AndroidSmsVerificationPackage());
32 |
33 | return packages;
34 | }
35 |
36 | @Override
37 | protected String getJSMainModuleName() {
38 | return "index";
39 | }
40 | };
41 |
42 | @Override
43 | public ReactNativeHost getReactNativeHost() {
44 | return mReactNativeHost;
45 | }
46 |
47 | @Override
48 | public void onCreate() {
49 | super.onCreate();
50 | SoLoader.init(this, /* native exopackage */ false);
51 | initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); // Remove this line if you don't want Flipper enabled
52 | }
53 |
54 | /**
55 | * Loads Flipper in React Native templates.
56 | *
57 | * @param context
58 | */
59 | private static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
60 | if (BuildConfig.DEBUG) {
61 | try {
62 | /*
63 | We use reflection here to pick up the class that initializes Flipper,
64 | since Flipper library is not available in release mode
65 | */
66 | Class> aClass = Class.forName("com.reactnativeandroidsmsverificationExample.ReactNativeFlipper");
67 | aClass
68 | .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
69 | .invoke(null, context, reactInstanceManager);
70 | } catch (ClassNotFoundException e) {
71 | e.printStackTrace();
72 | } catch (NoSuchMethodException e) {
73 | e.printStackTrace();
74 | } catch (IllegalAccessException e) {
75 | e.printStackTrace();
76 | } catch (InvocationTargetException e) {
77 | e.printStackTrace();
78 | }
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolfgio/react-native-android-sms-verification/a81c757ad8cefd5eb3db671a79190d520a51a240/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolfgio/react-native-android-sms-verification/a81c757ad8cefd5eb3db671a79190d520a51a240/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolfgio/react-native-android-sms-verification/a81c757ad8cefd5eb3db671a79190d520a51a240/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolfgio/react-native-android-sms-verification/a81c757ad8cefd5eb3db671a79190d520a51a240/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolfgio/react-native-android-sms-verification/a81c757ad8cefd5eb3db671a79190d520a51a240/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolfgio/react-native-android-sms-verification/a81c757ad8cefd5eb3db671a79190d520a51a240/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolfgio/react-native-android-sms-verification/a81c757ad8cefd5eb3db671a79190d520a51a240/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolfgio/react-native-android-sms-verification/a81c757ad8cefd5eb3db671a79190d520a51a240/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolfgio/react-native-android-sms-verification/a81c757ad8cefd5eb3db671a79190d520a51a240/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolfgio/react-native-android-sms-verification/a81c757ad8cefd5eb3db671a79190d520a51a240/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidSmsVerification Example
3 |
4 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/example/android/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext {
5 | buildToolsVersion = "28.0.3"
6 | minSdkVersion = 16
7 | compileSdkVersion = 28
8 | targetSdkVersion = 28
9 | }
10 | repositories {
11 | google()
12 | jcenter()
13 | }
14 | dependencies {
15 | classpath("com.android.tools.build:gradle:3.5.2")
16 |
17 | // NOTE: Do not place your application dependencies here; they belong
18 | // in the individual module build.gradle files
19 | }
20 | }
21 |
22 | allprojects {
23 | repositories {
24 | mavenLocal()
25 | maven {
26 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
27 | url("$rootDir/../node_modules/react-native/android")
28 | }
29 | maven {
30 | // Android JSC is installed from npm
31 | url("$rootDir/../node_modules/jsc-android/dist")
32 | }
33 |
34 | google()
35 | jcenter()
36 | maven { url 'https://www.jitpack.io' }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/example/android/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | android.useAndroidX=true
21 | android.enableJetifier=true
22 | FLIPPER_VERSION=0.33.1
23 |
--------------------------------------------------------------------------------
/example/android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wolfgio/react-native-android-sms-verification/a81c757ad8cefd5eb3db671a79190d520a51a240/example/android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/example/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/example/android/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 | # Determine the Java command to use to start the JVM.
86 | if [ -n "$JAVA_HOME" ] ; then
87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
88 | # IBM's JDK on AIX uses strange locations for the executables
89 | JAVACMD="$JAVA_HOME/jre/sh/java"
90 | else
91 | JAVACMD="$JAVA_HOME/bin/java"
92 | fi
93 | if [ ! -x "$JAVACMD" ] ; then
94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
95 |
96 | Please set the JAVA_HOME variable in your environment to match the
97 | location of your Java installation."
98 | fi
99 | else
100 | JAVACMD="java"
101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
102 |
103 | Please set the JAVA_HOME variable in your environment to match the
104 | location of your Java installation."
105 | fi
106 |
107 | # Increase the maximum file descriptors if we can.
108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
109 | MAX_FD_LIMIT=`ulimit -H -n`
110 | if [ $? -eq 0 ] ; then
111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
112 | MAX_FD="$MAX_FD_LIMIT"
113 | fi
114 | ulimit -n $MAX_FD
115 | if [ $? -ne 0 ] ; then
116 | warn "Could not set maximum file descriptor limit: $MAX_FD"
117 | fi
118 | else
119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
120 | fi
121 | fi
122 |
123 | # For Darwin, add options to specify how the application appears in the dock
124 | if $darwin; then
125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
126 | fi
127 |
128 | # For Cygwin, switch paths to Windows format before running java
129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
132 | JAVACMD=`cygpath --unix "$JAVACMD"`
133 |
134 | # We build the pattern for arguments to be converted via cygpath
135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
136 | SEP=""
137 | for dir in $ROOTDIRSRAW ; do
138 | ROOTDIRS="$ROOTDIRS$SEP$dir"
139 | SEP="|"
140 | done
141 | OURCYGPATTERN="(^($ROOTDIRS))"
142 | # Add a user-defined pattern to the cygpath arguments
143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
145 | fi
146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
147 | i=0
148 | for arg in "$@" ; do
149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
151 |
152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
154 | else
155 | eval `echo args$i`="\"$arg\""
156 | fi
157 | i=$((i+1))
158 | done
159 | case $i in
160 | (0) set -- ;;
161 | (1) set -- "$args0" ;;
162 | (2) set -- "$args0" "$args1" ;;
163 | (3) set -- "$args0" "$args1" "$args2" ;;
164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
170 | esac
171 | fi
172 |
173 | # Escape application args
174 | save () {
175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
176 | echo " "
177 | }
178 | APP_ARGS=$(save "$@")
179 |
180 | # Collect all arguments for the java command, following the shell quoting and substitution rules
181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
182 |
183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
185 | cd "$(dirname "$0")"
186 | fi
187 |
188 | exec "$JAVACMD" "$@"
189 |
--------------------------------------------------------------------------------
/example/android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem http://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
34 |
35 | @rem Find java.exe
36 | if defined JAVA_HOME goto findJavaFromJavaHome
37 |
38 | set JAVA_EXE=java.exe
39 | %JAVA_EXE% -version >NUL 2>&1
40 | if "%ERRORLEVEL%" == "0" goto init
41 |
42 | echo.
43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
44 | echo.
45 | echo Please set the JAVA_HOME variable in your environment to match the
46 | echo location of your Java installation.
47 |
48 | goto fail
49 |
50 | :findJavaFromJavaHome
51 | set JAVA_HOME=%JAVA_HOME:"=%
52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
53 |
54 | if exist "%JAVA_EXE%" goto init
55 |
56 | echo.
57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
58 | echo.
59 | echo Please set the JAVA_HOME variable in your environment to match the
60 | echo location of your Java installation.
61 |
62 | goto fail
63 |
64 | :init
65 | @rem Get command-line arguments, handling Windows variants
66 |
67 | if not "%OS%" == "Windows_NT" goto win9xME_args
68 |
69 | :win9xME_args
70 | @rem Slurp the command line arguments.
71 | set CMD_LINE_ARGS=
72 | set _SKIP=2
73 |
74 | :win9xME_args_slurp
75 | if "x%~1" == "x" goto execute
76 |
77 | set CMD_LINE_ARGS=%*
78 |
79 | :execute
80 | @rem Setup the command line
81 |
82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
83 |
84 | @rem Execute Gradle
85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
86 |
87 | :end
88 | @rem End local scope for the variables with windows NT shell
89 | if "%ERRORLEVEL%"=="0" goto mainEnd
90 |
91 | :fail
92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
93 | rem the _cmd.exe /c_ return code!
94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
95 | exit /b 1
96 |
97 | :mainEnd
98 | if "%OS%"=="Windows_NT" endlocal
99 |
100 | :omega
101 |
--------------------------------------------------------------------------------
/example/android/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'AndroidSmsVerificationExample'
2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
3 | include ':app'
4 |
5 | include ':reactnativeandroidsmsverification'
6 | project(':reactnativeandroidsmsverification').projectDir = new File(rootProject.projectDir, '../../android')
7 |
--------------------------------------------------------------------------------
/example/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "AndroidSmsVerificationExample",
3 | "displayName": "AndroidSmsVerification Example"
4 | }
5 |
--------------------------------------------------------------------------------
/example/babel.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const pak = require('../package.json');
3 |
4 | module.exports = {
5 | presets: ['module:metro-react-native-babel-preset'],
6 | plugins: [
7 | [
8 | 'module-resolver',
9 | {
10 | alias: {
11 | [pak.name]: path.join(__dirname, '..', pak.source),
12 | },
13 | },
14 | ],
15 | ],
16 | };
17 |
--------------------------------------------------------------------------------
/example/index.tsx:
--------------------------------------------------------------------------------
1 | import { AppRegistry } from 'react-native';
2 | import App from './src/App';
3 | import { name as appName } from './app.json';
4 |
5 | AppRegistry.registerComponent(appName, () => App);
6 |
--------------------------------------------------------------------------------
/example/metro.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const blacklist = require('metro-config/src/defaults/blacklist');
3 | const escape = require('escape-string-regexp');
4 | const pak = require('../package.json');
5 |
6 | const root = path.resolve(__dirname, '..');
7 |
8 | const modules = Object.keys({
9 | ...pak.peerDependencies,
10 | });
11 |
12 | module.exports = {
13 | projectRoot: __dirname,
14 | watchFolders: [root],
15 |
16 | // We need to make sure that only one version is loaded for peerDependencies
17 | // So we blacklist them at the root, and alias them to the versions in example's node_modules
18 | resolver: {
19 | blacklistRE: blacklist(
20 | modules.map(
21 | (m) =>
22 | new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)
23 | )
24 | ),
25 |
26 | extraNodeModules: modules.reduce((acc, name) => {
27 | acc[name] = path.join(__dirname, 'node_modules', name);
28 | return acc;
29 | }, {}),
30 | },
31 |
32 | transformer: {
33 | getTransformOptions: async () => ({
34 | transform: {
35 | experimentalImportSupport: false,
36 | inlineRequires: true,
37 | },
38 | }),
39 | },
40 | };
41 |
--------------------------------------------------------------------------------
/example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-android-sms-verification-example",
3 | "description": "Example app for react-native-android-sms-verification",
4 | "version": "0.0.1",
5 | "private": true,
6 | "scripts": {
7 | "android": "react-native run-android",
8 | "ios": "react-native run-ios",
9 | "start": "react-native start"
10 | },
11 | "dependencies": {
12 | "react": "16.11.0",
13 | "react-native": "0.62.2"
14 | },
15 | "devDependencies": {
16 | "@babel/core": "^7.9.6",
17 | "@babel/runtime": "^7.9.6",
18 | "babel-plugin-module-resolver": "^4.0.0",
19 | "metro-react-native-babel-preset": "^0.59.0"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/example/src/App.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import { StyleSheet, View, Text, TextInput } from 'react-native';
3 | import { useSmsRetriver } from 'react-native-android-sms-verification';
4 |
5 | export default function App() {
6 | const { message, startListener, stopListener } = useSmsRetriver();
7 | const [code, setCode] = React.useState('');
8 |
9 | React.useEffect(() => {
10 | const result = message.match('(\\d{6})');
11 |
12 | if (result) {
13 | setCode(result[0]);
14 | }
15 | }, [message]);
16 |
17 | React.useEffect(() => {
18 | startListener();
19 |
20 | return () => stopListener();
21 | // eslint-disable-next-line react-hooks/exhaustive-deps
22 | }, []);
23 |
24 | return (
25 |
26 | SMS will automatically fill this input
27 |
28 |
29 | );
30 | }
31 |
32 | const styles = StyleSheet.create({
33 | container: {
34 | flex: 1,
35 | alignItems: 'center',
36 | justifyContent: 'center',
37 | },
38 | input: {
39 | width: 300,
40 | paddingVertical: 8,
41 | paddingHorizontal: 16,
42 | borderWidth: 1,
43 | borderRadius: 16,
44 | borderColor: '#333',
45 | marginTop: 16,
46 | },
47 | });
48 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-android-sms-verification",
3 | "version": "2.0.8",
4 | "description": "rn abstraction of Android Verification API",
5 | "main": "lib/commonjs/index",
6 | "module": "lib/module/index",
7 | "types": "lib/typescript/src/index.d.ts",
8 | "react-native": "src/index",
9 | "source": "src/index",
10 | "files": [
11 | "src",
12 | "lib",
13 | "android",
14 | "ios",
15 | "cpp",
16 | "react-native-android-sms-verification.podspec",
17 | "!lib/typescript/example",
18 | "!**/__tests__",
19 | "!**/__fixtures__",
20 | "!**/__mocks__"
21 | ],
22 | "scripts": {
23 | "test": "jest",
24 | "typescript": "tsc --noEmit",
25 | "lint": "eslint \"**/*.{js,ts,tsx}\"",
26 | "prepare": "bob build",
27 | "release": "release-it",
28 | "example": "yarn --cwd example",
29 | "bootstrap": "yarn example && yarn && yarn pods"
30 | },
31 | "keywords": [
32 | "react-native",
33 | "android"
34 | ],
35 | "repository": "https://github.com/wolfgio/react-native-android-sms-verification",
36 | "author": "Giovanny Piovesan (https://github.com/wolfgio)",
37 | "license": "MIT",
38 | "bugs": {
39 | "url": "https://github.com/wolfgio/react-native-android-sms-verification/issues"
40 | },
41 | "homepage": "https://github.com/wolfgio/react-native-android-sms-verification#readme",
42 | "devDependencies": {
43 | "@commitlint/config-conventional": "^11.0.0",
44 | "@react-native-community/bob": "^0.16.2",
45 | "@react-native-community/eslint-config": "^2.0.0",
46 | "@release-it/conventional-changelog": "^1.1.4",
47 | "@types/jest": "^26.0.0",
48 | "@types/react": "^16.9.19",
49 | "@types/react-native": "0.62.13",
50 | "commitlint": "^8.3.5",
51 | "eslint": "^7.2.0",
52 | "eslint-config-prettier": "^6.11.0",
53 | "eslint-plugin-prettier": "^3.1.3",
54 | "husky": "^4.2.5",
55 | "jest": "^26.0.1",
56 | "pod-install": "^0.1.0",
57 | "prettier": "^2.0.5",
58 | "react": "16.11.0",
59 | "react-native": "0.62.2",
60 | "release-it": "^14.2.2",
61 | "typescript": "^3.8.3"
62 | },
63 | "peerDependencies": {
64 | "react": "*",
65 | "react-native": "*"
66 | },
67 | "jest": {
68 | "preset": "react-native",
69 | "modulePathIgnorePatterns": [
70 | "/example/node_modules",
71 | "/lib/"
72 | ]
73 | },
74 | "husky": {
75 | "hooks": {
76 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
77 | "pre-commit": "yarn lint && yarn typescript"
78 | }
79 | },
80 | "commitlint": {
81 | "extends": [
82 | "@commitlint/config-conventional"
83 | ]
84 | },
85 | "release-it": {
86 | "git": {
87 | "commitMessage": "chore: release ${version}",
88 | "tagName": "v${version}"
89 | },
90 | "npm": {
91 | "publish": true
92 | },
93 | "github": {
94 | "release": true
95 | },
96 | "plugins": {
97 | "@release-it/conventional-changelog": {
98 | "preset": "angular"
99 | }
100 | }
101 | },
102 | "eslintConfig": {
103 | "extends": [
104 | "@react-native-community",
105 | "prettier"
106 | ],
107 | "rules": {
108 | "prettier/prettier": [
109 | "error",
110 | {
111 | "quoteProps": "consistent",
112 | "singleQuote": true,
113 | "tabWidth": 2,
114 | "trailingComma": "es5",
115 | "useTabs": false
116 | }
117 | ]
118 | }
119 | },
120 | "eslintIgnore": [
121 | "node_modules/",
122 | "lib/"
123 | ],
124 | "prettier": {
125 | "quoteProps": "consistent",
126 | "singleQuote": true,
127 | "tabWidth": 2,
128 | "trailingComma": "es5",
129 | "useTabs": false
130 | },
131 | "@react-native-community/bob": {
132 | "source": "src",
133 | "output": "lib",
134 | "targets": [
135 | "commonjs",
136 | "module",
137 | "typescript"
138 | ]
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/src/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | it.todo('write a test');
2 |
--------------------------------------------------------------------------------
/src/index.tsx:
--------------------------------------------------------------------------------
1 | export { default as useSmsRetriver } from './sms-retriver';
2 |
--------------------------------------------------------------------------------
/src/sms-retriver.tsx:
--------------------------------------------------------------------------------
1 | import { useState, useRef, useCallback, useEffect, useMemo } from 'react';
2 | import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
3 | import type { EmitterSubscription } from 'react-native';
4 |
5 | interface UseSmsRetriver {
6 | message: string;
7 | timeout: boolean;
8 | startListener: () => void;
9 | stopListener: () => void;
10 | }
11 |
12 | const useSmsRetriver = (): UseSmsRetriver => {
13 | const { AndroidSmsVerification } = NativeModules;
14 | const [message, setMessage] = useState('');
15 | const [timeout, setTimeoutState] = useState(false);
16 | const listenerRef = useRef();
17 | const eventEmitter = useMemo(
18 | () => new NativeEventEmitter(AndroidSmsVerification),
19 | [AndroidSmsVerification]
20 | );
21 |
22 | useEffect(() => {
23 | const onStartListener = eventEmitter.addListener(
24 | 'onListenerStarted',
25 | (event) => console.info(event)
26 | );
27 | const onRegisterListener = eventEmitter.addListener(
28 | 'onReceiverRegistered',
29 | (event) => console.info(event)
30 | );
31 | const onUnregisterListener = eventEmitter.addListener(
32 | 'onReceiverUnregistered',
33 | (event) => console.info(event)
34 | );
35 | const onReceiverTimeout = eventEmitter.addListener(
36 | 'onReceiverTimeout',
37 | () => setTimeoutState(true)
38 | );
39 |
40 | return () => {
41 | onStartListener?.remove();
42 | onRegisterListener?.remove();
43 | onUnregisterListener?.remove();
44 | onReceiverTimeout?.remove();
45 | };
46 | }, [eventEmitter]);
47 |
48 | const startListener = useCallback((): void => {
49 | try {
50 | AndroidSmsVerification.registerBroadcastReceiver();
51 | AndroidSmsVerification.startBroadcastReceiver();
52 | setTimeoutState(false);
53 | listenerRef.current = eventEmitter.addListener(
54 | 'onMessageReceived',
55 | setMessage
56 | );
57 | } catch (error) {
58 | console.error(error);
59 | }
60 | }, [AndroidSmsVerification, eventEmitter]);
61 |
62 | const stopListener = useCallback((): void => {
63 | if (Platform.OS === 'android') {
64 | try {
65 | AndroidSmsVerification.unRegisterBroadcastReceiver();
66 | listenerRef.current?.remove();
67 | } catch (error) {
68 | console.error(error);
69 | }
70 | }
71 | }, [AndroidSmsVerification]);
72 |
73 | return { message, timeout, startListener, stopListener };
74 | };
75 |
76 | export default Platform.OS === 'android'
77 | ? useSmsRetriver
78 | : () =>
79 | ({
80 | message: '',
81 | timeout: false,
82 | startListener: () => {},
83 | stopListener: () => {},
84 | } as UseSmsRetriver);
85 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "baseUrl": ".",
4 | "paths": {
5 | "react-native-android-sms-verification": ["./src/index"]
6 | },
7 | "allowUnreachableCode": false,
8 | "allowUnusedLabels": false,
9 | "esModuleInterop": true,
10 | "importsNotUsedAsValues": "error",
11 | "forceConsistentCasingInFileNames": true,
12 | "jsx": "react",
13 | "lib": ["esnext"],
14 | "module": "esnext",
15 | "moduleResolution": "node",
16 | "noFallthroughCasesInSwitch": true,
17 | "noImplicitReturns": true,
18 | "noImplicitUseStrict": false,
19 | "noStrictGenericChecks": false,
20 | "noUnusedLocals": true,
21 | "noUnusedParameters": true,
22 | "resolveJsonModule": true,
23 | "skipLibCheck": true,
24 | "strict": true,
25 | "target": "esnext"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------