├── .buckconfig ├── .eslintrc.js ├── .flowconfig ├── .gitignore ├── .prettierrc.js ├── .watchmanconfig ├── README.md ├── android ├── .idea │ ├── .name │ ├── codeStyles │ │ └── Project.xml │ ├── misc.xml │ └── runConfigurations.xml ├── .project ├── .settings │ └── org.eclipse.buildship.core.prefs ├── app │ ├── .classpath │ ├── .project │ ├── .settings │ │ └── org.eclipse.buildship.core.prefs │ ├── _BUCK │ ├── agconnect-services.json │ ├── build.gradle │ ├── build_defs.bzl │ ├── debug.keystore │ ├── proguard-rules.pro │ └── src │ │ ├── debug │ │ └── AndroidManifest.xml │ │ ├── gms │ │ └── java │ │ │ └── com │ │ │ └── testrnhms │ │ │ └── ToastExample.java │ │ ├── hms │ │ └── java │ │ │ └── com │ │ │ └── testrnhms │ │ │ └── ToastExample.java │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── assets │ │ └── appcenter-config.json │ │ ├── java │ │ ├── com │ │ │ └── testrnhms │ │ │ │ ├── MainActivity.java │ │ │ │ ├── MainApplication.java │ │ │ │ └── utils │ │ │ │ └── JsonUtils.java │ │ └── rnhms │ │ │ ├── Constants.java │ │ │ ├── RNHMSPackage.java │ │ │ ├── account │ │ │ └── RNHMSLogin.java │ │ │ ├── analytics │ │ │ └── RNHMSAnalytics.java │ │ │ └── push │ │ │ ├── HmsPushService.java │ │ │ └── RNHMSPush.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 ├── commitlint.config.js ├── index.js ├── metro.config.js ├── package-lock.json ├── package.json └── src ├── App.js ├── components └── LoadingSpinner │ ├── LoadingSpinner.js │ ├── index.js │ └── style.js ├── containers └── SignInContainer │ ├── SignInContainer.js │ ├── index.js │ └── style.js ├── context └── UserContext.js └── pages ├── ProfilePage ├── ProfilePage.js ├── index.js └── style.js └── SignInPage ├── SignInPage.js ├── index.js └── style.js /.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: '@react-native-community', 4 | }; 5 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore polyfills 9 | node_modules/react-native/Libraries/polyfills/.* 10 | 11 | ; These should not be required directly 12 | ; require from fbjs/lib instead: require('fbjs/lib/warning') 13 | node_modules/warning/.* 14 | 15 | ; Flow doesn't support platforms 16 | .*/Libraries/Utilities/LoadingView.js 17 | 18 | [untyped] 19 | .*/node_modules/@react-native-community/cli/.*/.* 20 | 21 | [include] 22 | 23 | [libs] 24 | node_modules/react-native/Libraries/react-native/react-native-interface.js 25 | node_modules/react-native/flow/ 26 | 27 | [options] 28 | emoji=true 29 | 30 | esproposal.optional_chaining=enable 31 | esproposal.nullish_coalescing=enable 32 | 33 | module.file_ext=.js 34 | module.file_ext=.json 35 | module.file_ext=.ios.js 36 | 37 | munge_underscores=true 38 | 39 | module.name_mapper='^react-native$' -> '/node_modules/react-native/Libraries/react-native/react-native-implementation' 40 | module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react-native/\1' 41 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' 42 | 43 | suppress_type=$FlowIssue 44 | suppress_type=$FlowFixMe 45 | suppress_type=$FlowFixMeProps 46 | suppress_type=$FlowFixMeState 47 | 48 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\) 49 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+ 50 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 51 | 52 | [lints] 53 | sketchy-null-number=warn 54 | sketchy-null-mixed=warn 55 | sketchy-number=warn 56 | untyped-type-import=warn 57 | nonstrict-import=warn 58 | deprecated-type=warn 59 | unsafe-getters-setters=warn 60 | inexact-spread=warn 61 | unnecessary-invariant=warn 62 | signature-verification-failure=warn 63 | deprecated-utility=error 64 | 65 | [strict] 66 | deprecated-type 67 | nonstrict-import 68 | sketchy-null 69 | unclear-type 70 | unsafe-getters-setters 71 | untyped-import 72 | untyped-type-import 73 | 74 | [version] 75 | ^0.105.0 76 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/node,code,reactnative 3 | # Edit at https://www.gitignore.io/?templates=node,code,reactnative 4 | 5 | ### Code ### 6 | .vscode/* 7 | !.vscode/settings.json 8 | !.vscode/tasks.json 9 | !.vscode/launch.json 10 | !.vscode/extensions.json 11 | 12 | ### Node ### 13 | # Logs 14 | logs 15 | *.log 16 | npm-debug.log* 17 | yarn-debug.log* 18 | yarn-error.log* 19 | lerna-debug.log* 20 | 21 | # Diagnostic reports (https://nodejs.org/api/report.html) 22 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 23 | 24 | # Runtime data 25 | pids 26 | *.pid 27 | *.seed 28 | *.pid.lock 29 | 30 | # Directory for instrumented libs generated by jscoverage/JSCover 31 | lib-cov 32 | 33 | # Coverage directory used by tools like istanbul 34 | coverage 35 | *.lcov 36 | 37 | # nyc test coverage 38 | .nyc_output 39 | 40 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 41 | .grunt 42 | 43 | # Bower dependency directory (https://bower.io/) 44 | bower_components 45 | 46 | # node-waf configuration 47 | .lock-wscript 48 | 49 | # Compiled binary addons (https://nodejs.org/api/addons.html) 50 | build/Release 51 | 52 | # Dependency directories 53 | node_modules/ 54 | jspm_packages/ 55 | 56 | # TypeScript v1 declaration files 57 | typings/ 58 | 59 | # TypeScript cache 60 | *.tsbuildinfo 61 | 62 | # Optional npm cache directory 63 | .npm 64 | 65 | # Optional eslint cache 66 | .eslintcache 67 | 68 | # Optional REPL history 69 | .node_repl_history 70 | 71 | # Output of 'npm pack' 72 | *.tgz 73 | 74 | # Yarn Integrity file 75 | .yarn-integrity 76 | 77 | # dotenv environment variables file 78 | .env 79 | .env.test 80 | 81 | # parcel-bundler cache (https://parceljs.org/) 82 | .cache 83 | 84 | # next.js build output 85 | .next 86 | 87 | # nuxt.js build output 88 | .nuxt 89 | 90 | # rollup.js default build output 91 | dist/ 92 | 93 | # Uncomment the public line if your project uses Gatsby 94 | # https://nextjs.org/blog/next-9-1#public-directory-support 95 | # https://create-react-app.dev/docs/using-the-public-folder/#docsNav 96 | # public 97 | 98 | # Storybook build outputs 99 | .out 100 | .storybook-out 101 | 102 | # vuepress build output 103 | .vuepress/dist 104 | 105 | # Serverless directories 106 | .serverless/ 107 | 108 | # FuseBox cache 109 | .fusebox/ 110 | 111 | # DynamoDB Local files 112 | .dynamodb/ 113 | 114 | # Temporary folders 115 | tmp/ 116 | temp/ 117 | 118 | ### ReactNative ### 119 | # React Native Stack Base 120 | 121 | .expo 122 | __generated__ 123 | 124 | ### ReactNative.Xcode Stack ### 125 | # Xcode 126 | # 127 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 128 | 129 | ## User settings 130 | xcuserdata/ 131 | 132 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 133 | *.xcscmblueprint 134 | *.xccheckout 135 | 136 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 137 | build/ 138 | DerivedData/ 139 | *.moved-aside 140 | *.pbxuser 141 | !default.pbxuser 142 | *.mode1v3 143 | !default.mode1v3 144 | *.mode2v3 145 | !default.mode2v3 146 | *.perspectivev3 147 | !default.perspectivev3 148 | 149 | ## Xcode Patch 150 | *.xcodeproj/* 151 | !*.xcodeproj/project.pbxproj 152 | !*.xcodeproj/xcshareddata/ 153 | !*.xcworkspace/contents.xcworkspacedata 154 | /*.gcno 155 | 156 | ### ReactNative.Android Stack ### 157 | # Built application files 158 | *.apk 159 | *.ap_ 160 | *.aab 161 | 162 | # Files for the ART/Dalvik VM 163 | *.dex 164 | 165 | # Java class files 166 | *.class 167 | 168 | # Generated files 169 | bin/ 170 | gen/ 171 | out/ 172 | release/ 173 | 174 | # Gradle files 175 | .gradle/ 176 | 177 | # Local configuration file (sdk path, etc) 178 | local.properties 179 | 180 | # Proguard folder generated by Eclipse 181 | proguard/ 182 | 183 | # Log Files 184 | 185 | # Android Studio Navigation editor temp files 186 | android/navigation/ 187 | 188 | # Android Studio captures folder 189 | android/captures/ 190 | 191 | # IntelliJ 192 | *.iml 193 | android/.idea/workspace.xml 194 | idea/tasks.xml 195 | android/.idea/gradle.xml 196 | android/.idea/assetWizardSettings.xml 197 | android/.idea/dictionaries 198 | android/.idea/libraries 199 | # Android Studio 3 in .gitignore file. 200 | android/.idea/caches 201 | android/.idea/modules.xml 202 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 203 | android/.idea/navEditor.xml 204 | 205 | # Keystore files 206 | # Uncomment the following lines if you do not want to check your keystore files in. 207 | #*.jks 208 | #*.keystore 209 | 210 | # External native build folder generated in Android Studio 2.2 and later 211 | android/.externalNativeBuild 212 | .externalNativeBuild 213 | 214 | # Google Services (e.g. APIs or Firebase) 215 | # google-services.json 216 | 217 | # Freeline 218 | freeline.py 219 | freeline/ 220 | freeline_project_description.json 221 | 222 | # fastlane 223 | fastlane/report.xml 224 | fastlane/Preview.html 225 | fastlane/screenshots 226 | fastlane/test_output 227 | fastlane/readme.md 228 | 229 | # Version control 230 | vcs.xml 231 | 232 | # lint 233 | lint/intermediates/ 234 | lint/generated/ 235 | lint/outputs/ 236 | lint/tmp/ 237 | # lint/reports/ 238 | 239 | ### ReactNative.macOS Stack ### 240 | # General 241 | .DS_Store 242 | .AppleDouble 243 | .LSOverride 244 | 245 | # Icon must end with two \r 246 | Icon 247 | 248 | 249 | # Thumbnails 250 | ._* 251 | 252 | # Files that might appear in the root of a volume 253 | .DocumentRevisions-V100 254 | .fseventsd 255 | .Spotlight-V100 256 | .TemporaryItems 257 | .Trashes 258 | .VolumeIcon.icns 259 | .com.apple.timemachine.donotpresent 260 | 261 | # Directories potentially created on remote AFP share 262 | .AppleDB 263 | .AppleDesktop 264 | Network Trash Folder 265 | Temporary Items 266 | .apdisk 267 | 268 | ### ReactNative.Gradle Stack ### 269 | .gradle 270 | 271 | # Ignore Gradle GUI config 272 | gradle-app.setting 273 | 274 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 275 | !gradle-wrapper.jar 276 | 277 | # Cache of project 278 | .gradletasknamecache 279 | 280 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 281 | # gradle/wrapper/gradle-wrapper.properties 282 | 283 | ### ReactNative.Linux Stack ### 284 | *~ 285 | 286 | # temporary files which can be created if a process still has a handle open of a deleted file 287 | .fuse_hidden* 288 | 289 | # KDE directory preferences 290 | .directory 291 | 292 | # Linux trash folder which might appear on any partition or disk 293 | .Trash-* 294 | 295 | # .nfs files are created when an open file is removed but is still being accessed 296 | .nfs* 297 | 298 | ### ReactNative.Node Stack ### 299 | # Logs 300 | 301 | # Diagnostic reports (https://nodejs.org/api/report.html) 302 | 303 | # Runtime data 304 | 305 | # Directory for instrumented libs generated by jscoverage/JSCover 306 | 307 | # Coverage directory used by tools like istanbul 308 | 309 | # nyc test coverage 310 | 311 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 312 | 313 | # Bower dependency directory (https://bower.io/) 314 | 315 | # node-waf configuration 316 | 317 | # Compiled binary addons (https://nodejs.org/api/addons.html) 318 | 319 | # Dependency directories 320 | 321 | # TypeScript v1 declaration files 322 | 323 | # TypeScript cache 324 | 325 | # Optional npm cache directory 326 | 327 | # Optional eslint cache 328 | 329 | # Optional REPL history 330 | 331 | # Output of 'npm pack' 332 | 333 | # Yarn Integrity file 334 | 335 | # dotenv environment variables file 336 | 337 | # parcel-bundler cache (https://parceljs.org/) 338 | 339 | # next.js build output 340 | 341 | # nuxt.js build output 342 | 343 | # rollup.js default build output 344 | 345 | # Uncomment the public line if your project uses Gatsby 346 | # https://nextjs.org/blog/next-9-1#public-directory-support 347 | # https://create-react-app.dev/docs/using-the-public-folder/#docsNav 348 | # public 349 | 350 | # Storybook build outputs 351 | 352 | # vuepress build output 353 | 354 | # Serverless directories 355 | 356 | # FuseBox cache 357 | 358 | # DynamoDB Local files 359 | 360 | # Temporary folders 361 | 362 | ### ReactNative.Buck Stack ### 363 | buck-out/ 364 | .buckconfig.local 365 | .buckd/ 366 | .buckversion 367 | .fakebuckversion 368 | 369 | # End of https://www.gitignore.io/api/node,code,reactnative -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | bracketSpacing: false, 3 | jsxBracketSameLine: true, 4 | singleQuote: true, 5 | trailingComma: 'all', 6 | }; 7 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Native & HMS Sample 2 | 3 | This simple repo implements Account Kit, Push Kit and Analytics Kit of HMS ecosystem and aims to be playground for integration of other kits. 4 | 5 | 6 | ## Installing dependencies 7 | 8 | ```sh 9 | npm install 10 | ``` 11 | If you are having issues, you can follow [getting started.](https://facebook.github.io/react-native/docs/getting-started.html) 12 | 13 | 14 | ## Running the application 15 | 16 | ```sh 17 | cd reactnative-hms-bridge 18 | npx react-native run-android --variant=HmsDebug 19 | ``` 20 | For other variants, check productFlavors in `app/build.gradle` 21 | 22 | ## Contributing 23 | 24 | Commit messages must comply with [conventional commits](https://www.conventionalcommits.org). Otherwise [commitlint](https://github.com/conventional-changelog/commitlint) will complain. :) 25 | 26 | Thanks to [commitizen](https://github.com/commitizen), `npm run commit` command can be used to create commit messages complying with conventional commits. 27 | -------------------------------------------------------------------------------- /android/.idea/.name: -------------------------------------------------------------------------------- 1 | TestRnHMS -------------------------------------------------------------------------------- /android/.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | xmlns:android 14 | 15 | ^$ 16 | 17 | 18 | 19 |
20 |
21 | 22 | 23 | 24 | xmlns:.* 25 | 26 | ^$ 27 | 28 | 29 | BY_NAME 30 | 31 |
32 |
33 | 34 | 35 | 36 | .*:id 37 | 38 | http://schemas.android.com/apk/res/android 39 | 40 | 41 | 42 |
43 |
44 | 45 | 46 | 47 | .*:name 48 | 49 | http://schemas.android.com/apk/res/android 50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | 58 | name 59 | 60 | ^$ 61 | 62 | 63 | 64 |
65 |
66 | 67 | 68 | 69 | style 70 | 71 | ^$ 72 | 73 | 74 | 75 |
76 |
77 | 78 | 79 | 80 | .* 81 | 82 | ^$ 83 | 84 | 85 | BY_NAME 86 | 87 |
88 |
89 | 90 | 91 | 92 | .* 93 | 94 | http://schemas.android.com/apk/res/android 95 | 96 | 97 | ANDROID_ATTRIBUTE_ORDER 98 | 99 |
100 |
101 | 102 | 103 | 104 | .* 105 | 106 | .* 107 | 108 | 109 | BY_NAME 110 | 111 |
112 |
113 |
114 |
115 |
116 |
-------------------------------------------------------------------------------- /android/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /android/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /android/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | TestRnHMS 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 | connection.project.dir= 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /android/app/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /android/app/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | app 4 | Project app created by Buildship. 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.buildship.core.gradleprojectbuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.buildship.core.gradleprojectnature 22 | 23 | 24 | -------------------------------------------------------------------------------- /android/app/.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | connection.project.dir=.. 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /android/app/_BUCK: -------------------------------------------------------------------------------- 1 | # To learn about Buck see [Docs](https://buckbuild.com/). 2 | # To run your application with Buck: 3 | # - install Buck 4 | # - `npm start` - to start the packager 5 | # - `cd android` 6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` 7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 8 | # - `buck install -r android/app` - compile, install and run application 9 | # 10 | 11 | load(":build_defs.bzl", "create_aar_targets", "create_jar_targets") 12 | 13 | lib_deps = [] 14 | 15 | create_aar_targets(glob(["libs/*.aar"])) 16 | 17 | create_jar_targets(glob(["libs/*.jar"])) 18 | 19 | android_library( 20 | name = "all-libs", 21 | exported_deps = lib_deps, 22 | ) 23 | 24 | android_library( 25 | name = "app-code", 26 | srcs = glob([ 27 | "src/main/java/**/*.java", 28 | ]), 29 | deps = [ 30 | ":all-libs", 31 | ":build_config", 32 | ":res", 33 | ], 34 | ) 35 | 36 | android_build_config( 37 | name = "build_config", 38 | package = "com.testrnhms", 39 | ) 40 | 41 | android_resource( 42 | name = "res", 43 | package = "com.testrnhms", 44 | res = "src/main/res", 45 | ) 46 | 47 | android_binary( 48 | name = "app", 49 | keystore = "//android/keystores:debug", 50 | manifest = "src/main/AndroidManifest.xml", 51 | package_type = "debug", 52 | deps = [ 53 | ":app-code", 54 | ], 55 | ) 56 | -------------------------------------------------------------------------------- /android/app/agconnect-services.json: -------------------------------------------------------------------------------- 1 | { 2 | "agcgw":{ 3 | "backurl":"connect-dre.dbankcloud.cn", 4 | "url":"connect-dre.hispace.hicloud.com" 5 | }, 6 | "client":{ 7 | "cp_id":"890090000023105690", 8 | "product_id":"9105385871708438146", 9 | "client_id":"280530015160894592", 10 | "client_secret":"8E1275904E814428A45E7895C5C89BC268901D1B2E0D7B3DC6F0EDA27D7788AD", 11 | "app_id":"101672909", 12 | "package_name":"com.testrnhms", 13 | "api_key":"CV5QEoUcJz5L4K2pXtkv6xTOR7CxMtmjN439BLmsgOkikm6Y9R30aZMWhK9X+fTuS8Cu6Kpt0iWgypOMtmTR4v/ZXPkG" 14 | }, 15 | "service":{ 16 | "analytics":{ 17 | "collector_url":"datacollector-dre.dt.hicloud.com,datacollector-dre.dt.dbankcloud.cn", 18 | "resource_id":"p1", 19 | "channel_id":"" 20 | }, 21 | "ml":{ 22 | "mlservice_url":"ml-api-dre.ai.dbankcloud.com,ml-api-dre.ai.dbankcloud.cn" 23 | } 24 | }, 25 | "region":"DE", 26 | "configuration_version":"1.0" 27 | } -------------------------------------------------------------------------------- /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 example: 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 example, 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 | entryFile: "index.js", 80 | enableHermes: false, // clean and rebuild if changing 81 | ] 82 | 83 | apply from: "../../node_modules/react-native/react.gradle" 84 | 85 | /** 86 | * Set this to true to create two separate APKs instead of one: 87 | * - An APK that only works on ARM devices 88 | * - An APK that only works on x86 devices 89 | * The advantage is the size of the APK is reduced by about 4MB. 90 | * Upload all the APKs to the Play Store and people will download 91 | * the correct one based on the CPU architecture of their device. 92 | */ 93 | def enableSeparateBuildPerCPUArchitecture = false 94 | 95 | /** 96 | * Run Proguard to shrink the Java bytecode in release builds. 97 | */ 98 | def enableProguardInReleaseBuilds = false 99 | 100 | /** 101 | * The preferred build flavor of JavaScriptCore. 102 | * 103 | * For example, to use the international variant, you can use: 104 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` 105 | * 106 | * The international variant includes ICU i18n library and necessary data 107 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that 108 | * give correct results when using with locales other than en-US. Note that 109 | * this variant is about 6MiB larger per architecture than default. 110 | */ 111 | def jscFlavor = 'org.webkit:android-jsc:+' 112 | 113 | /** 114 | * Whether to enable the Hermes VM. 115 | * 116 | * This should be set on project.ext.react and mirrored here. If it is not set 117 | * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode 118 | * and the benefits of using Hermes will therefore be sharply reduced. 119 | */ 120 | def enableHermes = project.ext.react.get("enableHermes", false); 121 | 122 | android { 123 | compileSdkVersion rootProject.ext.compileSdkVersion 124 | 125 | compileOptions { 126 | sourceCompatibility JavaVersion.VERSION_1_8 127 | targetCompatibility JavaVersion.VERSION_1_8 128 | } 129 | 130 | defaultConfig { 131 | applicationId "com.testrnhms" 132 | minSdkVersion rootProject.ext.minSdkVersion 133 | targetSdkVersion rootProject.ext.targetSdkVersion 134 | versionCode 1 135 | versionName "1.0" 136 | } 137 | splits { 138 | abi { 139 | reset() 140 | enable enableSeparateBuildPerCPUArchitecture 141 | universalApk false // If true, also generate a universal APK 142 | include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" 143 | } 144 | } 145 | signingConfigs { 146 | debug { 147 | storeFile file('debug.keystore') 148 | storePassword 'android' 149 | keyAlias 'androiddebugkey' 150 | keyPassword 'android' 151 | } 152 | } 153 | buildTypes { 154 | debug { 155 | signingConfig signingConfigs.debug 156 | } 157 | release { 158 | // Caution! In production, you need to generate your own keystore file. 159 | // see https://facebook.github.io/react-native/docs/signed-apk-android. 160 | signingConfig signingConfigs.debug 161 | minifyEnabled enableProguardInReleaseBuilds 162 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 163 | } 164 | } 165 | // applicationVariants are e.g. debug, release 166 | applicationVariants.all { variant -> 167 | variant.outputs.each { output -> 168 | // For each separate APK per architecture, set a unique version code as described here: 169 | // https://developer.android.com/studio/build/configure-apk-splits.html 170 | def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] 171 | def abi = output.getFilter(OutputFile.ABI) 172 | if (abi != null) { // null for the universal-debug, universal-release variants 173 | output.versionCodeOverride = 174 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode 175 | } 176 | 177 | } 178 | } 179 | 180 | flavorDimensions "version" 181 | productFlavors{ 182 | gms{ 183 | dimension "version" 184 | } 185 | hms{ 186 | dimension "version" 187 | } 188 | } 189 | } 190 | 191 | dependencies { 192 | implementation fileTree(dir: "libs", include: ["*.jar"]) 193 | implementation "com.facebook.react:react-native:+" // From node_modules 194 | 195 | // HMS Kits 196 | implementation 'com.huawei.hms:hwid:3.0.3.301' 197 | implementation 'com.huawei.hms:push:3.0.3.301' 198 | implementation 'com.huawei.hms:hianalytics:4.0.0.303' 199 | 200 | 201 | 202 | if (enableHermes) { 203 | def hermesPath = "../../node_modules/hermes-engine/android/"; 204 | debugImplementation files(hermesPath + "hermes-debug.aar") 205 | releaseImplementation files(hermesPath + "hermes-release.aar") 206 | } else { 207 | implementation jscFlavor 208 | } 209 | } 210 | 211 | // Run this once to be able to run the application with BUCK 212 | // puts all compile dependencies into folder libs for BUCK to use 213 | task copyDownloadableDepsToLibs(type: Copy) { 214 | from configurations.compile 215 | into 'libs' 216 | } 217 | apply plugin: 'com.huawei.agconnect' 218 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) 219 | -------------------------------------------------------------------------------- /android/app/build_defs.bzl: -------------------------------------------------------------------------------- 1 | """Helper definitions to glob .aar and .jar targets""" 2 | 3 | def create_aar_targets(aarfiles): 4 | for aarfile in aarfiles: 5 | name = "aars__" + aarfile[aarfile.rindex("/") + 1:aarfile.rindex(".aar")] 6 | lib_deps.append(":" + name) 7 | android_prebuilt_aar( 8 | name = name, 9 | aar = aarfile, 10 | ) 11 | 12 | def create_jar_targets(jarfiles): 13 | for jarfile in jarfiles: 14 | name = "jars__" + jarfile[jarfile.rindex("/") + 1:jarfile.rindex(".jar")] 15 | lib_deps.append(":" + name) 16 | prebuilt_jar( 17 | name = name, 18 | binary_jar = jarfile, 19 | ) 20 | -------------------------------------------------------------------------------- /android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/reactnative-hms-bridge/28f1d07aec2222da93e14bffb9591472ec124484/android/app/debug.keystore -------------------------------------------------------------------------------- /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 | -ignorewarning 12 | -keepattributes *Annotation* 13 | -keepattributes Exceptions 14 | -keepattributes InnerClasses 15 | -keepattributes Signature 16 | -keepattributes SourceFile,LineNumberTable 17 | -keep class com.hianalytics.android.**{*;} 18 | -keep class com.huawei.updatesdk.**{*;} 19 | -keep class com.huawei.hms.**{*;} 20 | -keep interface com.huawei.hms.analytics.type.HAEventType{*;} 21 | -keep interface com.huawei.hms.analytics.type.HAParamType{*;} 22 | -keep class com.huawei.hms.analytics.HiAnalyticsTools{ 23 | public static void enableLog(); 24 | public static void enableLog(int); 25 | } 26 | -keep class com.huawei.hms.analytics.HiAnalyticsInstance{*;} 27 | -keep class com.huawei.hms.analytics.HiAnalytics{*;} -------------------------------------------------------------------------------- /android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android/app/src/gms/java/com/testrnhms/ToastExample.java: -------------------------------------------------------------------------------- 1 | package com.testrnhms; 2 | 3 | import android.widget.Toast; 4 | 5 | import com.facebook.react.bridge.NativeModule; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.react.bridge.ReactContext; 8 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 9 | import com.facebook.react.bridge.ReactMethod; 10 | 11 | import java.util.Map; 12 | import java.util.HashMap; 13 | 14 | public class ToastExample extends ReactContextBaseJavaModule { 15 | 16 | public ToastExample(ReactApplicationContext reactContext) { 17 | super(reactContext); 18 | } 19 | 20 | @Override 21 | public String getName() { 22 | return "ToastComponent"; 23 | } 24 | 25 | @ReactMethod 26 | public void toastMe() { 27 | Toast.makeText(getReactApplicationContext(), "gms", Toast.LENGTH_SHORT).show(); 28 | } 29 | } -------------------------------------------------------------------------------- /android/app/src/hms/java/com/testrnhms/ToastExample.java: -------------------------------------------------------------------------------- 1 | package com.testrnhms; 2 | 3 | import android.widget.Toast; 4 | 5 | import com.facebook.react.bridge.NativeModule; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.react.bridge.ReactContext; 8 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 9 | import com.facebook.react.bridge.ReactMethod; 10 | 11 | import java.util.Map; 12 | import java.util.HashMap; 13 | 14 | public class ToastExample extends ReactContextBaseJavaModule { 15 | 16 | public ToastExample(ReactApplicationContext reactContext) { 17 | super(reactContext); 18 | } 19 | 20 | @Override 21 | public String getName() { 22 | return "ToastComponent"; 23 | } 24 | 25 | @ReactMethod 26 | public void toastMe() { 27 | Toast.makeText(getReactApplicationContext(), "hms", Toast.LENGTH_SHORT).show(); 28 | } 29 | } -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 16 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 33 | 34 | 35 | 36 | 37 | 38 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /android/app/src/main/assets/appcenter-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "app_secret": "9bb45d11-50a7-4efb-9685-79cbef287948" 3 | } -------------------------------------------------------------------------------- /android/app/src/main/java/com/testrnhms/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.testrnhms; 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 "TestRnHMS"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /android/app/src/main/java/com/testrnhms/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.testrnhms; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.util.Log; 6 | 7 | import com.facebook.react.PackageList; 8 | import com.facebook.react.ReactApplication; 9 | import com.facebook.react.ReactNativeHost; 10 | import com.facebook.react.ReactPackage; 11 | import com.facebook.soloader.SoLoader; 12 | import com.huawei.hianalytics.hms.HiAnalyticsTools; 13 | import com.huawei.hms.analytics.HiAnalytics; 14 | import com.huawei.hms.analytics.HiAnalyticsInstance; 15 | 16 | import java.lang.reflect.InvocationTargetException; 17 | import java.util.List; 18 | 19 | import rnhms.RNHMSPackage; 20 | 21 | public class MainApplication extends Application implements ReactApplication { 22 | 23 | HiAnalyticsInstance instance; 24 | 25 | private final ReactNativeHost mReactNativeHost = 26 | new ReactNativeHost(this) { 27 | @Override 28 | public boolean getUseDeveloperSupport() { 29 | return BuildConfig.DEBUG; 30 | } 31 | 32 | @Override 33 | protected List getPackages() { 34 | @SuppressWarnings("UnnecessaryLocalVariable") 35 | List packages = new PackageList(this).getPackages(); 36 | // Packages that cannot be autolinked yet can be added manually here, for example: 37 | // packages.add(new MyReactNativePackage()); 38 | packages.add(new RNHMSPackage()); 39 | return packages; 40 | } 41 | 42 | @Override 43 | protected String getJSMainModuleName() { 44 | return "index"; 45 | } 46 | }; 47 | 48 | @Override 49 | public ReactNativeHost getReactNativeHost() { 50 | return mReactNativeHost; 51 | } 52 | 53 | @Override 54 | public void onCreate() { 55 | super.onCreate(); 56 | SoLoader.init(this, /* native exopackage */ false); 57 | // initializeFlipper(this); // Remove this line if you don't want Flipper enabled 58 | 59 | HiAnalyticsTools.enableLog(); 60 | 61 | instance = HiAnalytics.getInstance(this); 62 | 63 | Log.i("MainApplication",instance.toString()); 64 | 65 | // TODO: can be configurable 66 | instance.setAnalyticsEnabled(true); 67 | // TODO: can be configurable 68 | instance.setAutoCollectionEnabled(true); 69 | 70 | } 71 | 72 | /** 73 | * Loads Flipper in React Native templates. 74 | * 75 | * @param context 76 | */ 77 | private static void initializeFlipper(Context context) { 78 | if (BuildConfig.DEBUG) { 79 | try { 80 | /* 81 | We use reflection here to pick up the class that initializes Flipper, 82 | since Flipper library is not available in release mode 83 | */ 84 | Class aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper"); 85 | aClass.getMethod("initializeFlipper", Context.class).invoke(null, context); 86 | } catch (ClassNotFoundException e) { 87 | e.printStackTrace(); 88 | } catch (NoSuchMethodException e) { 89 | e.printStackTrace(); 90 | } catch (IllegalAccessException e) { 91 | e.printStackTrace(); 92 | } catch (InvocationTargetException e) { 93 | e.printStackTrace(); 94 | } 95 | } 96 | } 97 | 98 | 99 | } 100 | -------------------------------------------------------------------------------- /android/app/src/main/java/com/testrnhms/utils/JsonUtils.java: -------------------------------------------------------------------------------- 1 | package com.testrnhms.utils; 2 | 3 | import android.os.Bundle; 4 | 5 | import org.json.JSONException; 6 | import org.json.JSONObject; 7 | 8 | import java.util.Iterator; 9 | 10 | public class JsonUtils { 11 | 12 | public static Bundle jsonStringToBundle(String jsonString) { 13 | try { 14 | JSONObject jsonObject = toJsonObject(jsonString); 15 | return jsonToBundle(jsonObject); 16 | } catch (JSONException ignored) { 17 | 18 | } 19 | return null; 20 | } 21 | 22 | public static JSONObject toJsonObject(String jsonString) throws JSONException { 23 | return new JSONObject(jsonString); 24 | } 25 | 26 | public static Bundle jsonToBundle(JSONObject jsonObject) throws JSONException { 27 | Bundle bundle = new Bundle(); 28 | Iterator iter = jsonObject.keys(); 29 | while (iter.hasNext()) { 30 | String key = (String) iter.next(); 31 | String value = jsonObject.getString(key); 32 | bundle.putString(key, value); 33 | } 34 | return bundle; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /android/app/src/main/java/rnhms/Constants.java: -------------------------------------------------------------------------------- 1 | package rnhms; 2 | 3 | public interface Constants { 4 | static final Integer REQUEST_SIGN_IN_LOGIN = 1; 5 | static final Integer REQUEST_SIGN_IN_LOGOUT = 2; 6 | static final String ACCOUNT_TAG = "HMS Login: --------"; 7 | static final String PUSH_TAG = "HMS Push: --------"; 8 | static final String ANALYTICS_TAG = "HMS Analytics: --------"; 9 | } -------------------------------------------------------------------------------- /android/app/src/main/java/rnhms/RNHMSPackage.java: -------------------------------------------------------------------------------- 1 | package rnhms; 2 | 3 | import com.facebook.react.ReactPackage; 4 | import com.facebook.react.bridge.NativeModule; 5 | import com.facebook.react.bridge.ReactApplicationContext; 6 | import com.facebook.react.uimanager.ViewManager; 7 | import com.testrnhms.ToastExample; 8 | 9 | import java.util.ArrayList; 10 | import java.util.Collections; 11 | import java.util.List; 12 | 13 | import rnhms.account.RNHMSLogin; 14 | import rnhms.analytics.RNHMSAnalytics; 15 | import rnhms.push.RNHMSPush; 16 | 17 | public class RNHMSPackage implements ReactPackage { 18 | 19 | @Override 20 | public List createNativeModules(ReactApplicationContext reactContext) { 21 | List modules = new ArrayList<>(); 22 | modules.add(new RNHMSLogin(reactContext)); 23 | modules.add(new RNHMSPush(reactContext)); 24 | modules.add(new ToastExample(reactContext)); 25 | modules.add(new RNHMSAnalytics(reactContext)); 26 | return modules; 27 | } 28 | 29 | @Override 30 | public List createViewManagers(ReactApplicationContext reactContext) { 31 | return Collections.emptyList(); 32 | } 33 | } -------------------------------------------------------------------------------- /android/app/src/main/java/rnhms/account/RNHMSLogin.java: -------------------------------------------------------------------------------- 1 | package rnhms.account; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.util.Log; 6 | import android.widget.Toast; 7 | 8 | import com.facebook.react.bridge.ActivityEventListener; 9 | import com.facebook.react.bridge.BaseActivityEventListener; 10 | import com.facebook.react.bridge.Promise; 11 | import com.facebook.react.bridge.ReactApplicationContext; 12 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 13 | import com.facebook.react.bridge.ReactMethod; 14 | import com.facebook.react.bridge.Arguments; 15 | import com.facebook.react.bridge.WritableMap; 16 | 17 | import com.huawei.hmf.tasks.Task; 18 | import com.huawei.hms.auth.api.signin.HuaweiIdSignIn; 19 | import com.huawei.hms.auth.api.signin.HuaweiIdSignInClient; 20 | import com.huawei.hms.common.ApiException; 21 | import com.huawei.hms.support.api.hwid.HuaweiIdSignInOptions; 22 | import com.huawei.hms.support.api.hwid.SignInHuaweiId; 23 | 24 | import org.json.JSONException; 25 | 26 | import rnhms.Constants; 27 | 28 | public class RNHMSLogin extends ReactContextBaseJavaModule { 29 | private ReactApplicationContext mContext; 30 | private Promise mPromise; 31 | private Activity activity; 32 | private HuaweiIdSignInClient mSignInClient; 33 | 34 | public RNHMSLogin(ReactApplicationContext reactContext) { 35 | super(reactContext); 36 | this.mContext = reactContext; 37 | this.mContext.addActivityEventListener(mActivityEventListener); 38 | } 39 | 40 | @Override 41 | public String getName() { 42 | return "HMSLogin"; 43 | } 44 | 45 | private final ActivityEventListener mActivityEventListener = new BaseActivityEventListener() { 46 | 47 | @Override 48 | public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { 49 | 50 | Task signInHuaweiIdTask = HuaweiIdSignIn.getSignedInAccountFromIntent(data); 51 | 52 | if (mPromise != null && requestCode == Constants.REQUEST_SIGN_IN_LOGIN) { 53 | //login success 54 | //get user message by getSignedInAccountFromIntent 55 | if (signInHuaweiIdTask.isSuccessful()) { 56 | SignInHuaweiId huaweiAccount = signInHuaweiIdTask.getResult(); 57 | 58 | WritableMap map = Arguments.createMap(); 59 | map.putString("displayName", huaweiAccount.getDisplayName()); 60 | map.putString("idToken", huaweiAccount.getIdToken()); 61 | map.putString("email", huaweiAccount.getEmail()); 62 | map.putString("countryCode", huaweiAccount.getCountryCode()); 63 | map.putString("photoUriString", huaweiAccount.getPhotoUriString()); 64 | 65 | try { 66 | map.putString("allData", huaweiAccount.toJson()); 67 | } catch (JSONException e) { 68 | e.printStackTrace(); 69 | } 70 | mPromise.resolve(map); 71 | Log.i(Constants.ACCOUNT_TAG, "signIn success " + huaweiAccount.getDisplayName()); 72 | } else { 73 | Log.i(Constants.ACCOUNT_TAG, "signIn failed: " 74 | + ((ApiException) signInHuaweiIdTask.getException()).getStatusCode()); 75 | } 76 | } 77 | } 78 | }; 79 | 80 | // To export a method for JavaScript use, Java methods need to use the @reactmethod annotation 81 | @ReactMethod 82 | public void Login(Promise promise) { 83 | this.mPromise = promise; 84 | 85 | this.activity = getCurrentActivity(); 86 | 87 | HuaweiIdSignInOptions mSignInOptions = new HuaweiIdSignInOptions 88 | .Builder(HuaweiIdSignInOptions.DEFAULT_SIGN_IN).requestIdToken("").build(); 89 | 90 | this.mSignInClient = HuaweiIdSignIn.getClient(this.activity, mSignInOptions); 91 | 92 | mSignInClient.revokeAccess(); 93 | 94 | if(this.checkActivity(this.activity, promise)){ 95 | try { 96 | this.activity.startActivityForResult(this.mSignInClient.getSignInIntent(), Constants.REQUEST_SIGN_IN_LOGIN, null); 97 | } catch (Exception e) { 98 | promise.reject("START_ACTIVITY_ERROR", "START_ACTIVITY_ERROR"); 99 | promise = null; 100 | } 101 | } 102 | } 103 | 104 | @ReactMethod 105 | public void Logout() { 106 | if(this.checkActivity(this.activity, null)){ 107 | this.mSignInClient.signOut(); 108 | Toast.makeText(getReactApplicationContext(), "Your HMS Account has log out~~", Toast.LENGTH_LONG).show(); 109 | } 110 | } 111 | 112 | private boolean checkActivity(Activity activity, Promise promise) { 113 | if (activity == null && promise != null) { 114 | promise.reject("E_ACTIVITY_DOES_NOT_EXIST", "Activity doesn't exist"); 115 | } 116 | return activity != null; 117 | } 118 | 119 | } -------------------------------------------------------------------------------- /android/app/src/main/java/rnhms/analytics/RNHMSAnalytics.java: -------------------------------------------------------------------------------- 1 | package rnhms.analytics; 2 | 3 | import android.os.Bundle; 4 | import android.util.Log; 5 | import android.widget.Toast; 6 | 7 | import com.facebook.react.bridge.ReactApplicationContext; 8 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 9 | import com.facebook.react.bridge.ReactMethod; 10 | import com.huawei.hianalytics.hms.HiAnalyticsTools; 11 | import com.huawei.hms.analytics.HiAnalytics; 12 | import com.huawei.hms.analytics.HiAnalyticsInstance; 13 | import com.testrnhms.utils.JsonUtils; 14 | 15 | import rnhms.Constants; 16 | 17 | public class RNHMSAnalytics extends ReactContextBaseJavaModule { 18 | 19 | private HiAnalyticsInstance instance; 20 | 21 | public RNHMSAnalytics(ReactApplicationContext reactContext) { 22 | super(reactContext); 23 | HiAnalyticsTools.enableLog(); 24 | 25 | instance = HiAnalytics.getInstance(reactContext); 26 | 27 | Log.i(Constants.ANALYTICS_TAG, instance.toString()); 28 | } 29 | 30 | @Override 31 | public String getName() { 32 | return "HMSAnalytics"; 33 | } 34 | 35 | @ReactMethod 36 | public void sendEvent(String eventName, String bundleString) { 37 | Bundle bundle = JsonUtils.jsonStringToBundle(bundleString); 38 | 39 | Log.i(Constants.ANALYTICS_TAG, "eventName: " + eventName); 40 | Log.i(Constants.ANALYTICS_TAG, "bundle: " + bundleString); 41 | 42 | Toast.makeText(getReactApplicationContext(), 43 | "eventName: " + eventName + " bundle: " + bundleString, Toast.LENGTH_SHORT) 44 | .show(); 45 | 46 | instance.onEvent(eventName, bundle); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /android/app/src/main/java/rnhms/push/HmsPushService.java: -------------------------------------------------------------------------------- 1 | package rnhms.push; 2 | 3 | import android.util.Log; 4 | import android.widget.Toast; 5 | 6 | import com.huawei.hms.push.HmsMessageService; 7 | import com.huawei.hms.push.RemoteMessage; 8 | 9 | import rnhms.Constants; 10 | 11 | public class HmsPushService extends HmsMessageService { 12 | @Override 13 | public void onNewToken(String s) { 14 | super.onNewToken(s); 15 | Log.i(Constants.PUSH_TAG, "receive token:" + s); 16 | Toast.makeText(getApplicationContext(), "receive token:" + s, Toast.LENGTH_SHORT).show(); 17 | } 18 | 19 | @Override 20 | public void onMessageReceived(RemoteMessage remoteMessage) { 21 | super.onMessageReceived(remoteMessage); 22 | 23 | if (remoteMessage.getData(). length() > 0) { 24 | Log.i(Constants.PUSH_TAG, "Message data payload: " + remoteMessage.getData()); 25 | } 26 | if (remoteMessage.getNotification() != null) { 27 | Log.i(Constants.PUSH_TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); 28 | } 29 | } 30 | 31 | @Override 32 | public void onMessageSent(String s) { 33 | } 34 | 35 | @Override 36 | public void onSendError(String s, Exception e) { 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /android/app/src/main/java/rnhms/push/RNHMSPush.java: -------------------------------------------------------------------------------- 1 | package rnhms.push; 2 | 3 | import android.app.Activity; 4 | import android.text.TextUtils; 5 | import android.util.Log; 6 | import android.widget.Toast; 7 | 8 | import com.facebook.react.bridge.ReactApplicationContext; 9 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 10 | import com.facebook.react.bridge.ReactMethod; 11 | import com.huawei.agconnect.config.AGConnectServicesConfig; 12 | import com.huawei.hms.aaid.HmsInstanceId; 13 | 14 | import rnhms.Constants; 15 | 16 | public class RNHMSPush extends ReactContextBaseJavaModule { 17 | private Activity activity; 18 | private String pushtoken; 19 | 20 | public RNHMSPush(ReactApplicationContext reactContext) { 21 | super(reactContext); 22 | } 23 | 24 | @Override 25 | public String getName() { 26 | return "HMSPush"; 27 | } 28 | 29 | @ReactMethod 30 | public void getToken() { 31 | Log.i(Constants.PUSH_TAG, "get token: begin"); 32 | this.activity = getCurrentActivity(); 33 | 34 | // get token 35 | new Thread() { 36 | @Override 37 | public void run() { 38 | try { 39 | String appId = AGConnectServicesConfig.fromContext(activity).getString("client/app_id"); 40 | Log.i(Constants.PUSH_TAG, "appId: " + appId); 41 | pushtoken = HmsInstanceId.getInstance(activity).getToken(appId, "HCM"); 42 | Log.i(Constants.PUSH_TAG, "thread token: " + pushtoken); 43 | 44 | if(!TextUtils.isEmpty(pushtoken)) { 45 | Toast.makeText(getReactApplicationContext(), "get token:" + pushtoken, Toast.LENGTH_SHORT).show(); 46 | Log.i(Constants.PUSH_TAG, "get token:" + pushtoken); 47 | } 48 | } catch (Exception e) { 49 | Log.i(Constants.PUSH_TAG,"getToken failed, " + e); 50 | 51 | } 52 | } 53 | }.start(); 54 | } 55 | } -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/reactnative-hms-bridge/28f1d07aec2222da93e14bffb9591472ec124484/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/reactnative-hms-bridge/28f1d07aec2222da93e14bffb9591472ec124484/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/reactnative-hms-bridge/28f1d07aec2222da93e14bffb9591472ec124484/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/reactnative-hms-bridge/28f1d07aec2222da93e14bffb9591472ec124484/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/reactnative-hms-bridge/28f1d07aec2222da93e14bffb9591472ec124484/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/reactnative-hms-bridge/28f1d07aec2222da93e14bffb9591472ec124484/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/reactnative-hms-bridge/28f1d07aec2222da93e14bffb9591472ec124484/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/reactnative-hms-bridge/28f1d07aec2222da93e14bffb9591472ec124484/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/reactnative-hms-bridge/28f1d07aec2222da93e14bffb9591472ec124484/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/reactnative-hms-bridge/28f1d07aec2222da93e14bffb9591472ec124484/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | TestRnHMS 3 | DO_NOT_ASK_JAVASCRIPT 4 | ALWAYS_SEND 5 | 6 | -------------------------------------------------------------------------------- /android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /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 = 17 7 | compileSdkVersion = 28 8 | targetSdkVersion = 28 9 | } 10 | repositories { 11 | google() 12 | jcenter() 13 | maven {url 'http://developer.huawei.com/repo/'} 14 | } 15 | dependencies { 16 | classpath("com.android.tools.build:gradle:3.4.2") 17 | classpath 'com.huawei.agconnect:agcp:1.1.1.300' 18 | 19 | // NOTE: Do not place your application dependencies here; they belong 20 | // in the individual module build.gradle files 21 | } 22 | } 23 | 24 | allprojects { 25 | repositories { 26 | mavenLocal() 27 | maven { 28 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 29 | url("$rootDir/../node_modules/react-native/android") 30 | } 31 | maven { 32 | // Android JSC is installed from npm 33 | url("$rootDir/../node_modules/jsc-android/dist") 34 | } 35 | 36 | google() 37 | jcenter() 38 | maven { url 'https://jitpack.io' } 39 | maven { url 'http://developer.huawei.com/repo/' } 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/reactnative-hms-bridge/28f1d07aec2222da93e14bffb9591472ec124484/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /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 ; 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'TestRnHMS' 2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) 3 | include ':app' 4 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TestRnHMS", 3 | "displayName": "TestRnHMS" 4 | } -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@commitlint/config-conventional'] 3 | }; 4 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | */ 4 | 5 | import { AppRegistry } from 'react-native'; 6 | import App from './src/App'; 7 | import { name as appName } from './app.json'; 8 | 9 | AppRegistry.registerComponent(appName, () => App); 10 | -------------------------------------------------------------------------------- /metro.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Metro configuration for React Native 3 | * https://github.com/facebook/react-native 4 | * 5 | * @format 6 | */ 7 | 8 | module.exports = { 9 | transformer: { 10 | getTransformOptions: async () => ({ 11 | transform: { 12 | experimentalImportSupport: false, 13 | inlineRequires: false, 14 | }, 15 | }), 16 | }, 17 | }; 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TestRnHMS", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "android": "react-native run-android", 7 | "ios": "react-native run-ios", 8 | "start": "react-native start", 9 | "test": "jest", 10 | "lint": "eslint .", 11 | "commit": "git-cz" 12 | }, 13 | "dependencies": { 14 | "appcenter": "2.6.1", 15 | "appcenter-analytics": "2.6.1", 16 | "appcenter-crashes": "2.6.1", 17 | "react": "16.9.0", 18 | "react-native": "0.61.5" 19 | }, 20 | "devDependencies": { 21 | "@babel/core": "^7.6.2", 22 | "@babel/runtime": "^7.6.2", 23 | "@commitlint/cli": "^8.3.5", 24 | "@commitlint/config-conventional": "^8.3.4", 25 | "@react-native-community/eslint-config": "^0.0.5", 26 | "babel-jest": "^24.9.0", 27 | "cz-conventional-changelog": "^3.0.2", 28 | "eslint": "^6.5.1", 29 | "husky": "^4.2.0", 30 | "jest": "^24.9.0", 31 | "metro-react-native-babel-preset": "^0.56.0", 32 | "react-test-renderer": "16.9.0" 33 | }, 34 | "jest": { 35 | "preset": "react-native" 36 | }, 37 | "husky": { 38 | "hooks": { 39 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" 40 | } 41 | }, 42 | "config": { 43 | "commitizen": { 44 | "path": "./node_modules/cz-conventional-changelog" 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | import { UserContext } from './context/UserContext'; 4 | import SignInContainer from './containers/SignInContainer'; 5 | 6 | const App = () => { 7 | return ( 8 | 9 | 10 | 11 | ); 12 | }; 13 | 14 | export default App; 15 | -------------------------------------------------------------------------------- /src/components/LoadingSpinner/LoadingSpinner.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const LoadingSpinner = ({ isLoading }) => { 4 | return ( 5 | isLoading ? : null 6 | ); 7 | }; 8 | 9 | export default LoadingSpinner; 10 | -------------------------------------------------------------------------------- /src/components/LoadingSpinner/index.js: -------------------------------------------------------------------------------- 1 | import LoadingSpinner from './LoadingSpinner'; 2 | 3 | export default LoadingSpinner; 4 | -------------------------------------------------------------------------------- /src/components/LoadingSpinner/style.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/reactnative-hms-bridge/28f1d07aec2222da93e14bffb9591472ec124484/src/components/LoadingSpinner/style.js -------------------------------------------------------------------------------- /src/containers/SignInContainer/SignInContainer.js: -------------------------------------------------------------------------------- 1 | import React, { useMemo } from 'react'; 2 | 3 | import { useUser } from '../../context/UserContext'; 4 | import SignInPage from '../../pages/SignInPage'; 5 | import ProfilePage from '../../pages/ProfilePage'; 6 | 7 | const SignInContainer = () => { 8 | const { isLoggedIn } = useUser(); 9 | return useMemo(() => { 10 | return ( 11 | !isLoggedIn ? : 12 | ); 13 | }); 14 | }; 15 | 16 | export default SignInContainer; -------------------------------------------------------------------------------- /src/containers/SignInContainer/index.js: -------------------------------------------------------------------------------- 1 | import SignInContainer from './SignInContainer'; 2 | 3 | export default SignInContainer; 4 | -------------------------------------------------------------------------------- /src/containers/SignInContainer/style.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onurkenis/reactnative-hms-bridge/28f1d07aec2222da93e14bffb9591472ec124484/src/containers/SignInContainer/style.js -------------------------------------------------------------------------------- /src/context/UserContext.js: -------------------------------------------------------------------------------- 1 | import React, { useContext, useState, useMemo } from "react"; 2 | 3 | const Login = React.createContext({ 4 | user: "", 5 | setUser: () => { }, 6 | isLoggedIn: false, 7 | logOutUser: () => { }, 8 | }); 9 | 10 | export const useUser = () => useContext(Login); 11 | 12 | export const UserContext = ({ children }) => { 13 | const [user, setUser] = useState(""); 14 | 15 | const logOutUser = () => setUser(""); 16 | 17 | const isLoggedIn = useMemo(() => { 18 | return user === "" ? false : true 19 | }, [user]); 20 | 21 | const context = { user, setUser, isLoggedIn, logOutUser } 22 | 23 | return ( 24 | {children} 25 | ); 26 | }; 27 | -------------------------------------------------------------------------------- /src/pages/ProfilePage/ProfilePage.js: -------------------------------------------------------------------------------- 1 | import React, { useMemo } from 'react'; 2 | import { Text, View } from 'react-native'; 3 | import { useUser } from '../../context/UserContext'; 4 | import styles from './style' 5 | 6 | const ProfilePage = () => { 7 | const { user } = useUser(); 8 | 9 | return useMemo(() => { 10 | return ( 11 | 12 | Welcome {user.displayName} 13 | 14 | ); 15 | }, [user]); 16 | }; 17 | 18 | export default ProfilePage; -------------------------------------------------------------------------------- /src/pages/ProfilePage/index.js: -------------------------------------------------------------------------------- 1 | import ProfilePage from './ProfilePage'; 2 | 3 | export default ProfilePage; 4 | -------------------------------------------------------------------------------- /src/pages/ProfilePage/style.js: -------------------------------------------------------------------------------- 1 | import { StyleSheet } from "react-native"; 2 | 3 | const styles = StyleSheet.create({ 4 | container: { 5 | flex: 1, 6 | justifyContent: 'center', 7 | alignItems: 'center', 8 | backgroundColor: '#DCDCDC', 9 | } 10 | }); 11 | 12 | export default styles; 13 | -------------------------------------------------------------------------------- /src/pages/SignInPage/SignInPage.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | 3 | import { 4 | Text, 5 | View, 6 | TouchableHighlight, 7 | TouchableOpacity, 8 | Alert, 9 | NativeModules 10 | } from 'react-native'; 11 | import { useUser } from '../../context/UserContext'; 12 | import styles from './style' 13 | 14 | const SignInPage = () => { 15 | 16 | const { setUser, logOutUser } = useUser(); 17 | 18 | const testFlavor = () => NativeModules.ToastComponent.toastMe(); 19 | 20 | const getPushToken = () => NativeModules.HMSPush.getToken(); 21 | 22 | const sendEvent = (name, bundle) => NativeModules.HMSAnalytics.sendEvent(name, bundle); 23 | 24 | const login = () => { 25 | NativeModules.HMSLogin.Login().then((account) => { 26 | setUser(account); 27 | }, (code, message) => { 28 | logOutUser(); 29 | console.log(message); 30 | }); 31 | } 32 | 33 | return ( 34 | <> 35 | 36 | login()}> 37 | Login 38 | 39 | 40 | testFlavor()}> 41 | Test Flavor 42 | 43 | 44 | getPushToken()}> 45 | Get Push Token 46 | 47 | 48 | sendEvent("test", `{"message": "hi"}`)}> 50 | Send Analytics Event 51 | 52 | 53 | 54 | 55 | ); 56 | }; 57 | 58 | export default SignInPage; -------------------------------------------------------------------------------- /src/pages/SignInPage/index.js: -------------------------------------------------------------------------------- 1 | import SignInPage from './SignInPage'; 2 | 3 | export default SignInPage; 4 | -------------------------------------------------------------------------------- /src/pages/SignInPage/style.js: -------------------------------------------------------------------------------- 1 | import { StyleSheet } from "react-native"; 2 | 3 | export const BUTTON_COLOR = '#DCDCDC'; 4 | 5 | const styles = StyleSheet.create({ 6 | container: { 7 | flex: 1, 8 | justifyContent: 'center', 9 | alignItems: 'center', 10 | backgroundColor: BUTTON_COLOR, 11 | }, 12 | buttonContainer: { 13 | height: 45, 14 | flexDirection: 'row', 15 | justifyContent: 'center', 16 | alignItems: 'center', 17 | marginBottom: 20, 18 | width: 250, 19 | borderRadius: 30, 20 | }, 21 | loginButton: { 22 | backgroundColor: "#00b5ec", 23 | }, 24 | }); 25 | 26 | export default styles; 27 | 28 | --------------------------------------------------------------------------------