addEventListener
The SDK uses events to communicate changes in the current state.
Listeners for a specific event can be added with the following functions and are described in their corresponding topic guides.
interface NativeMethods {
  addEventListener(
    eventType: Events.SdkNotification.Pin,
    callback?: (event: Events.PinNotificationEvent) => void,
    ): EmitterSubscription;
  addEventListener(
    eventType: Events.SdkNotification.CustomRegistration,
    callback?: (event: Events.CustomRegistrationNotificationEvent) => void,
    ): EmitterSubscription;
  addEventListener(
    eventType: Events.SdkNotification.MobileAuthOtp,
    callback?: (event: Events.MobileAuthOtpNotificationEvent) => void,
    ): EmitterSubscription;
  addEventListener(
    eventType: Events.SdkNotification.Fingerprint,
    callback?: (event: Events.FingerprintNotificationEvent) => void,
    ): EmitterSubscription;
 __ ...
}
| Property | Type | Description | 
|---|---|---|
| eventType | SdkNotification | Name of the event e.g. Events.PinEvent | 
| callback | (event: Events.SdkEvent) => void | Callback function | 
Example handling PinEvent
const handleNotification = useCallback(
  async (event: Events.PinEvent) => {
    console.log('handle PIN notification event: ', event);
    __ Handling the events with a switch on the event.action will result in type inference.
    switch (event.action) {
      case Events.Pin.Open:
        await handleOpen(event);
        break;
      case Events.Pin.Close:
        setInitialState();
        break;
      case Events.Pin.IncorrectPin:
        handleIncorrectPin(event);
        break;
      case Events.Pin.PinNotAllowed:
        handlePinNotAllowed(event);
        break;
    }
  },
  [handleOpen, setConfirmState, handleError, setInitialState],
);
useEffect(() => {
  const listener = OnewelcomeSdk.addEventListener(
    Events.SdkNotification.Pin,
    handleNotification,
  );
  return () => {
    listener.remove();
  };
}, [handleNotification]);
Handling the Events with a switch as in the example is the prefered way as this allows for automatic type inference of the events.
See below for a list of all the event signatures.
export type SdkEvent =
  | PinCreateEvent
  | PinAuthenticationEvent
  | CustomRegistrationEvent
  | FingerprintEvent
  | MobileAuthOtpEvent
  | RegistrationURLEvent;
__ Pin
export type PinCreateEvent =
  | PinCreateCloseEvent
  | PinCreateOpenEvent
  | PinNotAllowedEvent;
export type PinAuthenticationEvent =
  | PinAuthenticationCloseEvent
  | PinAuthenticationOpenEvent
  | IncorrectPinEvent;
__ Create Pin
export type PinCreateCloseEvent = {
  action: PinCreate.Close;
  flow: PinFlow.Create;
};
export type PinCreateOpenEvent = {
  flow: PinFlow.Create;
  action: PinCreate.Open;
  profileId: string;
  pinLength: number;
};
export type PinNotAllowedEvent = {
  flow: PinFlow.Create;
  action: PinCreate.PinNotAllowed;
  errorType: number;
  errorMsg: string;
};
__ Authentication Pin
export type PinAuthenticationCloseEvent = {
  action: PinAuthentication.Close;
  flow: PinFlow.Authentication;
};
export type PinAuthenticationOpenEvent = {
  flow: PinFlow.Authentication;
  action: PinAuthentication.Open;
  profileId: string;
};
export type IncorrectPinEvent = {
  flow: PinFlow.Authentication;
  action: PinAuthentication.IncorrectPin;
  errorType: number;
  errorMsg: string;
  remainingFailureCount: number;
};
__Registration
export type RegistrationURLEvent = {
  url: string;
};
__CustomRegistration
export type CustomRegistrationEvent =
  | initRegistrationEvent
  | finishRegistrationEvent;
export type initRegistrationEvent = {
  action: CustomRegistration.InitRegistration;
  identityProviderId: string;
  customInfo?: {
    data: string;
    status: number;
  };
};
export type finishRegistrationEvent = {
  action: CustomRegistration.FinishRegistration;
  identityProviderId: string;
  customInfo?: {
    data: string;
    status: number;
  };
};
__MobileAuthOtp
export type MobileAuthOtpEvent =
  | startOtpAuthenticationEvent
  | finishOtpAuthenticationEvent;
export type startOtpAuthenticationEvent = {
  action: MobileAuthOtp.StartAuthentication;
  mobileAuthenticationRequest: {
    message: string;
    type: string;
    transactionId: string;
    signingData: string;
  };
};
export type finishOtpAuthenticationEvent = {
  action: MobileAuthOtp.FinishAuthentication;
  mobileAuthenticationRequest: {
    message: string;
    type: string;
    transactionId: string;
    signingData: string;
  };
};
__FingerPrint
export type FingerprintEvent =
  | startFingerprintAuthenticationEvent
  | onNextFingerprintAuthenticationAttemptEvent
  | onFingerprintCapturedEvent
  | finishFingerprintAuthenticationEvent;
export type startFingerprintAuthenticationEvent = {
  action: Fingerprint.StartAuthentication;
  userProfile: {
    profileId: string;
  };
};
export type onNextFingerprintAuthenticationAttemptEvent = {
  action: Fingerprint.OnNextAuthenticationAttempt;
};
export type onFingerprintCapturedEvent = {
  action: Fingerprint.OnFingerprintCaptured;
};
export type finishFingerprintAuthenticationEvent = {
  action: Fingerprint.FinishAuthentication;
};