File tree 2 files changed +15
-9
lines changed
2 files changed +15
-9
lines changed Original file line number Diff line number Diff line change 1
- import React , { useState } from 'react' ;
1
+ import React , { useState , useEffect } from 'react' ;
2
2
import {
3
3
SafeAreaView ,
4
4
StyleSheet ,
@@ -14,6 +14,8 @@ import AppleHealthKit, {
14
14
HealthKitPermissions ,
15
15
} from 'react-native-health' ;
16
16
17
+ import { NativeEventEmitter , NativeModules } from 'react-native' ;
18
+
17
19
/* Permission options */
18
20
const permissions = {
19
21
permissions : {
@@ -46,6 +48,15 @@ AppleHealthKit.initHealthKit(permissions, (error: string) => {
46
48
export default function App ( ) {
47
49
const [ authStatus , setAuthStatus ] = useState < any > ( { } ) ;
48
50
51
+ useEffect ( ( ) => {
52
+ new NativeEventEmitter ( NativeModules . AppleHealthKit ) . addListener (
53
+ 'healthKit:HeartRate:new' ,
54
+ async ( ) => {
55
+ console . log ( '--> observer triggered' ) ;
56
+ } ,
57
+ ) ;
58
+ } ) ;
59
+
49
60
const handlePressGetAuthStatus = ( ) => {
50
61
AppleHealthKit . getAuthStatus ( permissions , ( err , result ) => {
51
62
if ( err ) {
Original file line number Diff line number Diff line change 2
2
* @format
3
3
*/
4
4
5
- import { AppRegistry , NativeEventEmitter , NativeModules } from 'react-native' ;
5
+ import { AppRegistry } from 'react-native' ;
6
6
import App from './App' ;
7
- import { name as appName } from './app.json' ;
7
+ import { name as appName } from './app.json' ;
8
8
9
- AppRegistry . registerComponent ( appName , ( ) => {
10
- new NativeEventEmitter ( NativeModules . AppleHealthKit ) . addListener ( 'healthKit:HeartRate:new' , async ( ) => {
11
- console . log ( 'new sample' )
12
- } )
13
- return App
14
- } ) ;
9
+ AppRegistry . registerComponent ( appName , ( ) => App ) ;
You can’t perform that action at this time.
0 commit comments