Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 WIP: V2 #334

Draft
wants to merge 46 commits into
base: react-native-health-v2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
dbd36b3
- Initial implementation of the swift core with quantity type samples
GGGava Jul 6, 2023
ed323ae
- Improvements on aggregation queries
GGGava Jul 12, 2023
9c12579
- Added metadata field to samples
GGGava Jul 12, 2023
b2a275a
- Fixed typo
GGGava Jul 12, 2023
2545ff8
- Added save quantity sample method
GGGava Jul 12, 2023
7b9e050
- Created inser opearation with metadata
GGGava Jul 13, 2023
ee26662
- Recreated example app
GGGava Aug 4, 2023
a9e381b
- Fixed issue in initHealthKit wrapper
GGGava Aug 4, 2023
055a613
- Added getQuantitySamples to RN bridge
GGGava Aug 4, 2023
77c49ae
- Exported getQuantitySamplesAggregation method
GGGava Aug 11, 2023
2c232a1
- Exported saveQuantitySample method
GGGava Aug 11, 2023
09715b8
- Added initHealthKit support for older iOS versions
GGGava Aug 11, 2023
b8175de
Migrate to typescript
RuanAzevedo Aug 12, 2023
e82eb9a
Fix linter errors on the example app
RuanAzevedo Aug 12, 2023
36a6e27
Merge branch 'swift' of github.com:agencyenterprise/react-native-heal…
GGGava Aug 17, 2023
9de05b7
- Exported units and AggregationOptions
GGGava Aug 17, 2023
4ddaa73
- Added typing to exported functions
GGGava Aug 23, 2023
6873f2d
- Sample dates are now string
GGGava Aug 23, 2023
c6b1f7f
- Metadata is now visible in js
GGGava Aug 24, 2023
8308131
- Changed aggregation queries to statistics queries
GGGava Aug 24, 2023
33aaca3
- Added activityType and IDs filter to workout queries
GGGava Sep 7, 2023
988a918
- Created QueryParameters superclass to remove code duplication
GGGava Sep 7, 2023
7eb2486
- Exported getWorkout method
GGGava Sep 8, 2023
ec6efc3
- Added save workout method
GGGava Sep 8, 2023
6032248
Add docs to HealthKitCore
thalysviana Nov 22, 2023
9c226b5
Update StatisticsQuantityQuery class description
thalysviana Nov 22, 2023
7607ba6
WIP
thalysviana Nov 24, 2023
b39bbe1
Merge pull request #348 from agencyenterprise/chore/add-documentation…
thalysviana Nov 27, 2023
7ef57f4
Process workout metadata
thalysviana Nov 27, 2023
132985d
Move WorkoutMetadata to index.ts
thalysviana Nov 27, 2023
c80e861
Set deployment target to 14.0
thalysviana Nov 27, 2023
82c2499
Refactor workout creation to use new workout api
thalysviana Nov 28, 2023
8e608a1
Remove automatic code signing
thalysviana Nov 28, 2023
c5d2e03
Remove files
thalysviana Nov 28, 2023
8221b4a
Remove yarn.lock
thalysviana Nov 28, 2023
b4c6059
Comment keys with missing docs
thalysviana Nov 28, 2023
92d1626
Merge pull request #351 from agencyenterprise/feature/add-metadata-to…
thalysviana Nov 28, 2023
0f0e68d
Add workout activities to sample
thalysviana Nov 29, 2023
ff7f08f
Update example app with activities
thalysviana Nov 29, 2023
3b8d8ee
Update saveWorkout to include workout activities
thalysviana Nov 29, 2023
7a4a221
Fix issue with workout activitiy type assigned numbers
thalysviana Nov 29, 2023
0d374f3
Remove comments
thalysviana Nov 29, 2023
0bc9e4e
Update enum cases
thalysviana Nov 29, 2023
7693379
Update documentation
thalysviana Nov 29, 2023
429680e
Fix build due to missing dictionary casting
thalysviana Dec 1, 2023
10cbfe7
Merge pull request #352 from agencyenterprise/feature/add-actitivies-…
GGGava Jun 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions RNAppleHealthKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ A React Native package to interact with Apple HealthKit
s.homepage = 'https://github.com/agencyenterprise/react-native-health'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Agency Enterprise' => '' }
s.source = { :git => 'https://github.com/agencyenterprise/react-native-healthkit.git', :tag => s.version.to_s }
s.source = {
:git => 'https://github.com/agencyenterprise/react-native-healthkit.git',
:tag => s.version.to_s,
:submodules => true
}

s.ios.deployment_target = '9.0'
s.swift_version = '4.2'
s.ios.deployment_target = '13.0'
s.swift_version = '5.5'

