├── .circleci └── config.yml ├── .editorconfig ├── .gitattributes ├── .github └── dependabot.yml ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── android ├── .project ├── .settings │ └── org.eclipse.buildship.core.prefs ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── reactnativeandroidsmsverification │ ├── AndroidSmsVerificationModule.kt │ ├── AndroidSmsVerificationPackage.kt │ └── AndroidSmsVerificationReceiver.kt ├── babel.config.js ├── example ├── android │ ├── .project │ ├── .settings │ │ └── org.eclipse.buildship.core.prefs │ ├── app │ │ ├── build.gradle │ │ ├── debug.keystore │ │ ├── proguard-rules.pro │ │ ├── smshash.py │ │ └── src │ │ │ ├── debug │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── reactnativeandroidsmsverification │ │ │ │ └── ReactNativeFlipper.java │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── reactnativeandroidsmsverification │ │ │ │ ├── MainActivity.java │ │ │ │ └── MainApplication.java │ │ │ └── res │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ └── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── app.json ├── babel.config.js ├── index.tsx ├── metro.config.js ├── package.json ├── src │ └── App.tsx └── yarn.lock ├── package.json ├── src ├── __tests__ │ └── index.test.tsx ├── index.tsx └── sms-retriver.tsx ├── tsconfig.json └── yarn.lock /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | executors: 4 | default: 5 | docker: 6 | - image: circleci/node:10 7 | working_directory: ~/project 8 | 9 | commands: 10 | attach_project: 11 | steps: 12 | - attach_workspace: 13 | at: ~/project 14 | 15 | jobs: 16 | install-dependencies: 17 | executor: default 18 | steps: 19 | - checkout 20 | - attach_project 21 | - restore_cache: 22 | keys: 23 | - dependencies-{{ checksum "package.json" }} 24 | - dependencies- 25 | - restore_cache: 26 | keys: 27 | - dependencies-example-{{ checksum "example/package.json" }} 28 | - dependencies-example- 29 | - run: 30 | name: Install dependencies 31 | command: | 32 | yarn install --cwd example --frozen-lockfile 33 | yarn install --frozen-lockfile 34 | - save_cache: 35 | key: dependencies-{{ checksum "package.json" }} 36 | paths: node_modules 37 | - save_cache: 38 | key: dependencies-example-{{ checksum "example/package.json" }} 39 | paths: example/node_modules 40 | - persist_to_workspace: 41 | root: . 42 | paths: . 43 | 44 | lint: 45 | executor: default 46 | steps: 47 | - attach_project 48 | - run: 49 | name: Lint files 50 | command: | 51 | yarn lint 52 | 53 | typescript: 54 | executor: default 55 | steps: 56 | - attach_project 57 | - run: 58 | name: Typecheck files 59 | command: | 60 | yarn typescript 61 | 62 | unit-tests: 63 | executor: default 64 | steps: 65 | - attach_project 66 | - run: 67 | name: Run unit tests 68 | command: | 69 | yarn test --coverage 70 | - store_artifacts: 71 | path: coverage 72 | destination: coverage 73 | 74 | build-package: 75 | executor: default 76 | steps: 77 | - attach_project 78 | - run: 79 | name: Build package 80 | command: | 81 | yarn prepare 82 | 83 | deploy: 84 | executor: default 85 | steps: 86 | - attach_project 87 | - run: 88 | name: Authenticate with registry 89 | command: echo "//registry.npmjs.org/:_authToken=$npm_TOKEN" > ~/project/.npmrc 90 | - run: 91 | name: Publish package 92 | command: npm publish 93 | 94 | workflows: 95 | run-test-and-linter: 96 | jobs: 97 | - install-dependencies 98 | - lint: 99 | requires: 100 | - install-dependencies 101 | filters: 102 | branches: 103 | only: master 104 | - typescript: 105 | requires: 106 | - install-dependencies 107 | filters: 108 | branches: 109 | only: master 110 | - unit-tests: 111 | requires: 112 | - install-dependencies 113 | filters: 114 | branches: 115 | only: master 116 | test-build-and-deploy: 117 | jobs: 118 | - install-dependencies: 119 | filters: 120 | tags: 121 | only: /.*/ 122 | branches: 123 | ignore: /.*/ 124 | - lint: 125 | requires: 126 | - install-dependencies 127 | filters: 128 | tags: 129 | only: /.*/ 130 | branches: 131 | ignore: /.*/ 132 | - typescript: 133 | requires: 134 | - install-dependencies 135 | - lint 136 | filters: 137 | tags: 138 | only: /.*/ 139 | branches: 140 | ignore: /.*/ 141 | - unit-tests: 142 | requires: 143 | - install-dependencies 144 | - lint 145 | - typescript 146 | filters: 147 | tags: 148 | only: /.*/ 149 | branches: 150 | ignore: /.*/ 151 | - build-package: 152 | requires: 153 | - install-dependencies 154 | - lint 155 | - typescript 156 | - unit-tests 157 | filters: 158 | tags: 159 | only: /.*/ 160 | branches: 161 | ignore: /.*/ 162 | - deploy: 163 | requires: 164 | - install-dependencies 165 | - lint 166 | - typescript 167 | - unit-tests 168 | - build-package 169 | filters: 170 | tags: 171 | only: /.*/ 172 | branches: 173 | ignore: /.*/ 174 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "npm" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "daily" 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | 32 | # Android/IJ 33 | # 34 | .idea 35 | .gradle 36 | local.properties 37 | android.iml 38 | 39 | # Cocoapods 40 | # 41 | example/ios/Pods 42 | 43 | # node.js 44 | # 45 | node_modules/ 46 | npm-debug.log 47 | yarn-debug.log 48 | yarn-error.log 49 | 50 | # BUCK 51 | buck-out/ 52 | \.buckd/ 53 | android/app/libs 54 | android/keystores/debug.keystore 55 | 56 | # Expo 57 | .expo/* 58 | 59 | # generated by bob 60 | lib/ 61 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. 4 | 5 | ## Development workflow 6 | 7 | To get started with the project, run `yarn bootstrap` in the root directory to install the required dependencies for each package: 8 | 9 | ```sh 10 | yarn bootstrap 11 | ``` 12 | 13 | While developing, you can run the [example app](/example/) to test your changes. 14 | 15 | To start the packager: 16 | 17 | ```sh 18 | yarn example start 19 | ``` 20 | 21 | To run the example app on Android: 22 | 23 | ```sh 24 | yarn example android 25 | ``` 26 | 27 | Make sure your code passes TypeScript and ESLint. Run the following to verify: 28 | 29 | ```sh 30 | yarn typescript 31 | yarn lint 32 | ``` 33 | 34 | To fix formatting errors, run the following: 35 | 36 | ```sh 37 | yarn lint --fix 38 | ``` 39 | 40 | Remember to add tests for your change if possible. Run the unit tests by: 41 | 42 | ```sh 43 | yarn test 44 | ``` 45 | 46 | To edit the Kotlin files, open `example/android` in Android studio and find the source files at `reactnativeandroidsmsverification` under `Android`. 47 | 48 | ### Commit message convention 49 | 50 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages: 51 | 52 | - `fix`: bug fixes, e.g. fix crash due to deprecated method. 53 | - `feat`: new features, e.g. add new method to the module. 54 | - `refactor`: code refactor, e.g. migrate from class components to hooks. 55 | - `docs`: changes into documentation, e.g. add usage example for the module.. 56 | - `test`: adding or updating tests, eg add integration tests using detox. 57 | - `chore`: tooling changes, e.g. change CI config. 58 | 59 | Our pre-commit hooks verify that your commit message matches this format when committing. 60 | 61 | ### Linting and tests 62 | 63 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/) 64 | 65 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing. 66 | 67 | Our pre-commit hooks verify that the linter and tests pass when committing. 68 | 69 | ### Scripts 70 | 71 | The `package.json` file contains various scripts for common tasks: 72 | 73 | - `yarn bootstrap`: setup project by installing all dependencies and pods. 74 | - `yarn typescript`: type-check files with TypeScript. 75 | - `yarn lint`: lint files with ESLint. 76 | - `yarn test`: run unit tests with Jest. 77 | - `yarn example start`: start the Metro server for the example app. 78 | - `yarn example android`: run the example app on Android. 79 | 80 | ### Sending a pull request 81 | 82 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github). 83 | 84 | When you're sending a pull request: 85 | 86 | - Prefer small pull requests focused on one change. 87 | - Verify that linters and tests are passing. 88 | - Review the documentation to make sure it looks good. 89 | - Follow the pull request template when opening a pull request. 90 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue. 91 | 92 | ## Code of Conduct 93 | 94 | ### Our Pledge 95 | 96 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 97 | 98 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 99 | 100 | ### Our Standards 101 | 102 | Examples of behavior that contributes to a positive environment for our community include: 103 | 104 | - Demonstrating empathy and kindness toward other people 105 | - Being respectful of differing opinions, viewpoints, and experiences 106 | - Giving and gracefully accepting constructive feedback 107 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 108 | - Focusing on what is best not just for us as individuals, but for the overall community 109 | 110 | Examples of unacceptable behavior include: 111 | 112 | - The use of sexualized language or imagery, and sexual attention or 113 | advances of any kind 114 | - Trolling, insulting or derogatory comments, and personal or political attacks 115 | - Public or private harassment 116 | - Publishing others' private information, such as a physical or email 117 | address, without their explicit permission 118 | - Other conduct which could reasonably be considered inappropriate in a 119 | professional setting 120 | 121 | ### Enforcement Responsibilities 122 | 123 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 124 | 125 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 126 | 127 | ### Scope 128 | 129 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 130 | 131 | ### Enforcement 132 | 133 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly. 134 | 135 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 136 | 137 | ### Enforcement Guidelines 138 | 139 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 140 | 141 | #### 1. Correction 142 | 143 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 144 | 145 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. 146 | 147 | #### 2. Warning 148 | 149 | **Community Impact**: A violation through a single incident or series of actions. 150 | 151 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. 152 | 153 | #### 3. Temporary Ban 154 | 155 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 156 | 157 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. 158 | 159 | #### 4. Permanent Ban 160 | 161 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. 162 | 163 | **Consequence**: A permanent ban from any sort of public interaction within the community. 164 | 165 | ### Attribution 166 | 167 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 168 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 169 | 170 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 171 | 172 | [homepage]: https://www.contributor-covenant.org 173 | 174 | For answers to common questions about this code of conduct, see the FAQ at 175 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 176 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Giovanny Piovesan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-android-sms-verification 2 | 3 | rn abstraction of Android SMS Verification API 4 | 5 | [![CircleCI](https://circleci.com/gh/wolfgio/react-native-android-sms-verification.svg?style=svg)](https://circleci.com/gh/wolfgio/react-native-android-sms-verification) [![npm](https://img.shields.io/npm/v/react-native-android-sms-verification)](https://www.npmjs.com/package/react-native-android-sms-verification) 6 | 7 | https://developers.google.com/identity/sms-retriever/overview 8 | 9 | ## Installation 10 | 11 | ```sh 12 | npm install react-native-android-sms-verification 13 | ``` 14 | 15 | ## Usage 16 | 17 | ```js 18 | import { useSmsRetriver } from 'react-native-android-sms-verification'; 19 | 20 | const { message, timeout, startListener, stopListener } = useSmsRetriver(); 21 | ``` 22 | 23 | ## Contributing 24 | 25 | See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. 26 | 27 | ## License 28 | 29 | MIT 30 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /android/.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | arguments= 2 | auto.sync=false 3 | build.scans.enabled=false 4 | connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.0)) 5 | connection.project.dir= 6 | eclipse.preferences.version=1 7 | gradle.user.home= 8 | java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home 9 | jvm.arguments= 10 | offline.mode=false 11 | override.workspace.settings=true 12 | show.console.view=true 13 | show.executions.view=true 14 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | // Buildscript is evaluated before everything else so we can't use getExtOrDefault 3 | def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['AndroidSmsVerification_kotlinVersion'] 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.2.1' 12 | // noinspection DifferentKotlinGradleVersion 13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 14 | } 15 | } 16 | 17 | apply plugin: 'com.android.library' 18 | apply plugin: 'kotlin-android' 19 | 20 | def getExtOrDefault(name) { 21 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['AndroidSmsVerification_' + name] 22 | } 23 | 24 | def getExtOrIntegerDefault(name) { 25 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['AndroidSmsVerification_' + name]).toInteger() 26 | } 27 | 28 | android { 29 | compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') 30 | buildToolsVersion getExtOrDefault('buildToolsVersion') 31 | defaultConfig { 32 | minSdkVersion 16 33 | targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') 34 | versionCode 1 35 | versionName "2.0.8" 36 | 37 | } 38 | 39 | buildTypes { 40 | release { 41 | minifyEnabled false 42 | } 43 | } 44 | lintOptions { 45 | disable 'GradleCompatible' 46 | } 47 | compileOptions { 48 | sourceCompatibility JavaVersion.VERSION_1_8 49 | targetCompatibility JavaVersion.VERSION_1_8 50 | } 51 | } 52 | 53 | repositories { 54 | mavenCentral() 55 | jcenter() 56 | google() 57 | 58 | def found = false 59 | def defaultDir = null 60 | def androidSourcesName = 'React Native sources' 61 | 62 | if (rootProject.ext.has('reactNativeAndroidRoot')) { 63 | defaultDir = rootProject.ext.get('reactNativeAndroidRoot') 64 | } else { 65 | defaultDir = new File( 66 | projectDir, 67 | '/../../../node_modules/react-native/android' 68 | ) 69 | } 70 | 71 | if (defaultDir.exists()) { 72 | maven { 73 | url defaultDir.toString() 74 | name androidSourcesName 75 | } 76 | 77 | logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}") 78 | found = true 79 | } else { 80 | def parentDir = rootProject.projectDir 81 | 82 | 1.upto(5, { 83 | if (found) return true 84 | parentDir = parentDir.parentFile 85 | 86 | def androidSourcesDir = new File( 87 | parentDir, 88 | 'node_modules/react-native' 89 | ) 90 | 91 | def androidPrebuiltBinaryDir = new File( 92 | parentDir, 93 | 'node_modules/react-native/android' 94 | ) 95 | 96 | if (androidPrebuiltBinaryDir.exists()) { 97 | maven { 98 | url androidPrebuiltBinaryDir.toString() 99 | name androidSourcesName 100 | } 101 | 102 | logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}") 103 | found = true 104 | } else if (androidSourcesDir.exists()) { 105 | maven { 106 | url androidSourcesDir.toString() 107 | name androidSourcesName 108 | } 109 | 110 | logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}") 111 | found = true 112 | } 113 | }) 114 | } 115 | 116 | if (!found) { 117 | throw new GradleException( 118 | "${project.name}: unable to locate React Native android sources. " + 119 | "Ensure you have you installed React Native as a dependency in your project and try again." 120 | ) 121 | } 122 | } 123 | 124 | def kotlin_version = getExtOrDefault('kotlinVersion') 125 | 126 | dependencies { 127 | // noinspection GradleDynamicVersion 128 | api 'com.facebook.react:react-native:+' 129 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 130 | implementation 'com.google.android.gms:play-services-auth:17.0.0' 131 | implementation 'com.google.android.gms:play-services-auth-api-phone:17.4.0' 132 | } 133 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | AndroidSmsVerification_kotlinVersion=1.3.50 2 | AndroidSmsVerification_compileSdkVersion=29 3 | AndroidSmsVerification_buildToolsVersion=20.0.2 4 | AndroidSmsVerification_targetSdkVersion=29 5 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wolfgio/react-native-android-sms-verification/a81c757ad8cefd5eb3db671a79190d520a51a240/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Aug 25 19:35:13 BRT 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip 7 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativeandroidsmsverification/AndroidSmsVerificationModule.kt: -------------------------------------------------------------------------------- 1 | package com.reactnativeandroidsmsverification 2 | 3 | import android.content.IntentFilter 4 | import android.util.Log 5 | import com.facebook.react.bridge.* 6 | import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter 7 | import com.google.android.gms.auth.api.phone.SmsRetriever 8 | import com.google.android.gms.auth.api.phone.SmsRetrieverClient 9 | 10 | 11 | class AndroidSmsVerificationModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext), LifecycleEventListener { 12 | private val receiver: AndroidSmsVerificationReceiver? 13 | private val client: SmsRetrieverClient 14 | private var isReceiverRegistered: Boolean 15 | 16 | 17 | init { 18 | this.receiver = AndroidSmsVerificationReceiver(reactContext) 19 | this.isReceiverRegistered = false 20 | this.client = SmsRetriever.getClient(reactContext) 21 | reactContext.addLifecycleEventListener(this) 22 | } 23 | 24 | override fun getName(): String { 25 | return "AndroidSmsVerification" 26 | } 27 | 28 | @ReactMethod 29 | fun registerBroadcastReceiver() { 30 | this.registerReceiver() 31 | } 32 | 33 | @ReactMethod 34 | fun unRegisterBroadcastReceiver() { 35 | this.unRegisterReceiver() 36 | } 37 | 38 | @ReactMethod 39 | fun startBroadcastReceiver() { 40 | if (isReceiverRegistered) { 41 | try { 42 | val task = client.startSmsRetriever(); 43 | 44 | task.addOnSuccessListener { 45 | Log.d(this.name, "Listener started!") 46 | reactContext.getJSModule(RCTDeviceEventEmitter::class.java) 47 | .emit("onListenerStarted", "Listener started!") 48 | } 49 | 50 | task.addOnFailureListener { 51 | exception -> exception.printStackTrace() 52 | } 53 | } catch (e: Exception) { 54 | throw Exception("Failed to start listener: ${e.message}", e) 55 | } 56 | } else { 57 | throw Exception("Please register the receiver before starting it") 58 | } 59 | } 60 | 61 | private fun registerReceiver() { 62 | if (receiver == null || currentActivity == null) return 63 | 64 | try { 65 | currentActivity!!.registerReceiver(this.receiver, IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION)) 66 | Log.d(this.name, "Receiver registered!") 67 | reactContext.getJSModule(RCTDeviceEventEmitter::class.java) 68 | .emit("onReceiverRegistered", "Broadcast Receiver registered!") 69 | isReceiverRegistered = true 70 | } catch (e: Exception) { 71 | throw Exception("Failed to register the receiver: ${e.message}", e) 72 | } 73 | } 74 | 75 | 76 | private fun unRegisterReceiver() { 77 | if (receiver == null || currentActivity == null || isReceiverRegistered) return 78 | 79 | try { 80 | currentActivity!!.unregisterReceiver(this.receiver) 81 | Log.d(this.name, "Receiver unRegistered!") 82 | reactContext.getJSModule(RCTDeviceEventEmitter::class.java) 83 | .emit("onReceiverUnregistered", "Broadcast Receiver unregistered!") 84 | isReceiverRegistered = false 85 | } catch (e: Exception) { 86 | throw Exception("Failed to unRegister the receiver: ${e.message}", e) 87 | } 88 | } 89 | 90 | override fun onHostResume() { 91 | this.registerReceiver() 92 | } 93 | 94 | override fun onHostPause() { 95 | this.unRegisterReceiver() 96 | } 97 | 98 | override fun onHostDestroy() { 99 | this.unRegisterReceiver() 100 | } 101 | } 102 | 103 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativeandroidsmsverification/AndroidSmsVerificationPackage.kt: -------------------------------------------------------------------------------- 1 | package com.reactnativeandroidsmsverification 2 | 3 | import java.util.Arrays 4 | 5 | import com.facebook.react.ReactPackage 6 | import com.facebook.react.bridge.NativeModule 7 | import com.facebook.react.bridge.ReactApplicationContext 8 | import com.facebook.react.uimanager.ViewManager 9 | 10 | class AndroidSmsVerificationPackage : ReactPackage { 11 | override fun createNativeModules(reactContext: ReactApplicationContext): List { 12 | return listOf(AndroidSmsVerificationModule(reactContext)) 13 | } 14 | 15 | override fun createViewManagers(reactContext: ReactApplicationContext): List> { 16 | return emptyList>() 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 | --------------------------------------------------------------------------------