Zentrust / OTPublishersHeadlessSDK

OTPublishersHeadlessSDK for iOS
Other
7 stars 5 forks source link

[React Native] listenForConsentChanges issue #31

Open lorenc-tomasz opened 7 months ago

lorenc-tomasz commented 7 months ago

listenForConsentChanges function should return EmitterSubscription object, but it doesn't do that.


/**

   * Listen for consent changes to a particular category
   * @param {string} category String of the category ID to listen for
   * @callback 
   * @param {string} category Category that was changed. Matches the category in listener registration
   * @param {number} consent Consent value (1 = consent given, 0 = consent not given)
   * @returns {object} Returns an event emitter that can be unsubscribed from when your component dismounts

   */

  static listenForConsentChanges(category:string, callback = function (category:string,consent:number) {}) {

    if (Platform.OS === 'android') {
      OneTrust.listenForConsentChanges(category);
      DeviceEventEmitter.addListener(category, (consent:number) =>
        callback(category, consent),
      );

    } else {
      iOSBroadcast.listenForConsentChanges(category);
      const consentListener = new NativeEventEmitter(iOSBroadcast);
      consentListener.addListener(category, (consent:number) =>
        callback(category, consent),
      );
    }
  }

It should look like this:

  static listenForConsentChanges(category:string, callback = function (category:string,consent:number) {}) {

    if (Platform.OS === 'android') {
      OneTrust.listenForConsentChanges(category);
      return DeviceEventEmitter.addListener(category, (consent:number) =>
        callback(category, consent),
      );

    } else {
      iOSBroadcast.listenForConsentChanges(category);
      const consentListener = new NativeEventEmitter(iOSBroadcast);
      return consentListener.addListener(category, (consent:number) =>
        callback(category, consent),
      );
    }
  }

Could you fix this ASAP, please?