s.source_files = 'RCTAppleHealthKit/**/*'
s.source_files = ['v2/RNHealthKitCore/ReactNativeBridge/**/*', 'v2/RNHealthKitCore/HealthKitCore/**/*.swift']
s.requires_arc = true

s.frameworks = ['HealthKit']
s.dependency 'React'
Expand Down
6 changes: 0 additions & 6 deletions example/.buckconfig

This file was deleted.

2 changes: 1 addition & 1 deletion example/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: '@react-native-community',
extends: '@react-native',
};
1 change: 0 additions & 1 deletion example/.gitattributes

This file was deleted.

31 changes: 17 additions & 14 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ DerivedData
*.hmap
*.ipa
*.xcuserstate
ios/.xcode.env.local

# Android/IntelliJ
#
Expand All @@ -28,36 +29,38 @@ build/
.gradle
local.properties
*.iml

# Visual Studio Code
#
.vscode/
*.hprof
.cxx/
*.keystore
!debug.keystore

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# BUCK
buck-out/
\.buckd/
*.keystore
!debug.keystore

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots
**/fastlane/report.xml
**/fastlane/Preview.html
**/fastlane/screenshots
**/fastlane/test_output

# Bundle artifact
*.jsbundle

# CocoaPods
# Ruby / CocoaPods
/ios/Pods/
/vendor/bundle/

# Temporary files created by Metro to check the health of the file watcher
.metro-health-check*

# testing
/coverage
3 changes: 2 additions & 1 deletion example/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
arrowParens: 'avoid',
bracketSameLine: true,
bracketSpacing: false,
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
};
2 changes: 1 addition & 1 deletion example/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
132 changes: 74 additions & 58 deletions example/App.tsx
Original file line number Diff line number Diff line change
@@ -1,71 +1,75 @@
import React, {useState, useEffect} from 'react';
import React, { useEffect } from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
Button,
} from 'react-native';

import {Colors} from 'react-native/Libraries/NewAppScreen';
import AppleHealthKit, {
HealthValue,
HealthKitPermissions,
} from 'react-native-health';
import RNHealthKit, { HealthType, HealthUnit, StatisticsOption, Interval } from 'react-native-health';

import {NativeEventEmitter, NativeModules} from 'react-native';
RNHealthKit.initHealthKit(Object.values(HealthType), [
HealthType.HeartRate,
]);

/* Permission options */
const permissions = {
permissions: {
read: [AppleHealthKit.Constants.Permissions.HeartRate],
write: [AppleHealthKit.Constants.Permissions.Steps],
},
} as HealthKitPermissions;

