1 | import nullthrows from 'nullthrows';
|
2 | import React from 'react';
|
3 | import { TouchableOpacity } from 'react-native';
|
4 | import { AdTriggerViewContext } from './withNativeAd';
|
5 | export default class AdTriggerView extends React.Component {
|
6 | constructor() {
|
7 | super(...arguments);
|
8 | this._trigger = null;
|
9 | }
|
10 | render() {
|
11 | return (React.createElement(AdTriggerViewContext.Consumer, null, (contextValue) => {
|
12 | const context = nullthrows(contextValue);
|
13 |
|
14 | const forwardedProps = this._getForwardedProps();
|
15 | const props = Object.assign({}, forwardedProps, {
|
16 |
|
17 | ref: (component) => {
|
18 | if (component) {
|
19 | this._trigger = component;
|
20 | context.registerComponent(component);
|
21 | }
|
22 | else {
|
23 | context.unregisterComponent(nullthrows(this._trigger));
|
24 | this._trigger = null;
|
25 | }
|
26 | },
|
27 |
|
28 | onPress(...args) {
|
29 | context.onTriggerAd();
|
30 | if (forwardedProps.onPress) {
|
31 | return forwardedProps.onPress(...args);
|
32 | }
|
33 | },
|
34 | });
|
35 | return this.props.renderInteractiveComponent
|
36 | ? this.props.renderInteractiveComponent(props)
|
37 | : this._renderDefaultInteractiveComponent(props);
|
38 | }));
|
39 | }
|
40 |
|
41 |
|
42 |
|
43 | _getForwardedProps() {
|
44 | const { renderInteractiveComponent, ...props } = this.props;
|
45 | return props;
|
46 | }
|
47 |
|
48 | _renderDefaultInteractiveComponent(props) {
|
49 | return React.createElement(TouchableOpacity, Object.assign({}, props, { collapsable: false }));
|
50 | }
|
51 | }
|
52 |
|
\ | No newline at end of file |