import nullthrows from 'nullthrows'; import React from 'react'; import { TouchableOpacity } from 'react-native'; import { AdTriggerViewContext, AdTriggerViewContextValue } from './withNativeAd'; type TouchableProps = { onPress?: (...args: any[]) => any; }; type AdTriggerViewProps
= { renderInteractiveComponent?: (props: P) => React.ReactElement
;
} & P;
export default class AdTriggerView<
P extends TouchableProps = React.ComponentProps | null = null;
render() {
return (
| null): void => {
if (component) {
this._trigger = component;
context.registerComponent(component);
} else {
context.unregisterComponent(nullthrows(this._trigger));
this._trigger = null;
}
},
// Notify the ad manager to trigger the ad
onPress(...args: any[]): any {
context.onTriggerAd();
if (forwardedProps.onPress) {
return forwardedProps.onPress(...args);
}
},
});
return this.props.renderInteractiveComponent
? this.props.renderInteractiveComponent(props)
: this._renderDefaultInteractiveComponent(props);
}}
{
// @ts-ignore: the RN TypeScript declarations are missing the "collapsable" prop
return