Skip to content

Commit 6ad0214

Browse files
authored
Merge pull request #3 from xmartlabs/active-basal-energy
feat: read basal/active energy
2 parents f7c8fa0 + 669c512 commit 6ad0214

File tree

17 files changed

+207
-46
lines changed

17 files changed

+207
-46
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ This library supports reading and writing the following health data types:
2626
- **Resting heart rate** - Resting heart rate measurements
2727
- **Blood pressure** - Systolic and diastolic blood pressure readings
2828
- **Oxygen saturation** - Blood oxygen saturation percentage
29+
- **Active Energy Burned** - The amount of energy expended during a specific activity.
30+
- **Basal Energy Burned** - The amount of energy expended at rest.
31+
2932

3033
## Usage
3134

docs/initializeHealth.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The `initializeHealth` function sets up health integration for the application b
44

55
It accepts a `permissions` object with keys `read` and `write`. Use the `HealthLinkPermissions` enum to add permissions to the arrays.
66

7-
Write method does not support `BloodPressure`, `RestingHeartRate` and `OxygenSaturation`, so I'd recommend not to ask for write permissions for those data types.
7+
Write method does not support `BloodPressure`, `RestingHeartRate`, `ActiveEnergyBurned`, `BasalEnergyBurned` and `OxygenSaturation`, so I'd recommend not to ask for write permissions for those data types.
88

99
---
1010

docs/read.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ RestingHeartRate
2727
BloodPressure
2828
OxygenSaturation
2929
Steps
30+
ActiveEnergyBurned
31+
BasalEnergyBurned
3032
```
3133

3234
## **`ReadOptions` Interface**
@@ -77,12 +79,13 @@ The `ReadOptions` interface defines the optional parameters that can be used to
7779

7880
The `Unit` type supports various health-related units:
7981

80-
| **Unit Type** | **Examples** |
81-
| ------------------ | --------------------- |
82-
| `BloodGlucoseUnit` | `MmolPerL`, `MgPerDL` |
83-
| `WeightUnit` | `Kg`, `Lbs` |
84-
| `HeightUnit` | `Cm`, `Inches` |
85-
| `HeartRateUnit` | `BeatsPerMinute` |
82+
| **Unit Type** | **Examples** |
83+
| ------------------ | ---------------------------------- |
84+
| `BloodGlucoseUnit` | `MmolPerL`, `MgPerDL` |
85+
| `WeightUnit` | `Kg`, `Lbs` |
86+
| `HeightUnit` | `Cm`, `Inches` |
87+
| `HeartRateUnit` | `BeatsPerMinute` |
88+
| `EnergyUnit` | `Calories`, `Joules`, `Kilojoules` |
8689

8790
---
8891

@@ -97,3 +100,23 @@ read(HealthLinkDataType.BloodGlucose, {
97100
unit: BloodGlucoseUnit.MmolPerL,
98101
});
99102
```
103+
104+
#### Retrieve Active Energy Burned Data
105+
106+
```typescript
107+
read(HealthLinkDataType.ActiveEnergyBurned, {
108+
startDate: '2025-01-01T00:00:00Z',
109+
endDate: '2025-01-31T23:59:59Z',
110+
unit: EnergyUnit.Calories,
111+
});
112+
```
113+
114+
#### Retrieve Basal Energy Burned Data
115+
116+
```typescript
117+
read(HealthLinkDataType.BasalEnergyBurned, {
118+
startDate: '2025-01-01T00:00:00Z',
119+
endDate: '2025-01-31T23:59:59Z',
120+
unit: EnergyUnit.Calories,
121+
});
122+
```

example/android/app/build.gradle

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,4 @@ dependencies {
116116
} else {
117117
implementation jscFlavor
118118
}
119-
}
120-
121-
def isNewArchitectureEnabled() {
122-
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
123-
}
124-
125-
if (isNewArchitectureEnabled()) {
126-
// Since our library doesn't invoke codegen automatically we need to do it here.
127-
tasks.register('invokeLibraryCodegen', Exec) {
128-
workingDir "$rootDir/../../"
129-
def isWindows = System.getProperty('os.name').toLowerCase().contains('windows')
130-
131-
if (isWindows) {
132-
commandLine 'cmd', '/c', 'npx bob build --target codegen'
133-
} else {
134-
commandLine 'sh', '-c', 'npx bob build --target codegen'
135-
}
136-
}
137-
preBuild.dependsOn invokeLibraryCodegen
138119
}

example/android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<uses-permission android:name="android.permission.health.WRITE_WEIGHT" />
1818
<uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE" />
1919
<uses-permission android:name="android.permission.health.WRITE_RESTING_HEART_RATE" />
20+
<uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED" />
21+
<uses-permission android:name="android.permission.health.READ_BASAL_METABOLIC_RATE" />
2022

2123
<application
2224
android:name=".MainApplication"

