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gBACH,CAAC;aACF,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC,KAAK,CAAC,0BAA0B;gBAC1C,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,0BAA0B,CAAC,KAAK,CAAC;gBAC9C,CAAC,CAAC,IAAI,CAAC,kCAAkC,CAAC,KAAK,CAAC,CAAC;QACrD,CAAC,CAC6B,CACjC,CAAC;IACJ,CAAC;IAED,6FAA6F;IAC7F,+FAA+F;IAC/F,4BAA4B;IAC5B,kBAAkB;QAChB,MAAM,EAAE,0BAA0B,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,KAAY,CAAC;QACnE,OAAO,KAAU,CAAC;IACpB,CAAC;IAED,2EAA2E;IAC3E,kCAAkC,CAAC,KAAQ;QACzC,OAAO,oBAAC,gBAAgB,oBAAK,KAAK,IAAE,WAAW,EAAE,KAAK,IAAI,CAAC;IAC7D,CAAC;CACF","sourcesContent":["import nullthrows from 'nullthrows';\nimport React from 'react';\nimport { TouchableOpacity } from 'react-native';\n\nimport { AdTriggerViewContext, AdTriggerViewContextValue } from './withNativeAd';\n\ntype TouchableProps = {\n onPress?: (...args: any[]) => any;\n};\n\ntype AdTriggerViewProps<P> = {\n renderInteractiveComponent?: (props: P) => React.ReactElement<P>;\n} & P;\n\nexport default class AdTriggerView<\n P extends TouchableProps = React.ComponentProps<typeof TouchableOpacity>\n> extends React.Component<AdTriggerViewProps<P>> {\n _trigger: React.Component<P> | null = null;\n\n render() {\n return (\n <AdTriggerViewContext.Consumer>\n {(contextValue: AdTriggerViewContextValue | null) => {\n const context = nullthrows(contextValue);\n\n // Compute the context-dependent props to pass to the interactive component\n const forwardedProps = this._getForwardedProps();\n const props = Object.assign({}, forwardedProps, {\n // Register the trigger component with the ad manager when it is mounted and unmounted\n ref: (component: React.Component<P> | null): void => {\n if (component) {\n this._trigger = component;\n context.registerComponent(component);\n } else {\n context.unregisterComponent(nullthrows(this._trigger));\n this._trigger = null;\n }\n },\n\n // Notify the ad manager to trigger the ad\n onPress(...args: any[]): any {\n context.onTriggerAd();\n\n if (forwardedProps.onPress) {\n return forwardedProps.onPress(...args);\n }\n },\n });\n\n return this.props.renderInteractiveComponent\n ? this.props.renderInteractiveComponent(props)\n : this._renderDefaultInteractiveComponent(props);\n }}\n </AdTriggerViewContext.Consumer>\n );\n }\n\n // NOTE: This is a helper method to extract the props to forward to the interactive component\n // because TypeScript does not currently support rest objects with generic types in some cases,\n // hence the type assertions\n _getForwardedProps(): P {\n const { renderInteractiveComponent, ...props } = this.props as any;\n return props as P;\n }\n\n // TODO: change from TouchableOpacity to a Gesture Handler BorderlessButton\n _renderDefaultInteractiveComponent(props: P): React.ReactElement<P> {\n return <TouchableOpacity {...props} collapsable={false} />;\n }\n}\n"]}
\No newline at end of file