@tryvital/vital-core-react-native 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.editorconfig ADDED
@@ -0,0 +1,15 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # editorconfig.org
4
+
5
+ root = true
6
+
7
+ [*]
8
+
9
+ indent_style = space
10
+ indent_size = 2
11
+
12
+ end_of_line = lf
13
+ charset = utf-8
14
+ trim_trailing_whitespace = true
15
+ insert_final_newline = true
package/.gitattributes ADDED
@@ -0,0 +1,3 @@
1
+ *.pbxproj -text
2
+ # specific for windows script files
3
+ *.bat text eol=crlf
package/.gitignore ADDED
@@ -0,0 +1,70 @@
1
+ # OSX
2
+ #
3
+ .DS_Store
4
+
5
+ # XDE
6
+ .expo/
7
+
8
+ # VSCode
9
+ .vscode/
10
+ jsconfig.json
11
+
12
+ # Xcode
13
+ #
14
+ build/
15
+ *.pbxuser
16
+ !default.pbxuser
17
+ *.mode1v3
18
+ !default.mode1v3
19
+ *.mode2v3
20
+ !default.mode2v3
21
+ *.perspectivev3
22
+ !default.perspectivev3
23
+ xcuserdata
24
+ *.xccheckout
25
+ *.moved-aside
26
+ DerivedData
27
+ *.hmap
28
+ *.ipa
29
+ *.xcuserstate
30
+ project.xcworkspace
31
+
32
+ # Android/IJ
33
+ #
34
+ .classpath
35
+ .cxx
36
+ .gradle
37
+ .idea
38
+ .project
39
+ .settings
40
+ local.properties
41
+ android.iml
42
+
43
+ # Cocoapods
44
+ #
45
+ example/ios/Pods
46
+
47
+ # Ruby
48
+ example/vendor/
49
+
50
+ # node.js
51
+ #
52
+ node_modules/
53
+ npm-debug.log
54
+ yarn-debug.log
55
+ yarn-error.log
56
+
57
+ # BUCK
58
+ buck-out/
59
+ \.buckd/
60
+ android/app/libs
61
+ android/keystores/debug.keystore
62
+
63
+ # Expo
64
+ .expo/
65
+
66
+ # Turborepo
67
+ .turbo/
68
+
69
+ # generated by bob
70
+ lib/
@@ -0,0 +1 @@
1
+ {}
package/.yarnrc ADDED
@@ -0,0 +1,3 @@
1
+ # Override Yarn command so we can automatically setup the repo on running `yarn`
2
+
3
+ yarn-path "scripts/bootstrap.js"
package/LICENSE ADDED
@@ -0,0 +1 @@
1
+ todo
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # vital-core-react-native
2
+
3
+ todo
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install vital-core-react-native
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import { multiply } from 'vital-core-react-native';
15
+
16
+ // ...
17
+
18
+ const result = await multiply(3, 7);
19
+ ```
20
+
21
+ ## Contributing
22
+
23
+ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
24
+
25
+ ## License
26
+
27
+ MIT
28
+
29
+ ---
30
+
31
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,146 @@
1
+ buildscript {
2
+ // Buildscript is evaluated before everything else so we can't use getExtOrDefault
3
+ def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['VitalCoreReactNative_kotlinVersion']
4
+
5
+ repositories {
6
+ google()
7
+ mavenCentral()
8
+ }
9
+
10
+ dependencies {
11
+ classpath 'com.android.tools.build:gradle:3.5.3'
12
+ // noinspection DifferentKotlinGradleVersion
13
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14
+ }
15
+ }
16
+
17
+ def isNewArchitectureEnabled() {
18
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
19
+ }
20
+
21
+ apply plugin: 'com.android.library'
22
+ apply plugin: 'kotlin-android'
23
+
24
+ if (isNewArchitectureEnabled()) {
25
+ apply plugin: 'com.facebook.react'
26
+ }
27
+
28
+ def getExtOrDefault(name) {
29
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['VitalCoreReactNative_' + name]
30
+ }
31
+
32
+ def getExtOrIntegerDefault(name) {
33
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['VitalCoreReactNative_' + name]).toInteger()
34
+ }
35
+
36
+ android {
37
+ compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
38
+
39
+ defaultConfig {
40
+ minSdkVersion getExtOrIntegerDefault('minSdkVersion')
41
+ targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
42
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
43
+ }
44
+ buildTypes {
45
+ release {
46
+ minifyEnabled false
47
+ }
48
+ }
49
+
50
+ lintOptions {
51
+ disable 'GradleCompatible'
52
+ }
53
+
54
+ compileOptions {
55
+ sourceCompatibility JavaVersion.VERSION_1_8
56
+ targetCompatibility JavaVersion.VERSION_1_8
57
+ }
58
+
59
+ }
60
+
61
+ repositories {
62
+ mavenCentral()
63
+ google()
64
+
65
+ def found = false
66
+ def defaultDir = null
67
+ def androidSourcesName = 'React Native sources'
68
+
69
+ if (rootProject.ext.has('reactNativeAndroidRoot')) {
70
+ defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
71
+ } else {
72
+ defaultDir = new File(
73
+ projectDir,
74
+ '/../../../node_modules/react-native/android'
75
+ )
76
+ }
77
+
78
+ if (defaultDir.exists()) {
79
+ maven {
80
+ url defaultDir.toString()
81
+ name androidSourcesName
82
+ }
83
+
84
+ logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
85
+ found = true
86
+ } else {
87
+ def parentDir = rootProject.projectDir
88
+
89
+ 1.upto(5, {
90
+ if (found) return true
91
+ parentDir = parentDir.parentFile
92
+
93
+ def androidSourcesDir = new File(
94
+ parentDir,
95
+ 'node_modules/react-native'
96
+ )
97
+
98
+ def androidPrebuiltBinaryDir = new File(
99
+ parentDir,
100
+ 'node_modules/react-native/android'
101
+ )
102
+
103
+ if (androidPrebuiltBinaryDir.exists()) {
104
+ maven {
105
+ url androidPrebuiltBinaryDir.toString()
106
+ name androidSourcesName
107
+ }
108
+
109
+ logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
110
+ found = true
111
+ } else if (androidSourcesDir.exists()) {
112
+ maven {
113
+ url androidSourcesDir.toString()
114
+ name androidSourcesName
115
+ }
116
+
117
+ logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
118
+ found = true
119
+ }
120
+ })
121
+ }
122
+
123
+ if (!found) {
124
+ throw new GradleException(
125
+ "${project.name}: unable to locate React Native android sources. " +
126
+ "Ensure you have you installed React Native as a dependency in your project and try again."
127
+ )
128
+ }
129
+ }
130
+
131
+ def kotlin_version = getExtOrDefault('kotlinVersion')
132
+
133
+ dependencies {
134
+ //noinspection GradleDynamicVersion
135
+ implementation "com.facebook.react:react-native:+"
136
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
137
+ // From node_modules
138
+ }
139
+
140
+ if (isNewArchitectureEnabled()) {
141
+ react {
142
+ jsRootDir = file("../src/")
143
+ libraryName = "VitalCoreReactNative"
144
+ codegenJavaPackageName = "com.vitalcorereactnative"
145
+ }
146
+ }
@@ -0,0 +1,5 @@
1
+ VitalCoreReactNative_kotlinVersion=1.7.0
2
+ VitalCoreReactNative_minSdkVersion=21
3
+ VitalCoreReactNative_targetSdkVersion=31
4
+ VitalCoreReactNative_compileSdkVersion=31
5
+ VitalCoreReactNative_ndkversion=21.4.7075529
@@ -0,0 +1,4 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.vitalcorereactnative">
3
+
4
+ </manifest>
@@ -0,0 +1,25 @@
1
+ package com.vitalcorereactnative
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
5
+ import com.facebook.react.bridge.ReactMethod
6
+ import com.facebook.react.bridge.Promise
7
+
8
+ class VitalCoreReactNativeModule(reactContext: ReactApplicationContext) :
9
+ ReactContextBaseJavaModule(reactContext) {
10
+
11
+ override fun getName(): String {
12
+ return NAME
13
+ }
14
+
15
+ // Example method
16
+ // See https://reactnative.dev/docs/native-modules-android
17
+ @ReactMethod
18
+ fun multiply(a: Double, b: Double, promise: Promise) {
19
+ promise.resolve(a * b)
20
+ }
21
+
22
+ companion object {
23
+ const val NAME = "VitalCoreReactNative"
24
+ }
25
+ }
@@ -0,0 +1,17 @@
1
+ package com.vitalcorereactnative
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
+
8
+
9
+ class VitalCoreReactNativePackage : ReactPackage {
10
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
11
+ return listOf(VitalCoreReactNativeModule(reactContext))
12
+ }
13
+
14
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
15
+ return emptyList()
16
+ }
17
+ }
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ presets: ['module:metro-react-native-babel-preset'],
3
+ };
@@ -0,0 +1,2 @@
1
+ #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTViewManager.h>
@@ -0,0 +1,24 @@
1
+ #import <React/RCTBridgeModule.h>
2
+
3
+ @interface RCT_EXTERN_MODULE(VitalCoreReactNative, NSObject)
4
+
5
+ RCT_EXTERN_METHOD(setUserId:(NSString *)userId
6
+ resolver:(RCTPromiseResolveBlock)resolve
7
+ rejecter:(RCTPromiseRejectBlock)reject)
8
+
9
+ RCT_EXTERN_METHOD(configure:(NSString *)apiKey
10
+ environment:(NSString *)environment
11
+ region:(NSString *)region
12
+ enableLogs:(BOOL)enableLogs
13
+ resolver:(RCTPromiseResolveBlock)resolve
14
+ rejecter:(RCTPromiseRejectBlock)reject)
15
+
16
+ RCT_EXTERN_METHOD(cleanUp:(RCTPromiseResolveBlock)resolve
17
+ rejecter:(RCTPromiseRejectBlock)reject)
18
+
19
+ + (BOOL)requiresMainQueueSetup
20
+ {
21
+ return NO;
22
+ }
23
+
24
+ @end
@@ -0,0 +1,57 @@
1
+ import VitalCore
2
+
3
+ @objc(VitalCoreReactNative)
4
+ class VitalCoreReactNative: NSObject {
5
+
6
+ @objc(setUserId:resolver:rejecter:)
7
+ func setUserId(_ userId: String, resolve: @escaping RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
8
+ guard let userId = UUID.init(uuidString: userId) else {
9
+ reject(nil, "userId must be an UUID", nil)
10
+ return
11
+ }
12
+
13
+ Task {
14
+ await VitalClient.setUserId(userId)
15
+ resolve(())
16
+ }
17
+ }
18
+
19
+ @objc(configure:environment:region:enableLogs:resolver:rejecter:)
20
+ func configure(
21
+ _ apiKey: String,
22
+ environment: String,
23
+ region: String,
24
+ enableLogs: Bool,
25
+ resolve:@escaping RCTPromiseResolveBlock,
26
+ reject:RCTPromiseRejectBlock
27
+ ) {
28
+
29
+ let env: Environment
30
+ switch (environment, region) {
31
+ case ("production", "us"):
32
+ env = .production(.us)
33
+ case ("production", "eu"):
34
+ env = .production(.eu)
35
+ case ("sandbox", "us"):
36
+ env = .sandbox(.us)
37
+ case ("sandbox", "eu"):
38
+ env = .sandbox(.eu)
39
+ default:
40
+ reject(nil, "enviroment / region values not accepted", nil)
41
+ return
42
+ }
43
+
44
+ Task {
45
+ await VitalClient.configure(apiKey: apiKey, environment: env, configuration: .init(logsEnable: enableLogs))
46
+ resolve(())
47
+ }
48
+ }
49
+
50
+ @objc(cleanUp:rejecter:)
51
+ func cleanUp(resolve:@escaping RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
52
+ Task {
53
+ await VitalClient.shared.cleanUp()
54
+ resolve(())
55
+ }
56
+ }
57
+ }