HMS-Core / hms-react-native-plugin

This repo contains all of React-Native HMS plugins.
https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin?ha_source=hms1
Apache License 2.0
235 stars 67 forks source link

Fix types and crash issue in ios for react-native-hms-availability #251

Closed aljary12 closed 1 year ago

aljary12 commented 1 year ago

Hi! When we import react-native-hms-availability, there is no issue in android or Huawei phones, but the app crashes if we run it on ios device. The error is Invariant Violation: new NativeEventEmitter() requires a non-null argument. The fix is to move new NativeEventEmitter(HMSAvailabilityModule) into OnErrorDialogFragmentCancelledListenerAdd function.

ozcanozgur commented 1 year ago

Hi @aljary12,

We are aware of this issue and planning to solve it in our new releases, but there are different development processes in our team so at this time we can't merge your PR directly, thank you for your contribution.

In addition to your solution, you can try to create a new component with Availability plugin, then you will be able to import the new component dynamically in your App.js file with Platform checking feature of React Native.

const App = () => {
  return (
    <SafeAreaView >
      {Platform.OS === 'ios' ? null : <TestAvailability />}
    </SafeAreaView>
  );
};