expo react native back、forward和AdMobinterstial for webview应用程序

laik7k3q  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(289)

我有这个安卓网络视图应用。我提出了一些函数。然后,它停止显示广告。广告是间隙广告。
我做了一些改变。然后,它显示广告,但没有返回功能。。。

import React, { Component } from 'react';
import { BackHandler} from 'react-native';
import { WebView } from 'react-native-webview';
import { AdMobInterstitial, AdMobBanner } from 'expo-ads-admob';
// ...
class MyWebComponent extends Component {
  webView = {
    canGoBack: false,
    ref: null,
  }
  onAndroidBackPress = () => {
    if (this.webView.canGoBack && this.webView.ref) {
      this.webView.ref.goBack();
      return true;
    }
    return false;
  }
  componentDidMount() {
    if (Platform.OS === 'android') {
      BackHandler.addEventListener('hardwareBackPress', this.onAndroidBackPress);
    }
  }
  componentWillUnmount() {
    if (Platform.OS === 'android') {
      BackHandler.removeEventListener('hardwareBackPress');
    }
  }
}
export default class App extends React.Component {
adFunction = async () => {
AdMobInterstitial.setAdUnitID('ca-app-pub-'); 
await AdMobInterstitial.requestAdAsync({ servePersonalizedAds: true});
await AdMobInterstitial.showAdAsync();
}
componentDidMount() {
this.adFunction();
}
  render() {
    return (
      <WebView
        source={{ uri: "https://.com" }}
        ref={(webView) => { this.webView.ref = webView; }}
        onNavigationStateChange={(navState) => { this.webView.canGoBack = navState.canGoBack; }}
      />
    );
  }
}
export default MyWebComponent

谁能帮我一下吗?谢谢

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题