├── .gitattributes ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── android ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── eddieowens │ ├── RNBoundaryModule.java │ ├── RNBoundaryPackage.java │ ├── errors │ └── GeofenceErrorMessages.java │ ├── receivers │ └── BoundaryEventBroadcastReceiver.java │ └── services │ ├── BoundaryEventHeadlessTaskService.java │ └── BoundaryEventJobIntentService.java ├── index.js ├── ios ├── RNBoundary.h ├── RNBoundary.m ├── RNBoundary.podspec ├── RNBoundary.xcodeproj │ └── project.pbxproj └── RNBoundary.xcworkspace │ └── contents.xcworkspacedata ├── package.json ├── typings └── index.d.ts └── yarn.lock /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # OSX 3 | # 4 | .DS_Store 5 | 6 | # node.js 7 | # 8 | node_modules/ 9 | npm-debug.log 10 | yarn-error.log 11 | 12 | 13 | # Xcode 14 | # 15 | build/ 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | xcuserdata 25 | *.xccheckout 26 | *.moved-aside 27 | DerivedData 28 | *.hmap 29 | *.ipa 30 | *.xcuserstate 31 | project.xcworkspace 32 | 33 | 34 | # Android/IntelliJ 35 | # 36 | build/ 37 | .idea 38 | .gradle 39 | local.properties 40 | *.iml 41 | 42 | # BUCK 43 | buck-out/ 44 | \.buckd/ 45 | *.keystore 46 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | npm-debug.log 4 | 5 | # Xcode 6 | xcuserdata 7 | project.xcworkspace 8 | ios/react-native 9 | 10 | # Android/IJ 11 | .idea 12 | .gradle 13 | local.properties 14 | *.iml 15 | build 16 | *.skip -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # react-native-boundary 3 | 4 | A simple, native, and efficient geofencing/region monitoring react native library for both iOS and android. 5 | 6 | ## Usage 7 | ```javascript 8 | import Boundary, {Events} from 'react-native-boundary'; 9 | 10 | class MyComponent extends Class { 11 | componentWillMount() { 12 | Boundary.add({ 13 | lat: 34.017714, 14 | lng: -118.499033, 15 | radius: 50, // in meters 16 | id: "Chipotle", 17 | }) 18 | .then(() => console.log("success!")) 19 | .catch(e => console.error("error :(", e)); 20 | 21 | Boundary.on(Events.ENTER, id => { 22 | // Prints 'Get out of my Chipotle!!' 23 | console.log(`Get out of my ${id}!!`); 24 | }); 25 | 26 | Boundary.on(Events.EXIT, id => { 27 | // Prints 'Ya! You better get out of my Chipotle!!' 28 | console.log(`Ya! You better get out of my ${id}!!`) 29 | }) 30 | } 31 | 32 | componentWillUnmount() { 33 | // Remove the events 34 | Boundary.off(Events.ENTER) 35 | Boundary.off(Events.EXIT) 36 | 37 | // Remove the boundary from native API´s 38 | Boundary.remove('Chipotle') 39 | .then(() => console.log('Goodbye Chipotle :(')) 40 | .catch(e => console.log('Failed to delete Chipotle :)', e)) 41 | } 42 | } 43 | ``` 44 | ## Getting started 45 | 46 | `$ npm install react-native-boundary --save` 47 | 48 | ### Automatic Installation 49 | 50 | `$ react-native link react-native-boundary` 51 | 52 | ### Manual installation 53 | 54 | 55 | #### iOS 56 | 57 | 1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]` 58 | 2. Go to `node_modules` ➜ `react-native-boundary` and add `RNBoundary.xcodeproj` 59 | 3. In XCode, in the project navigator, select your project. Add `libRNBoundary.a` to your project's `Build Phases` ➜ `Link Binary With Libraries` 60 | 4. Run your project (`Cmd+R`)< 61 | 62 | #### Android 63 | 64 | 1. Open up `android/app/src/main/java/[...]/MainActivity.java` 65 | - Add `import com.eddieowens.RNBoundaryPackage;` to the imports at the top of the file 66 | - Add `new RNBoundaryPackage()` to the list returned by the `getPackages()` method 67 | 2. Append the following lines to `android/settings.gradle`: 68 | ``` 69 | include ':react-native-boundary' 70 | project(':react-native-boundary').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-boundary/android') 71 | ``` 72 | 3. Insert the following lines inside the dependencies block in `android/app/build.gradle`: 73 | ``` 74 | compile project(':react-native-boundary') 75 | ``` 76 | 77 | ### Post Install 78 | 79 | #### Android 80 | 81 | Add the `ACCESS_FINE_LOCATION` permission to your `AndroidManifest.xml` like so, 82 | 83 | ```xml 84 | 86 | 87 | ... 88 | 89 | ``` 90 | 91 | #### iOS 92 | Before iOS 11: 93 | Add the following to your `Info.plist`: 94 | - `NSLocationAlwaysUsageDescription` 95 | 96 | For iOS 11: 97 | Add the following to your `Info.plist`: 98 | - `NSLocationWhenInUseUsageDescription` 99 | - `NSLocationAlwaysAndWhenInUseUsageDescription` 100 | 101 | ## API 102 | 103 | ### Functions 104 | Name | Arguments | Note 105 | ----------- | --------------------------------------------- | --- 106 | `on` | event: [event](#events), callback: `function` | Triggers the callback when the `event` occurs. The callback will be passed an array of boundary ids as `strings`. Can be called in the background 107 | `off` | event: [event](#events) | Removes bound event listeners 108 | `add` | boundary: [boundary](#boundary) | Adds a `Boundary` that can be triggered when an [event](#events) occurs 109 | `remove` | id: `string` | Removes a Boundary from being triggered. Boundaries will remain until `remove` or `removeAll` is called or the app is uninstalled 110 | `removeAll` | `void` | Removes all boundaries and event callbacks. 111 | 112 | ### Types 113 | #### Boundary 114 | Field | Type | Note 115 | -------- | -------- | ---- 116 | `id` | `string` | ID for your boundary. Value that is returned when an [event](#events) is triggered 117 | `lat` | `number` | Must be a valid latitude 118 | `lng` | `number` | Must be a valid longitude 119 | `radius` | `number` | In meters. It is highly suggested that the `radius` is greater than 50 meters 120 | 121 | #### Events 122 | Field | Type | Note 123 | -------- | --------- | ---- 124 | `ENTER` | `string` | Event for when a user enters a [boundary](#boundary) 125 | `EXIT` | `string` | Event for when a user exits a [boundary](#boundary) 126 | 127 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | google() 5 | } 6 | 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:3.1.3' 9 | } 10 | } 11 | 12 | apply plugin: 'com.android.library' 13 | 14 | def DEFAULT_COMPILE_SDK_VERSION = 26 15 | def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3" 16 | def DEFAULT_TARGET_SDK_VERSION = 26 17 | def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "15.0.1" 18 | 19 | android { 20 | compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION 21 | buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION 22 | 23 | defaultConfig { 24 | minSdkVersion 16 25 | targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION 26 | versionCode 1 27 | versionName "1.0" 28 | } 29 | lintOptions { 30 | abortOnError false 31 | } 32 | } 33 | 34 | repositories { 35 | mavenLocal() 36 | google() 37 | jcenter() 38 | maven { 39 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 40 | url "$rootDir/../node_modules/react-native/android" 41 | } 42 | } 43 | 44 | def googlePlayServicesVersion = rootProject.hasProperty('googlePlayServicesVersion') ? rootProject.googlePlayServicesVersion : DEFAULT_GOOGLE_PLAY_SERVICES_VERSION 45 | 46 | dependencies { 47 | implementation "com.google.android.gms:play-services-location:$googlePlayServicesVersion" 48 | api 'com.facebook.react:react-native:+' 49 | } 50 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddieowens/react-native-boundary/03fecc1f75b73f4ea51a87036f87a97c5904ade7/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 6 | -------------------------------------------------------------------------------- /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 | 6 | 7 | 8 | 9 | 14 | 15 | 16 | 17 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /android/src/main/java/com/eddieowens/RNBoundaryModule.java: -------------------------------------------------------------------------------- 1 | package com.eddieowens; 2 | 3 | import android.Manifest; 4 | import android.app.PendingIntent; 5 | import android.content.Intent; 6 | import android.content.pm.PackageManager; 7 | import android.support.annotation.NonNull; 8 | import android.support.v4.app.ActivityCompat; 9 | import android.util.Log; 10 | 11 | import com.eddieowens.receivers.BoundaryEventBroadcastReceiver; 12 | import com.facebook.react.bridge.Arguments; 13 | import com.facebook.react.bridge.LifecycleEventListener; 14 | import com.facebook.react.bridge.Promise; 15 | import com.facebook.react.bridge.ReactApplicationContext; 16 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 17 | import com.facebook.react.bridge.ReactMethod; 18 | import com.facebook.react.bridge.ReadableArray; 19 | import com.facebook.react.bridge.ReadableMap; 20 | import com.facebook.react.bridge.WritableArray; 21 | import com.google.android.gms.location.Geofence; 22 | import com.google.android.gms.location.GeofencingClient; 23 | import com.google.android.gms.location.GeofencingRequest; 24 | import com.google.android.gms.location.LocationServices; 25 | import com.google.android.gms.tasks.OnFailureListener; 26 | import com.google.android.gms.tasks.OnSuccessListener; 27 | 28 | import java.util.ArrayList; 29 | import java.util.Collections; 30 | import java.util.List; 31 | 32 | public class RNBoundaryModule extends ReactContextBaseJavaModule implements LifecycleEventListener { 33 | 34 | public static final String TAG = "RNBoundary"; 35 | public static final String ON_ENTER = "onEnter"; 36 | public static final String ON_EXIT = "onExit"; 37 | public static final String GEOFENCE_DATA_TO_EMIT = "com.eddieowens.GEOFENCE_DATA_TO_EMIT"; 38 | 39 | private GeofencingClient mGeofencingClient; 40 | private PendingIntent mBoundaryPendingIntent; 41 | 42 | RNBoundaryModule(ReactApplicationContext reactContext) { 43 | super(reactContext); 44 | this.mGeofencingClient = LocationServices.getGeofencingClient(getReactApplicationContext()); 45 | getReactApplicationContext().addLifecycleEventListener(this); 46 | } 47 | 48 | @ReactMethod 49 | public void removeAll(final Promise promise) { 50 | mGeofencingClient.removeGeofences(getBoundaryPendingIntent()) 51 | .addOnSuccessListener(new OnSuccessListener() { 52 | @Override 53 | public void onSuccess(Void aVoid) { 54 | Log.i(TAG, "Successfully removed all geofences"); 55 | promise.resolve(null); 56 | } 57 | }) 58 | .addOnFailureListener(new OnFailureListener() { 59 | @Override 60 | public void onFailure(@NonNull Exception e) { 61 | Log.i(TAG, "Failed to remove all geofences"); 62 | promise.reject(e); 63 | } 64 | }); 65 | } 66 | 67 | @ReactMethod 68 | public void remove(final String boundaryRequestId, Promise promise) { 69 | removeGeofence(promise, Collections.singletonList(boundaryRequestId)); 70 | } 71 | 72 | @ReactMethod 73 | public void remove(final ReadableArray readableArray, Promise promise) { 74 | 75 | final List boundaryRequestIds = new ArrayList<>(); 76 | for (int i = 0; i < readableArray.size(); ++i) { 77 | boundaryRequestIds.add(readableArray.getString(i)); 78 | } 79 | 80 | removeGeofence(promise, boundaryRequestIds); 81 | } 82 | 83 | @ReactMethod 84 | public void add(final ReadableMap readableMap, final Promise promise) { 85 | final GeofencingRequest geofencingRequest = createGeofenceRequest(createGeofence(readableMap)); 86 | addGeofence(promise, geofencingRequest, geofencingRequest.getGeofences().get(0).getRequestId()); 87 | } 88 | 89 | @ReactMethod 90 | public void add(final ReadableArray readableArray, final Promise promise) { 91 | final List geofences = createGeofences(readableArray); 92 | final WritableArray geofenceRequestIds = Arguments.createArray(); 93 | for (Geofence g : geofences) { 94 | geofenceRequestIds.pushString(g.getRequestId()); 95 | } 96 | 97 | GeofencingRequest geofencingRequest = createGeofenceRequest(createGeofences(readableArray)); 98 | 99 | addGeofence(promise, geofencingRequest, geofenceRequestIds); 100 | } 101 | 102 | private Geofence createGeofence(ReadableMap readableMap) { 103 | return new Geofence.Builder() 104 | .setRequestId(readableMap.getString("id")) 105 | .setCircularRegion(readableMap.getDouble("lat"), readableMap.getDouble("lng"), (float) readableMap.getDouble("radius")) 106 | .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT) 107 | .setExpirationDuration(Geofence.NEVER_EXPIRE) 108 | .build(); 109 | } 110 | 111 | private List createGeofences(ReadableArray readableArray) { 112 | List geofences = new ArrayList<>(); 113 | for (int i = 0; i < readableArray.size(); ++i) { 114 | geofences.add(createGeofence(readableArray.getMap(i))); 115 | } 116 | return geofences; 117 | } 118 | 119 | private GeofencingRequest createGeofenceRequest(List geofences) { 120 | return new GeofencingRequest.Builder() 121 | .setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER) 122 | .addGeofences(geofences) 123 | .build(); 124 | } 125 | 126 | private GeofencingRequest createGeofenceRequest(Geofence geofence) { 127 | return new GeofencingRequest.Builder() 128 | .addGeofence(geofence) 129 | .setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER) 130 | .build(); 131 | } 132 | 133 | private PendingIntent getBoundaryPendingIntent() { 134 | if (mBoundaryPendingIntent != null) { 135 | return mBoundaryPendingIntent; 136 | } 137 | Intent intent = new Intent(getReactApplicationContext(), BoundaryEventBroadcastReceiver.class); 138 | mBoundaryPendingIntent = PendingIntent.getBroadcast(getReactApplicationContext(), 0, intent, PendingIntent. 139 | FLAG_UPDATE_CURRENT); 140 | return mBoundaryPendingIntent; 141 | } 142 | 143 | private void addGeofence(final Promise promise, final GeofencingRequest geofencingRequest, final WritableArray geofenceRequestIds) { 144 | int permission = ActivityCompat.checkSelfPermission(getReactApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION); 145 | 146 | 147 | if (permission != PackageManager.PERMISSION_GRANTED) { 148 | permission = requestPermissions(); 149 | } 150 | 151 | 152 | if (permission != PackageManager.PERMISSION_GRANTED) { 153 | promise.reject("PERM", "Access fine location is not permitted"); 154 | } else { 155 | mGeofencingClient.addGeofences( 156 | geofencingRequest, 157 | getBoundaryPendingIntent() 158 | ) 159 | .addOnSuccessListener(new OnSuccessListener() { 160 | @Override 161 | public void onSuccess(Void aVoid) { 162 | promise.resolve(geofenceRequestIds); 163 | } 164 | }) 165 | .addOnFailureListener(new OnFailureListener() { 166 | @Override 167 | public void onFailure(@NonNull Exception e) { 168 | promise.reject(e); 169 | } 170 | }); 171 | } 172 | 173 | } 174 | 175 | private void addGeofence(final Promise promise, final GeofencingRequest geofencingRequest, final String requestId) { 176 | int permission = ActivityCompat.checkSelfPermission(getReactApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION); 177 | 178 | 179 | if (permission != PackageManager.PERMISSION_GRANTED) { 180 | permission = requestPermissions(); 181 | } 182 | 183 | if (permission != PackageManager.PERMISSION_GRANTED) { 184 | promise.reject("PERM", "Access fine location is not permitted. Hello"); 185 | } else { 186 | Log.i(TAG, "Attempting to add geofence."); 187 | 188 | mGeofencingClient.addGeofences( 189 | geofencingRequest, 190 | getBoundaryPendingIntent() 191 | ) 192 | .addOnSuccessListener(new OnSuccessListener() { 193 | @Override 194 | public void onSuccess(Void aVoid) { 195 | Log.i(TAG, "Successfully added geofence."); 196 | promise.resolve(requestId); 197 | } 198 | }) 199 | .addOnFailureListener(new OnFailureListener() { 200 | @Override 201 | public void onFailure(@NonNull Exception e) { 202 | Log.i(TAG, "Failed to add geofence."); 203 | promise.reject(e); 204 | } 205 | }); 206 | } 207 | } 208 | 209 | private void removeGeofence(final Promise promise, final List requestIds) { 210 | Log.i(TAG, "Attempting to remove geofence."); 211 | mGeofencingClient.removeGeofences(requestIds) 212 | .addOnSuccessListener(new OnSuccessListener() { 213 | @Override 214 | public void onSuccess(Void aVoid) { 215 | Log.i(TAG, "Successfully removed geofence."); 216 | promise.resolve(null); 217 | } 218 | }) 219 | .addOnFailureListener(new OnFailureListener() { 220 | @Override 221 | public void onFailure(@NonNull Exception e) { 222 | Log.i(TAG, "Failed to remove geofence."); 223 | promise.reject(e); 224 | } 225 | }); 226 | } 227 | 228 | private int requestPermissions() { 229 | ActivityCompat.requestPermissions(getReactApplicationContext().getCurrentActivity(), 230 | new String[]{ 231 | Manifest.permission.ACCESS_FINE_LOCATION, 232 | Manifest.permission.ACCESS_COARSE_LOCATION 233 | }, 1); 234 | 235 | return ActivityCompat.checkSelfPermission(getReactApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION); 236 | } 237 | 238 | @Override 239 | public String getName() { 240 | return "RNBoundary"; 241 | } 242 | 243 | @Override 244 | public void onHostResume() { 245 | } 246 | 247 | @Override 248 | public void onHostPause() { 249 | } 250 | 251 | @Override 252 | public void onHostDestroy() { 253 | } 254 | } -------------------------------------------------------------------------------- /android/src/main/java/com/eddieowens/RNBoundaryPackage.java: -------------------------------------------------------------------------------- 1 | 2 | package com.eddieowens; 3 | 4 | import com.facebook.react.ReactPackage; 5 | import com.facebook.react.bridge.JavaScriptModule; 6 | import com.facebook.react.bridge.NativeModule; 7 | import com.facebook.react.bridge.ReactApplicationContext; 8 | import com.facebook.react.uimanager.ViewManager; 9 | 10 | import java.util.ArrayList; 11 | import java.util.Collections; 12 | import java.util.List; 13 | 14 | public class RNBoundaryPackage implements ReactPackage { 15 | @Override 16 | public List createNativeModules(ReactApplicationContext reactContext) { 17 | List nativeModules = new ArrayList<>(); 18 | nativeModules.add(new RNBoundaryModule(reactContext)); 19 | return nativeModules; 20 | } 21 | 22 | public List> createJSModules() { 23 | return Collections.emptyList(); 24 | } 25 | 26 | @Override 27 | public List createViewManagers(ReactApplicationContext reactContext) { 28 | return Collections.emptyList(); 29 | } 30 | } -------------------------------------------------------------------------------- /android/src/main/java/com/eddieowens/errors/GeofenceErrorMessages.java: -------------------------------------------------------------------------------- 1 | package com.eddieowens.errors; 2 | 3 | import com.google.android.gms.location.GeofenceStatusCodes; 4 | 5 | public class GeofenceErrorMessages { 6 | private GeofenceErrorMessages() {} 7 | 8 | 9 | /** 10 | * Returns the error string for a geofencing error code. 11 | */ 12 | public static String getErrorString(int errorCode) { 13 | switch (errorCode) { 14 | case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE: 15 | return "Geofence is not available"; 16 | case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: 17 | return "Too many geofences"; 18 | case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: 19 | return "Too many pending intents"; 20 | default: 21 | return "Unknown error: " + Integer.toString(errorCode); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /android/src/main/java/com/eddieowens/receivers/BoundaryEventBroadcastReceiver.java: -------------------------------------------------------------------------------- 1 | package com.eddieowens.receivers; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.support.v4.app.JobIntentService; 7 | import android.util.Log; 8 | 9 | import com.eddieowens.services.BoundaryEventJobIntentService; 10 | 11 | import static com.eddieowens.RNBoundaryModule.TAG; 12 | 13 | public class BoundaryEventBroadcastReceiver extends BroadcastReceiver { 14 | 15 | public BoundaryEventBroadcastReceiver() { 16 | } 17 | 18 | @Override 19 | public void onReceive(Context context, Intent intent) { 20 | Log.i(TAG, "Broadcasting geofence event"); 21 | JobIntentService.enqueueWork(context, BoundaryEventJobIntentService.class, 0, intent); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /android/src/main/java/com/eddieowens/services/BoundaryEventHeadlessTaskService.java: -------------------------------------------------------------------------------- 1 | package com.eddieowens.services; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | 7 | import com.facebook.react.HeadlessJsTaskService; 8 | import com.facebook.react.jstasks.HeadlessJsTaskConfig; 9 | import com.facebook.react.bridge.Arguments; 10 | 11 | public class BoundaryEventHeadlessTaskService extends HeadlessJsTaskService { 12 | @Nullable 13 | protected HeadlessJsTaskConfig getTaskConfig(Intent intent) { 14 | Bundle extras = intent.getExtras(); 15 | return new HeadlessJsTaskConfig( 16 | "OnBoundaryEvent", 17 | extras != null ? Arguments.fromBundle(extras) : null, 18 | 5000, 19 | true); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /android/src/main/java/com/eddieowens/services/BoundaryEventJobIntentService.java: -------------------------------------------------------------------------------- 1 | package com.eddieowens.services; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.annotation.NonNull; 7 | import android.support.v4.app.JobIntentService; 8 | import android.util.Log; 9 | 10 | import com.eddieowens.RNBoundaryModule; 11 | import com.eddieowens.errors.GeofenceErrorMessages; 12 | import com.facebook.react.HeadlessJsTaskService; 13 | import com.google.android.gms.location.Geofence; 14 | import com.google.android.gms.location.GeofencingEvent; 15 | 16 | import java.util.ArrayList; 17 | 18 | import static com.eddieowens.RNBoundaryModule.TAG; 19 | 20 | public class BoundaryEventJobIntentService extends JobIntentService { 21 | 22 | public static final String ON_ENTER = "onEnter"; 23 | public static final String ON_EXIT = "onExit"; 24 | 25 | public BoundaryEventJobIntentService() { 26 | super(); 27 | } 28 | 29 | @Override 30 | protected void onHandleWork(@NonNull Intent intent) { 31 | Log.i(TAG, "Handling geofencing event"); 32 | GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); 33 | 34 | Log.i(TAG, "Geofence transition: " + geofencingEvent.getGeofenceTransition()); 35 | if (geofencingEvent.hasError()) { 36 | Log.e(TAG, "Error in handling geofence " + GeofenceErrorMessages.getErrorString(geofencingEvent.getErrorCode())); 37 | return; 38 | } 39 | switch (geofencingEvent.getGeofenceTransition()) { 40 | case Geofence.GEOFENCE_TRANSITION_ENTER: 41 | Log.i(TAG, "Enter geofence event detected. Sending event."); 42 | final ArrayList enteredGeofences = new ArrayList<>(); 43 | for (Geofence geofence : geofencingEvent.getTriggeringGeofences()) { 44 | enteredGeofences.add(geofence.getRequestId()); 45 | } 46 | sendEvent(this.getApplicationContext(), ON_ENTER, enteredGeofences); 47 | break; 48 | case Geofence.GEOFENCE_TRANSITION_EXIT: 49 | Log.i(TAG, "Exit geofence event detected. Sending event."); 50 | final ArrayList exitingGeofences = new ArrayList<>(); 51 | for (Geofence geofence : geofencingEvent.getTriggeringGeofences()) { 52 | exitingGeofences.add(geofence.getRequestId()); 53 | } 54 | sendEvent(this.getApplicationContext(), ON_EXIT, exitingGeofences); 55 | break; 56 | } 57 | } 58 | 59 | private void sendEvent(Context context, String event, ArrayList params) { 60 | final Intent intent = new Intent(RNBoundaryModule.GEOFENCE_DATA_TO_EMIT); 61 | intent.putExtra("event", event); 62 | intent.putExtra("params", params); 63 | 64 | Bundle bundle = new Bundle(); 65 | bundle.putString("event", event); 66 | bundle.putStringArrayList("ids", intent.getStringArrayListExtra("params")); 67 | 68 | Intent headlessBoundaryIntent = new Intent(context, BoundaryEventHeadlessTaskService.class); 69 | headlessBoundaryIntent.putExtras(bundle); 70 | 71 | context.startService(headlessBoundaryIntent); 72 | HeadlessJsTaskService.acquireWakeLockNow(context); 73 | } 74 | } -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import {NativeEventEmitter, NativeModules, AppRegistry} from 'react-native'; 2 | 3 | const {RNBoundary} = NativeModules; 4 | 5 | const TAG = "RNBoundary"; 6 | 7 | const boundaryEventEmitter = new NativeEventEmitter(RNBoundary); 8 | 9 | const Events = { 10 | EXIT: "onExit", 11 | ENTER: "onEnter", 12 | }; 13 | 14 | export { 15 | Events 16 | } 17 | 18 | const HeadlessBoundaryEventTask = async ({event, ids}) => { 19 | console.log(event, ids); 20 | boundaryEventEmitter.emit(event, ids) 21 | }; 22 | 23 | AppRegistry.registerHeadlessTask('OnBoundaryEvent', () => HeadlessBoundaryEventTask); 24 | 25 | export default { 26 | add: boundary => { 27 | if (!boundary || (boundary.constructor !== Array && typeof boundary !== 'object')) { 28 | throw TAG + ': a boundary must be an array or non-null object'; 29 | } 30 | return new Promise((resolve, reject) => { 31 | if (typeof boundary === 'object' && !boundary.id) { 32 | reject(TAG + ': an id is required') 33 | } 34 | 35 | RNBoundary.add(boundary) 36 | .then(id => resolve(id)) 37 | .catch(e => reject(e)) 38 | }) 39 | }, 40 | 41 | on: (event, callback) => { 42 | if (typeof callback !== 'function') { 43 | throw TAG + ': callback function must be provided'; 44 | } 45 | if (!Object.values(Events).find(e => e === event)) { 46 | throw TAG + ': invalid event'; 47 | } 48 | 49 | return boundaryEventEmitter.addListener(event, callback); 50 | }, 51 | 52 | off: (event) => { 53 | if (!Object.values(Events).find(e => e === event)) { 54 | throw TAG + ': invalid event'; 55 | } 56 | 57 | return boundaryEventEmitter.removeAllListeners(event); 58 | }, 59 | 60 | removeAll: () => { 61 | return RNBoundary.removeAll(); 62 | }, 63 | 64 | remove: id => { 65 | if (!id || (id.constructor !== Array && typeof id !== 'string')) { 66 | throw TAG + ': id must be a string'; 67 | } 68 | 69 | return RNBoundary.remove(id); 70 | } 71 | } 72 | 73 | -------------------------------------------------------------------------------- /ios/RNBoundary.h: -------------------------------------------------------------------------------- 1 | 2 | #if __has_include() 3 | #import 4 | #else 5 | #import "RCTBridgeModule.h" 6 | #endif 7 | #import 8 | #import 9 | #import 10 | 11 | @interface RNBoundary : RCTEventEmitter 12 | - (bool) removeBoundary:(NSString *)boundaryId; 13 | - (void) removeAllBoundaries; 14 | @property (strong, nonatomic) CLLocationManager *locationManager; 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /ios/RNBoundary.m: -------------------------------------------------------------------------------- 1 | 2 | #import "RNBoundary.h" 3 | 4 | @implementation RNBoundary 5 | 6 | RCT_EXPORT_MODULE() 7 | 8 | -(instancetype)init 9 | { 10 | self = [super init]; 11 | if (self) { 12 | self.locationManager = [[CLLocationManager alloc] init]; 13 | self.locationManager.delegate = self; 14 | } 15 | 16 | return self; 17 | } 18 | 19 | RCT_EXPORT_METHOD(add:(NSDictionary*)boundary addWithResolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 20 | { 21 | if (CLLocationManager.authorizationStatus != kCLAuthorizationStatusAuthorizedAlways) { 22 | [self.locationManager requestAlwaysAuthorization]; 23 | } 24 | 25 | if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways) { 26 | NSString *id = boundary[@"id"]; 27 | CLLocationCoordinate2D center = CLLocationCoordinate2DMake([boundary[@"lat"] doubleValue], [boundary[@"lng"] doubleValue]); 28 | CLRegion *boundaryRegion = [[CLCircularRegion alloc]initWithCenter:center 29 | radius:[boundary[@"radius"] doubleValue] 30 | identifier:id]; 31 | 32 | [self.locationManager startMonitoringForRegion:boundaryRegion]; 33 | 34 | resolve(id); 35 | } else { 36 | reject(@"PERM", @"Access fine location is not permitted", [NSError errorWithDomain:@"boundary" code:200 userInfo:@{@"Error reason": @"Invalid permissions"}]); 37 | } 38 | } 39 | 40 | RCT_EXPORT_METHOD(remove:(NSString *)boundaryId removeWithResolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 41 | { 42 | if ([self removeBoundary:boundaryId]) { 43 | resolve(boundaryId); 44 | } else { 45 | reject(@"@no_boundary", @"No boundary with the provided id was found", [NSError errorWithDomain:@"boundary" code:200 userInfo:@{@"Error reason": @"Invalid boundary ID"}]); 46 | } 47 | } 48 | 49 | RCT_EXPORT_METHOD(removeAll:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 50 | { 51 | @try { 52 | [self removeAllBoundaries]; 53 | } 54 | @catch (NSError *ex) { 55 | reject(@"failed_remove_all", @"Failed to remove all boundaries", ex); 56 | } 57 | resolve(NULL); 58 | } 59 | 60 | - (void) removeAllBoundaries 61 | { 62 | for(CLRegion *region in [self.locationManager monitoredRegions]) { 63 | [self.locationManager stopMonitoringForRegion:region]; 64 | } 65 | } 66 | 67 | - (bool) removeBoundary:(NSString *)boundaryId 68 | { 69 | for(CLRegion *region in [self.locationManager monitoredRegions]){ 70 | if ([region.identifier isEqualToString:boundaryId]) { 71 | [self.locationManager stopMonitoringForRegion:region]; 72 | return true; 73 | } 74 | } 75 | return false; 76 | } 77 | 78 | - (NSArray *)supportedEvents 79 | { 80 | return @[@"onEnter", @"onExit"]; 81 | } 82 | 83 | - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region 84 | { 85 | NSLog(@"didEnter : %@", region); 86 | [self sendEventWithName:@"onEnter" body:region.identifier]; 87 | } 88 | 89 | - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region 90 | { 91 | NSLog(@"didExit : %@", region); 92 | [self sendEventWithName:@"onExit" body:region.identifier]; 93 | } 94 | 95 | + (BOOL)requiresMainQueueSetup 96 | { 97 | return YES; 98 | } 99 | 100 | @end 101 | 102 | -------------------------------------------------------------------------------- /ios/RNBoundary.podspec: -------------------------------------------------------------------------------- 1 | 2 | Pod::Spec.new do |s| 3 | s.name = "RNBoundary" 4 | s.version = "1.0.0" 5 | s.summary = "RNBoundary" 6 | s.description = <<-DESC 7 | RNBoundary 8 | DESC 9 | s.homepage = "" 10 | s.license = "MIT" 11 | # s.license = { :type => "MIT", :file => "FILE_LICENSE" } 12 | s.author = { "author" => "author@domain.cn" } 13 | s.platform = :ios, "7.0" 14 | s.source = { :git => "https://github.com/author/RNBoundary.git", :tag => "master" } 15 | s.source_files = "RNBoundary/**/*.{h,m}" 16 | s.requires_arc = true 17 | 18 | 19 | s.dependency "React" 20 | #s.dependency "others" 21 | 22 | end 23 | 24 | -------------------------------------------------------------------------------- /ios/RNBoundary.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F51BA0232117F52C00036CE6 /* RNBoundary.m in Sources */ = {isa = PBXBuildFile; fileRef = F51BA0212117F52C00036CE6 /* RNBoundary.m */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXCopyFilesBuildPhase section */ 14 | 58B511D91A9E6C8500147676 /* CopyFiles */ = { 15 | isa = PBXCopyFilesBuildPhase; 16 | buildActionMask = 2147483647; 17 | dstPath = "include/$(PRODUCT_NAME)"; 18 | dstSubfolderSpec = 16; 19 | files = ( 20 | ); 21 | runOnlyForDeploymentPostprocessing = 0; 22 | }; 23 | /* End PBXCopyFilesBuildPhase section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | 134814201AA4EA6300B7C361 /* libRNBoundary.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNBoundary.a; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | F51BA0212117F52C00036CE6 /* RNBoundary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNBoundary.m; sourceTree = ""; }; 28 | F51BA0222117F52C00036CE6 /* RNBoundary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNBoundary.h; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 58B511D81A9E6C8500147676 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 134814211AA4EA7D00B7C361 /* Products */ = { 43 | isa = PBXGroup; 44 | children = ( 45 | 134814201AA4EA6300B7C361 /* libRNBoundary.a */, 46 | ); 47 | name = Products; 48 | sourceTree = ""; 49 | }; 50 | 58B511D21A9E6C8500147676 = { 51 | isa = PBXGroup; 52 | children = ( 53 | F51BA0222117F52C00036CE6 /* RNBoundary.h */, 54 | F51BA0212117F52C00036CE6 /* RNBoundary.m */, 55 | 134814211AA4EA7D00B7C361 /* Products */, 56 | ); 57 | sourceTree = ""; 58 | }; 59 | /* End PBXGroup section */ 60 | 61 | /* Begin PBXNativeTarget section */ 62 | 58B511DA1A9E6C8500147676 /* RNBoundary */ = { 63 | isa = PBXNativeTarget; 64 | buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNBoundary" */; 65 | buildPhases = ( 66 | 58B511D71A9E6C8500147676 /* Sources */, 67 | 58B511D81A9E6C8500147676 /* Frameworks */, 68 | 58B511D91A9E6C8500147676 /* CopyFiles */, 69 | ); 70 | buildRules = ( 71 | ); 72 | dependencies = ( 73 | ); 74 | name = RNBoundary; 75 | productName = RCTDataManager; 76 | productReference = 134814201AA4EA6300B7C361 /* libRNBoundary.a */; 77 | productType = "com.apple.product-type.library.static"; 78 | }; 79 | /* End PBXNativeTarget section */ 80 | 81 | /* Begin PBXProject section */ 82 | 58B511D31A9E6C8500147676 /* Project object */ = { 83 | isa = PBXProject; 84 | attributes = { 85 | LastUpgradeCheck = 1010; 86 | ORGANIZATIONNAME = Facebook; 87 | TargetAttributes = { 88 | 58B511DA1A9E6C8500147676 = { 89 | CreatedOnToolsVersion = 6.1.1; 90 | LastSwiftMigration = 0940; 91 | }; 92 | }; 93 | }; 94 | buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNBoundary" */; 95 | compatibilityVersion = "Xcode 3.2"; 96 | developmentRegion = English; 97 | hasScannedForEncodings = 0; 98 | knownRegions = ( 99 | en, 100 | ); 101 | mainGroup = 58B511D21A9E6C8500147676; 102 | productRefGroup = 58B511D21A9E6C8500147676; 103 | projectDirPath = ""; 104 | projectRoot = ""; 105 | targets = ( 106 | 58B511DA1A9E6C8500147676 /* RNBoundary */, 107 | ); 108 | }; 109 | /* End PBXProject section */ 110 | 111 | /* Begin PBXSourcesBuildPhase section */ 112 | 58B511D71A9E6C8500147676 /* Sources */ = { 113 | isa = PBXSourcesBuildPhase; 114 | buildActionMask = 2147483647; 115 | files = ( 116 | F51BA0232117F52C00036CE6 /* RNBoundary.m in Sources */, 117 | ); 118 | runOnlyForDeploymentPostprocessing = 0; 119 | }; 120 | /* End PBXSourcesBuildPhase section */ 121 | 122 | /* Begin XCBuildConfiguration section */ 123 | 58B511ED1A9E6C8500147676 /* Debug */ = { 124 | isa = XCBuildConfiguration; 125 | buildSettings = { 126 | ALWAYS_SEARCH_USER_PATHS = NO; 127 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 128 | CLANG_CXX_LIBRARY = "libc++"; 129 | CLANG_ENABLE_MODULES = YES; 130 | CLANG_ENABLE_OBJC_ARC = YES; 131 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 132 | CLANG_WARN_BOOL_CONVERSION = YES; 133 | CLANG_WARN_COMMA = YES; 134 | CLANG_WARN_CONSTANT_CONVERSION = YES; 135 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 136 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 137 | CLANG_WARN_EMPTY_BODY = YES; 138 | CLANG_WARN_ENUM_CONVERSION = YES; 139 | CLANG_WARN_INFINITE_RECURSION = YES; 140 | CLANG_WARN_INT_CONVERSION = YES; 141 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 142 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 143 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 144 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 145 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 146 | CLANG_WARN_STRICT_PROTOTYPES = YES; 147 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 148 | CLANG_WARN_UNREACHABLE_CODE = YES; 149 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 150 | COPY_PHASE_STRIP = NO; 151 | ENABLE_STRICT_OBJC_MSGSEND = YES; 152 | ENABLE_TESTABILITY = YES; 153 | GCC_C_LANGUAGE_STANDARD = gnu99; 154 | GCC_DYNAMIC_NO_PIC = NO; 155 | GCC_NO_COMMON_BLOCKS = YES; 156 | GCC_OPTIMIZATION_LEVEL = 0; 157 | GCC_PREPROCESSOR_DEFINITIONS = ( 158 | "DEBUG=1", 159 | "$(inherited)", 160 | ); 161 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 162 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 163 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 164 | GCC_WARN_UNDECLARED_SELECTOR = YES; 165 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 166 | GCC_WARN_UNUSED_FUNCTION = YES; 167 | GCC_WARN_UNUSED_VARIABLE = YES; 168 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 169 | MTL_ENABLE_DEBUG_INFO = YES; 170 | ONLY_ACTIVE_ARCH = YES; 171 | SDKROOT = iphoneos; 172 | }; 173 | name = Debug; 174 | }; 175 | 58B511EE1A9E6C8500147676 /* Release */ = { 176 | isa = XCBuildConfiguration; 177 | buildSettings = { 178 | ALWAYS_SEARCH_USER_PATHS = NO; 179 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 180 | CLANG_CXX_LIBRARY = "libc++"; 181 | CLANG_ENABLE_MODULES = YES; 182 | CLANG_ENABLE_OBJC_ARC = YES; 183 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 184 | CLANG_WARN_BOOL_CONVERSION = YES; 185 | CLANG_WARN_COMMA = YES; 186 | CLANG_WARN_CONSTANT_CONVERSION = YES; 187 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 188 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 189 | CLANG_WARN_EMPTY_BODY = YES; 190 | CLANG_WARN_ENUM_CONVERSION = YES; 191 | CLANG_WARN_INFINITE_RECURSION = YES; 192 | CLANG_WARN_INT_CONVERSION = YES; 193 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 194 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 195 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 196 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 197 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 198 | CLANG_WARN_STRICT_PROTOTYPES = YES; 199 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 200 | CLANG_WARN_UNREACHABLE_CODE = YES; 201 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 202 | COPY_PHASE_STRIP = YES; 203 | ENABLE_NS_ASSERTIONS = NO; 204 | ENABLE_STRICT_OBJC_MSGSEND = YES; 205 | GCC_C_LANGUAGE_STANDARD = gnu99; 206 | GCC_NO_COMMON_BLOCKS = YES; 207 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 208 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 209 | GCC_WARN_UNDECLARED_SELECTOR = YES; 210 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 211 | GCC_WARN_UNUSED_FUNCTION = YES; 212 | GCC_WARN_UNUSED_VARIABLE = YES; 213 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 214 | MTL_ENABLE_DEBUG_INFO = NO; 215 | SDKROOT = iphoneos; 216 | VALIDATE_PRODUCT = YES; 217 | }; 218 | name = Release; 219 | }; 220 | 58B511F01A9E6C8500147676 /* Debug */ = { 221 | isa = XCBuildConfiguration; 222 | buildSettings = { 223 | CLANG_ENABLE_MODULES = YES; 224 | HEADER_SEARCH_PATHS = ( 225 | "$(inherited)", 226 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 227 | "$(SRCROOT)/../../../React/**", 228 | "$(SRCROOT)/../../react-native/React/**", 229 | ); 230 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 231 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 232 | OTHER_LDFLAGS = "-ObjC"; 233 | PRODUCT_NAME = RNBoundary; 234 | SKIP_INSTALL = YES; 235 | SWIFT_OBJC_BRIDGING_HEADER = "RNBoundary-Bridging-Header.h"; 236 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 237 | SWIFT_VERSION = 3.0; 238 | }; 239 | name = Debug; 240 | }; 241 | 58B511F11A9E6C8500147676 /* Release */ = { 242 | isa = XCBuildConfiguration; 243 | buildSettings = { 244 | CLANG_ENABLE_MODULES = YES; 245 | HEADER_SEARCH_PATHS = ( 246 | "$(inherited)", 247 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 248 | "$(SRCROOT)/../../../React/**", 249 | "$(SRCROOT)/../../react-native/React/**", 250 | ); 251 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 252 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 253 | OTHER_LDFLAGS = "-ObjC"; 254 | PRODUCT_NAME = RNBoundary; 255 | SKIP_INSTALL = YES; 256 | SWIFT_OBJC_BRIDGING_HEADER = "RNBoundary-Bridging-Header.h"; 257 | SWIFT_VERSION = 3.0; 258 | }; 259 | name = Release; 260 | }; 261 | /* End XCBuildConfiguration section */ 262 | 263 | /* Begin XCConfigurationList section */ 264 | 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNBoundary" */ = { 265 | isa = XCConfigurationList; 266 | buildConfigurations = ( 267 | 58B511ED1A9E6C8500147676 /* Debug */, 268 | 58B511EE1A9E6C8500147676 /* Release */, 269 | ); 270 | defaultConfigurationIsVisible = 0; 271 | defaultConfigurationName = Release; 272 | }; 273 | 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNBoundary" */ = { 274 | isa = XCConfigurationList; 275 | buildConfigurations = ( 276 | 58B511F01A9E6C8500147676 /* Debug */, 277 | 58B511F11A9E6C8500147676 /* Release */, 278 | ); 279 | defaultConfigurationIsVisible = 0; 280 | defaultConfigurationName = Release; 281 | }; 282 | /* End XCConfigurationList section */ 283 | }; 284 | rootObject = 58B511D31A9E6C8500147676 /* Project object */; 285 | } 286 | -------------------------------------------------------------------------------- /ios/RNBoundary.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | 3 | 5 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-boundary", 3 | "version": "1.1.1", 4 | "description": "native geofencing and region monitoring", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/eddieowens/react-native-boundary.git" 12 | }, 13 | "typings": "typings/index.d.ts", 14 | "keywords": [ 15 | "react-native", 16 | "geofence", 17 | "boundary", 18 | "ios", 19 | "android", 20 | "location", 21 | "region monitoring" 22 | ], 23 | "author": "Edward Owens", 24 | "license": "Apache-2.0", 25 | "peerDependencies": { 26 | "react-native": ">0.49.0" 27 | }, 28 | "devDependencies": { 29 | "@types/react-native": "^0.57.60" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /typings/index.d.ts: -------------------------------------------------------------------------------- 1 | import {EmitterSubscription} from 'react-native'; 2 | 3 | export enum Events { 4 | EXIT = 'onExit', 5 | ENTER = 'onEnter', 6 | } 7 | 8 | export interface Boundary { 9 | id: string; 10 | lat: number; 11 | lng: number; 12 | radius: number; 13 | } 14 | 15 | export interface BoundaryStatic { 16 | on: (event: Events, callback: (boundaries: string[]) => void) => EmitterSubscription; 17 | off: (event: Events) => void; 18 | add: (boundary: Boundary) => Promise; 19 | remove: (id: string) => Promise; 20 | removeAll: () => Promise; 21 | } 22 | 23 | declare let Boundary: BoundaryStatic; 24 | export default Boundary; 25 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | "@types/prop-types@*": 6 | version "15.7.1" 7 | resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.1.tgz#f1a11e7babb0c3cad68100be381d1e064c68f1f6" 8 | integrity sha512-CFzn9idOEpHrgdw8JsoTkaDDyRWk1jrzIV8djzcgpq0y9tG4B4lFT+Nxh52DVpDXV+n4+NPNv7M1Dj5uMp6XFg== 9 | 10 | "@types/react-native@^0.57.60": 11 | version "0.57.60" 12 | resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.57.60.tgz#61e97a84e2f64ed971e7d238bb30cec188898235" 13 | integrity sha512-zObrnRsCbpM7qDm97d8+5qiSIMMYRaWgpqu6orjbjzLUAcJaKnpBMXgW6bRXWkFBjHgm3hjDAdVVGMWlrYJBdw== 14 | dependencies: 15 | "@types/prop-types" "*" 16 | "@types/react" "*" 17 | 18 | "@types/react@*": 19 | version "16.8.19" 20 | resolved "https://registry.yarnpkg.com/@types/react/-/react-16.8.19.tgz#629154ef05e2e1985cdde94477deefd823ad9be3" 21 | integrity sha512-QzEzjrd1zFzY9cDlbIiFvdr+YUmefuuRYrPxmkwG0UQv5XF35gFIi7a95m1bNVcFU0VimxSZ5QVGSiBmlggQXQ== 22 | dependencies: 23 | "@types/prop-types" "*" 24 | csstype "^2.2.0" 25 | 26 | csstype@^2.2.0: 27 | version "2.6.5" 28 | resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.5.tgz#1cd1dff742ebf4d7c991470ae71e12bb6751e034" 29 | integrity sha512-JsTaiksRsel5n7XwqPAfB0l3TFKdpjW/kgAELf9vrb5adGA7UCPLajKK5s3nFrcFm3Rkyp/Qkgl73ENc1UY3cA== 30 | --------------------------------------------------------------------------------