example/react-native.config.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ module.exports = {
1111
[pkg.name]: {
1212
root: path.join(__dirname, '..'),
1313
platforms: {
14-
// Codegen script incorrectly fails without this
15-
// So we explicitly specify the platforms with empty object
16-
ios: {},
17-
android: {},
14+
ios: null,
15+
android: null,
1816
},
1917
},
2018
},

example/src/App.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import { useEffect, useState } from 'react';
33
import { HealthLinkPermissions } from '../../src/types/permissions';
44
import { HealthLinkDataType } from '../../src/types/dataTypes';
55
import { initializeHealth, read, write } from 'react-native-health-link';
6-
import { BloodGlucoseUnit, HeighUnit, WeightUnit } from '../../src/types/units';
6+
import {
7+
BloodGlucoseUnit,
8+
EnergyUnit,
9+
HeighUnit,
10+
WeightUnit,
11+
} from '../../src/types/units';
712

813
export default function App() {
914
const [bloodGlucose, setBloodGlucose] = useState<number | undefined>();
@@ -20,6 +25,12 @@ export default function App() {
2025
number | undefined
2126
>();
2227
const [steps, setSteps] = useState<number | undefined>();
28+
const [activeEnergyBurned, setActiveEnergyBurned] = useState<
29+
number | undefined
30+
>();
31+
const [basalEnergyBurned, setBasalEnergyBurned] = useState<
32+
number | undefined
33+
>();
2334

2435
useEffect(() => {
2536
initializeHealth({
@@ -32,6 +43,8 @@ export default function App() {
3243
HealthLinkPermissions.BloodPressure,
3344
HealthLinkPermissions.OxygenSaturation,
3445
HealthLinkPermissions.Steps,
46+
HealthLinkPermissions.ActiveEnergyBurned,
47+
HealthLinkPermissions.BasalEnergyBurned,
3548
],
3649
write: [
3750
HealthLinkPermissions.BloodGlucose,
@@ -85,6 +98,18 @@ export default function App() {
8598
}).then((data) => {
8699
setSteps(data[0]?.value);
87100
});
101+
read(HealthLinkDataType.ActiveEnergyBurned, {
102+
startDate: new Date('2024-12-30').toISOString(),
103+
unit: EnergyUnit.Calories,
104+
}).then((data) => {
105+
setActiveEnergyBurned(data[0]?.value);
106+
});
107+
read(HealthLinkDataType.BasalEnergyBurned, {
108+
startDate: new Date('2024-12-30').toISOString(),
109+
unit: EnergyUnit.Calories,
110+
}).then((data) => {
111+
setBasalEnergyBurned(data[0]?.value);
112+
});
88113
write(HealthLinkDataType.BloodGlucose, {
89114
value: 4,
90115
unit: BloodGlucoseUnit.MmolPerL,
@@ -121,6 +146,8 @@ export default function App() {
121146
</Text>
122147
<Text>Your oxygen saturation is {oxygenSaturation}</Text>
123148
<Text>Your steps today are {steps}</Text>
149+
<Text>Your active energy is {activeEnergyBurned}</Text>
150+
<Text>Your basal energy is {basalEnergyBurned}</Text>
124151
</View>
125152
);
126153
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-health-link",
3-
"version": "0.1.4",
3+
"version": "0.2.0",
44
"description": "A common interface for react-naative-health and react-native-health-connect.",
55
"source": "./src/index.tsx",
66
"main": "./lib/commonjs/index.js",

react-native.config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
module.exports = {
55
dependency: {
66
platforms: {
7-
android: {
8-
cmakeListsPath: 'generated/jni/CMakeLists.txt',
9-
},
7+
android: null,
8+
ios: null,
109
},
1110
},
1211
};

src/helpers/permissions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ const genericToIosMap: { [key: string]: string | string[] } = {
8080
[HealthLinkPermissions.OxygenSaturation]:
8181
AppleHealthKit.Constants.Permissions.OxygenSaturation,
8282
[HealthLinkPermissions.Steps]: AppleHealthKit.Constants.Permissions.Steps,
83+
[HealthLinkPermissions.ActiveEnergyBurned]:
84+
AppleHealthKit.Constants.Permissions.ActiveEnergyBurned,
85+
[HealthLinkPermissions.BasalEnergyBurned]:
86+
AppleHealthKit.Constants.Permissions.BasalEnergyBurned,
8387
};
8488

8589
const genericToAndroidMap: {
@@ -93,4 +97,6 @@ const genericToAndroidMap: {
9397
[HealthLinkPermissions.BloodPressure]: 'BloodPressure',
9498
[HealthLinkPermissions.OxygenSaturation]: 'OxygenSaturation',
9599
[HealthLinkPermissions.Steps]: 'Steps',
100+
[HealthLinkPermissions.ActiveEnergyBurned]: 'ActiveCaloriesBurned',
101+
[HealthLinkPermissions.BasalEnergyBurned]: 'BasalMetabolicRate',
96102
};

0 commit comments

Comments
 (0)