Skip to content

Commit

Permalink
Merge pull request #105 from NZME/fix/typescript-npm-prepare-error
Browse files Browse the repository at this point in the history
Changes are to solve errors spit out from command npm run prepare
  • Loading branch information
aleccolville-nzme authored Jun 22, 2023
2 parents a6093f6 + ab72a58 commit 8baa226
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/CTKAdManagerBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
findNodeHandle,
NativeSyntheticEvent,
DeviceEventEmitter,
EventSubscription
} from 'react-native';
import { createErrorFromErrorData } from './utils';
import type {
Expand Down Expand Up @@ -56,7 +57,7 @@ interface IAdManagerBannerPropsBase extends ViewProps {
interface IAdManagerBannerProps extends IAdManagerBannerPropsBase {
// onError is a callback function sent from parent RN component of your RN app, aka: the error handler.
// so if your RN App wants to handle the error, please pass in the "onError" function.
onError?: () => void;
onError?: (eventData: Error) => void;
/**
* DFP library events
*/
Expand All @@ -74,6 +75,7 @@ interface IAdManagerBannerState {
width?: number;
height?: number;
};
error: Error | null;
}

interface IAdManagerBannerNativeProps extends IAdManagerBannerPropsBase {
Expand Down Expand Up @@ -106,12 +108,16 @@ export class Banner extends React.Component<
IAdManagerBannerProps,
IAdManagerBannerState
> {
hasOnErrorFromParent: boolean;
customListener: EventSubscription | undefined;

constructor(props: IAdManagerBannerProps) {
super(props);
this.hasOnErrorFromParent = Object.prototype.hasOwnProperty.call(props, 'onError');
this.handleSizeChange = this.handleSizeChange.bind(this);
this.state = {
style: {},
error: null,
};
}

Expand All @@ -133,15 +139,17 @@ export class Banner extends React.Component<
componentDidMount() {
this.customListener= DeviceEventEmitter.addListener('onError',eventData=>{
this.setState({ error: eventData });
if (this.hasOnErrorFromParent) {
this.props?.onError(eventData);
if (this.hasOnErrorFromParent && this.props.onError) {
this.props.onError(eventData);
}
});
this.loadBanner();
}

componentWillUnmount() {
this.customListener.remove();
componentWillUnmount() {
if (this.customListener) {
this.customListener.remove();
}
}

loadBanner() {
Expand Down

0 comments on commit 8baa226

Please sign in to comment.