react-native-health-connect 3.1.0 → 3.1.1

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/README.md CHANGED
@@ -19,7 +19,7 @@ This library is a wrapper around Health Connect for react native. Health Connect
19
19
 
20
20
  ## Requirements
21
21
 
22
- Make sure you have React Native version 0.71 or higher installed to use v2 of React Native Health Connect.
22
+ Make sure you have React Native version 0.71 or higher **with the latest patch** installed to use v2 of React Native Health Connect.
23
23
 
24
24
  - [Health Connect](https://play.google.com/store/apps/details?id=com.google.android.apps.healthdata&hl=en&gl=US) needs to be installed on the user's device. Starting from Android 14 (Upside Down Cake), Health Connect is part of the Android Framework. Read more [here](https://developer.android.com/health-and-fitness/guides/health-connect/develop/get-started#step-1).
25
25
  - Health Connect API requires `minSdkVersion=26` (Android Oreo / 8.0).
@@ -4,7 +4,6 @@ import androidx.health.connect.client.PermissionController
4
4
  import androidx.health.connect.client.permission.HealthPermission
5
5
  import com.facebook.react.bridge.ReadableArray
6
6
  import com.facebook.react.bridge.WritableNativeArray
7
- import com.facebook.react.bridge.WritableNativeMap
8
7
  import dev.matinzd.healthconnect.utils.InvalidRecordType
9
8
  import dev.matinzd.healthconnect.utils.reactRecordTypeToClassMap
10
9
 
@@ -31,27 +30,20 @@ class PermissionUtils {
31
30
 
32
31
  fun mapPermissionResult(grantedPermissions: Set<String>): WritableNativeArray {
33
32
  return WritableNativeArray().apply {
34
- grantedPermissions.forEach {
35
- val map = WritableNativeMap()
33
+ for ((recordType, recordClass) in reactRecordTypeToClassMap) {
34
+ val readPermissionForRecord = HealthPermission.getReadPermission(recordClass)
35
+ val writePermissionForRecord = HealthPermission.getWritePermission(recordClass)
36
36
 
37
- val (accessType, recordType) = extractPermissionResult(it)
37
+ if (grantedPermissions.contains(readPermissionForRecord)) {
38
+ pushMap(ReactPermission(AccessType.READ, recordType).toReadableMap())
39
+ }
38
40
 
39
- map.putString("recordType", snakeToCamel(recordType))
40
- map.putString("accessType", accessType)
41
- pushMap(map)
41
+ if (grantedPermissions.contains(writePermissionForRecord)) {
42
+ pushMap(ReactPermission(AccessType.WRITE, recordType).toReadableMap())
43
+ }
42
44
  }
43
45
  }
44
46
  }
45
47
 
46
- private fun extractPermissionResult(it: String): Pair<String, String> {
47
- val accessType = it.substring(it.lastIndexOf(".") + 1, it.indexOf("_")).lowercase()
48
- val recordType = it.substring(it.indexOf("_") + 1).lowercase()
49
- return Pair(accessType, recordType)
50
- }
51
-
52
- private fun snakeToCamel(word: String): String {
53
- val components = word.split("_")
54
- return components.joinToString("") { it[0].uppercase() + it.substring(1) }
55
- }
56
48
  }
57
49
  }
@@ -0,0 +1,23 @@
1
+ package dev.matinzd.healthconnect.permissions
2
+
3
+ import com.facebook.react.bridge.ReadableMap
4
+ import com.facebook.react.bridge.WritableNativeMap
5
+
6
+ data class ReactPermission(val accessType: AccessType, val recordType: String) {
7
+ fun toReadableMap(): ReadableMap {
8
+ val map = WritableNativeMap()
9
+ map.putString(ACCESS_TYPE, accessType.reactName)
10
+ map.putString(RECORD_TYPE, recordType)
11
+ return map
12
+ }
13
+
14
+ companion object {
15
+ private const val ACCESS_TYPE = "accessType"
16
+ private const val RECORD_TYPE = "recordType"
17
+ }
18
+ }
19
+
20
+ enum class AccessType(val reactName: String) {
21
+ READ("read"),
22
+ WRITE("write")
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-health-connect",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "React native library for health connect (Android only)",
5
5
  "funding": "https://github.com/matinzd/react-native-health-connect?sponsor=1",
6
6
  "main": "lib/commonjs/index",