AppleHealthKit.initHealthKit(permissions, (error: string) => {
/* Called after we receive a response from the system */

if (error) {
console.log('[ERROR] Cannot grant permissions!');
}

/* Can now read or write to HealthKit */
async function runQuery() {
const result = await RNHealthKit.getQuantitySamples(
{
type: HealthType.HeartRate,
startDate: new Date(2023, 7, 1).toISOString(),
endDate: new Date().toISOString(),
unit: HealthUnit.BeatsPerMinute,
},
);
console.log(result);
}

const options = {
startDate: new Date(2020, 1, 1).toISOString(),
};
async function runStatisticsQuery() {
const result = await RNHealthKit.getQuantitySamplesStatistics(
{
type: HealthType.ActiveEnergyBurned,
startDate: new Date(2022, 0, 1).toISOString(),
endDate: new Date(2024, 0, 1).toISOString(),
interval: Interval.Year,
anchorDate: new Date(2023, 0, 1).toISOString(),
unit: HealthUnit.Kilocalories,
option: StatisticsOption.CumulativeSum,
},
);
console.log(result);
}

AppleHealthKit.getHeartRateSamples(
options,
(callbackError: string, results: HealthValue[]) => {
/* Samples are now collected from HealthKit */
async function saveQuantitySample() {
const result = await RNHealthKit.saveQuantitySample(
HealthType.HeartRate,
{
startDate: new Date().toISOString(),
endDate: new Date().toISOString(),
value: 82,
unit: HealthUnit.BeatsPerMinute,
metadata: {
"TestingMetadata": "TestingValue"
},
},
);
});
console.log(result);
}

export default function App() {
const [authStatus, setAuthStatus] = useState<any>({});
// const [authStatus, setAuthStatus] = useState<any>({});

useEffect(() => {
new NativeEventEmitter(NativeModules.AppleHealthKit).addListener(
'healthKit:HeartRate:new',
async () => {
console.log('--> observer triggered');
},
);
// new NativeEventEmitter(NativeModules.AppleHealthKit).addListener(
// 'healthKit:HeartRate:new',
// async () => {
// console.log('--> observer triggered');
// },
// );
});

const handlePressGetAuthStatus = () => {
AppleHealthKit.getAuthStatus(permissions, (err, result) => {
if (err) {
console.error(err);
}
setAuthStatus(result);
});
};

return (
<>
<StatusBar barStyle="dark-content" />
Expand All @@ -78,12 +82,24 @@ export default function App() {
<Text style={styles.sectionTitle}>
React Native Health Example
</Text>
<Text onPress={handlePressGetAuthStatus}>
Press me to get Auth Status
</Text>
<Text style={styles.sectionDescription}>
{JSON.stringify(authStatus, null, 2)}
</Text>
<Button
title="Run Query"
onPress={() => {
runQuery();
}}
/>
<Button
title="Run Statistics Query"
onPress={() => {
runStatisticsQuery();
}}
/>
<Button
title="Save Quantity Sample"
onPress={() => {
saveQuantitySample();
}}
/>
</View>
</View>
</ScrollView>
Expand All @@ -94,14 +110,14 @@ export default function App() {

const styles = StyleSheet.create({
scrollView: {
backgroundColor: Colors.lighter,
backgroundColor: '#f5f5f5',
},
engine: {
position: 'absolute',
right: 0,
},
body: {
backgroundColor: Colors.white,
backgroundColor: '#ffffff',
},
sectionContainer: {
marginTop: 32,
Expand All @@ -110,19 +126,19 @@ const styles = StyleSheet.create({
sectionTitle: {
fontSize: 24,
fontWeight: '600',
color: Colors.black,
color: '#000000',
},
sectionDescription: {
marginTop: 8,
fontSize: 18,
fontWeight: '400',
color: Colors.dark,
color: '#000000',
},
highlight: {
fontWeight: '700',
},
footer: {
color: Colors.dark,
color: '#000000',
fontSize: 12,
fontWeight: '600',
padding: 4,
Expand Down
79 changes: 79 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli).

# Getting Started

>**Note**: Make sure you have completed the [React Native - Environment Setup](https://reactnative.dev/docs/environment-setup) instructions till "Creating a new application" step, before proceeding.
## Step 1: Start the Metro Server

First, you will need to start **Metro**, the JavaScript _bundler_ that ships _with_ React Native.

To start Metro, run the following command from the _root_ of your React Native project:

```bash
# using npm
npm start

# OR using Yarn
yarn start
```

## Step 2: Start your Application

Let Metro Bundler run in its _own_ terminal. Open a _new_ terminal from the _root_ of your React Native project. Run the following command to start your _Android_ or _iOS_ app:

### For Android

```bash
# using npm
npm run android

# OR using Yarn
yarn android
```

### For iOS

```bash
# using npm
npm run ios

# OR using Yarn
yarn ios
```

If everything is set up _correctly_, you should see your new app running in your _Android Emulator_ or _iOS Simulator_ shortly provided you have set up your emulator/simulator correctly.

This is one way to run your app — you can also run it directly from within Android Studio and Xcode respectively.

## Step 3: Modifying your App

Now that you have successfully run the app, let's modify it.

1. Open `App.tsx` in your text editor of choice and edit some lines.
2. For **Android**: Press the <kbd>R</kbd> key twice or select **"Reload"** from the **Developer Menu** (<kbd>Ctrl</kbd> + <kbd>M</kbd> (on Window and Linux) or <kbd>Cmd ⌘</kbd> + <kbd>M</kbd> (on macOS)) to see your changes!

For **iOS**: Hit <kbd>Cmd ⌘</kbd> + <kbd>R</kbd> in your iOS Simulator to reload the app and see your changes!

## Congratulations! :tada:

You've successfully run and modified your React Native App. :partying_face:

### Now what?

- If you want to add this new React Native code to an existing application, check out the [Integration guide](https://reactnative.dev/docs/integration-with-existing-apps).
- If you're curious to learn more about React Native, check out the [Introduction to React Native](https://reactnative.dev/docs/getting-started).

# Troubleshooting

If you can't get this to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page.

# Learn More

To learn more about React Native, take a look at the following resources:

- [React Native Website](https://reactnative.dev) - learn more about React Native.
- [Getting Started](https://reactnative.dev/docs/environment-setup) - an **overview** of React Native and how setup your environment.
- [Learn the Basics](https://reactnative.dev/docs/getting-started) - a **guided tour** of the React Native **basics**.
- [Blog](https://reactnative.dev/blog) - read the latest official React Native **Blog** posts.
- [`@facebook/react-native`](https://github.com/facebook/react-native) - the Open Source; GitHub **repository** for React Native.
14 changes: 0 additions & 14 deletions example/__tests__/App-test.tsx

This file was deleted.

Empty file added example/__tests__/App.test.tsx
Empty file.