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

Doesn't work with new bridgeless architecture on 0.76.0 #395

Open
andrewzey opened this issue Oct 30, 2024 · 2 comments · May be fixed by #396
Open

Doesn't work with new bridgeless architecture on 0.76.0 #395

andrewzey opened this issue Oct 30, 2024 · 2 comments · May be fixed by #396
Labels
bug Something isn't working

Comments

@andrewzey
Copy link

andrewzey commented Oct 30, 2024

Describe the bug
Because the new react-native architecture lazy loads modules by default, require('react-native').NativeModules is an empty object at app startup time. Search for "Lazy module loading by default" in https://reactnative.dev/blog/2024/10/23/the-new-architecture-is-here

To Reproduce
Load the app on React Native 0.76.0 and observe that all functions expected on AppleHealthKit are undefined.

Expected behavior
All functions on AppleHealthKit are should be defined at access time.

Workaround Confirmed to Work
Per this user's helpful comment (facebook/react-native#29228 (comment)), this workaround fixes the issue for MY app which only uses a handful of functions from react-native-health. This is far from a global solution though. I'm using yarn so I'm able to simply do a yarn patch react-native-health to be unblocked with this change:

index.js

import { Activities, Observers, Permissions, Units } from './src/constants'

// const { AppleHealthKit } = require('react-native').NativeModules

// export const HealthKit = Object.assign({}, AppleHealthKit, {
//   Constants: {
//     Activities,
//     Observers,
//     Permissions,
//     Units,
//   },
// })

// Temporary workaround per:
// https://github.com/facebook/react-native/issues/29228#issuecomment-2345062090
const NativeModules = require('react-native').NativeModules
export const HealthKit = {
  isAvailable: NativeModules.AppleHealthKit.isAvailable,
  initHealthKit: NativeModules.AppleHealthKit.initHealthKit,
  getDailyStepCountSamples: NativeModules.AppleHealthKit.getDailyStepCountSamples,
  getSamples: NativeModules.AppleHealthKit.getSamples,

  Constants: {
    Activities,
    Observers,
    Permissions,
    Units,
  },
}

module.exports = HealthKit
@andrewzey andrewzey added the bug Something isn't working label Oct 30, 2024
@andrewzey
Copy link
Author

andrewzey commented Oct 30, 2024

An example of the error message a user would encounter is:

_reactNativeHealth.default.isAvailable is not a function (it is undefined)

Simulator Screenshot - iPhone 16 Pro - 2024-10-29 at 20 58 17

@andrewzey andrewzey linked a pull request Oct 30, 2024 that will close this issue
5 tasks
@dhgavali
Copy link

dhgavali commented Nov 17, 2024

Native Emitter is not getting triggered in my case event after checking the apple health or updating the data.

My Project details :
"react-native-health": "^1.19.0",
"expo": "^51.0.38",
"react-native": "0.74.5",

ureReason=No such process found}}}
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - HeartRateVariabilitySDNN
[fitcentive.debug.dylib] There is no listeners for healthKit:HeartRateVariabilitySDNN:new
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - HeartRateVariabilitySDNN
healthKit:HeartRateVariabilitySDNN:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - RestingHeartRate
[fitcentive.debug.dylib] There is no listeners for healthKit:RestingHeartRate:new
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - RestingHeartRate
healthKit:RestingHeartRate:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - BasalEnergyBurned
[fitcentive.debug.dylib] There is no listeners for healthKit:BasalEnergyBurned:new
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - BasalEnergyBurned
healthKit:BasalEnergyBurned:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - StepCount
[fitcentive.debug.dylib] There is no listeners for healthKit:StepCount:new
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - StepCount healthKit:StepCount:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - Workout
[fitcentive.debug.dylib] There is no listeners for healthKit:Workout:new
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - Workout healthKit:Workout:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - Walking
[fitcentive.debug.dylib] There is no listeners for healthKit:Walking:new
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - Walking healthKit:Walking:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - MindfulSession
[fitcentive.debug.dylib] There is no listeners for healthKit:MindfulSession:new
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - MindfulSession
healthKit:MindfulSession:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - ActiveEnergyBurned
[fitcentive.debug.dylib] There is no listeners for healthKit:ActiveEnergyBurned:new
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - ActiveEnergyBurned
healthKit:ActiveEnergyBurned:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - HeartRate
[fitcentive.debug.dylib] There is no listeners for healthKit:HeartRate:new
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - HeartRate healthKit:HeartRate:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - Vo2Max
[fitcentive.debug.dylib] There is no listeners for healthKit:Vo2Max:new
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - Vo2Max healthKit:Vo2Max:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - SleepAnalysis
[fitcentive.debug.dylib] There is no listeners for healthKit:SleepAnalysis:new
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - SleepAnalysis healthKit:SleepAnalysis:new
 LOG  *** samples 65
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - RestingHeartRate
[fitcentive.debug.dylib] There is no listeners for healthKit:RestingHeartRate:new
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - RestingHeartRate
healthKit:RestingHeartRate:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - HeartRateVariabilitySDNN
[fitcentive.debug.dylib] There is no listeners for healthKit:HeartRateVariabilitySDNN:new
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - HeartRateVariabilitySDNN
healthKit:HeartRateVariabilitySDNN:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - BasalEnergyBurned
[fitcentive.debug.dylib] There is no listeners for healthKit:BasalEnergyBurned:new
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - BasalEnergyBurned
healthKit:BasalEnergyBurned:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - MindfulSession
[fitcentive.debug.dylib] There is no listeners for healthKit:MindfulSession:new
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - MindfulSession
healthKit:MindfulSession:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - Workout
[fitcentive.debug.dylib] There is no listeners for healthKit:Workout:new
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - Workout healthKit:Workout:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - HeartRate
[fitcentive.debug.dylib] There is no listeners for healthKit:HeartRate:new``` These kind of logs for no listeners are printing on console. 

but sometimes it automatically works 
``` [fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - ActiveEnergyBurned
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - ActiveEnergyBurned
healthKit:ActiveEnergyBurned:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - Walking
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - Walking healthKit:Walking:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - Vo2Max
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - Vo2Max healthKit:Vo2Max:new
[fitcentive.debug.dylib] [HealthKit] New sample received from Apple HealthKit - SleepAnalysis
[fitcentive.debug.dylib] [HealthKit] New sample from Apple HealthKit processed - SleepAnalysis healthKit:SleepAnalysis:new

However in both of cases nativeEmitter is not getting triggered and I'm not able to get any data in background / foreground. There is no proper example in the documentation as well how does the background listening of data work. a very short explanation on that. Any hints on getting background data updates would be helpful. I want to get data every time when there is change in data for health app. however as of now it doesn't matter for me after how much interval I get the updated data. does anyone know the solution? In existing issues find that most of the users are facing background issue updated. sample code on background listeners would really help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants