React-native-admob: Cannot read property 'style' of undefined

Created on 4 Aug 2018  路  9Comments  路  Source: sbugert/react-native-admob

Hi,

Trying to get AdMob working in a project and followed the steps to install but when ever I import this library using import { AdMobBanner } from 'react-native-admob' I get the error Cannot read property 'style' of undefined.

If I try and use the beta version I get a different error Invariant Violation: requireNativeComponent: "RNGADBannerView" was not found in the UIManager.

Any ideas what the problem is?

Thanks,
Gary

Most helpful comment

Problem in React.propTypes you can import prop-types and change AdMobBanner.propTypes and RNPublisherBanner.propTypes

import PropTypes from 'prop-types';

React.PropTypes.string -> PropTypes.string,

All 9 comments

Cannot read property 'style' of undefined
May In Code, you misplace or incorrectly spelling use of style.
Invariant Violation: requireNativeComponent: "RNGADBannerView" was not found in the UIManager.
The solution is to link your AdMob. i.e react-native link react-native-admob.
you can refer to this link:
https://react-native-solutions.blogspot.com/2018/08/problems-related-to-admob-updated.html

I did try numerous times to check the spelling of style but I wasn't actually referencing it anywhere.
That issue only appeared when I merely imported the library, not even using it.

Regarding the second error, I ran react-native link numerous times and would see the following but still got the error.

rnpm-install info Platform 'ios' module react-native-admob is already linked
rnpm-install info Platform 'android' module react-native-admob is already linked

@garyrutland, you did everything right.
can you send the piece of code and which RN version you using?

Apparently I'm using version 0.56.0 and this is the code for loading the ads:

import React, { Component } from 'react';
import { StyleSheet } from 'react-native';
import { View } from 'native-base';
import { AdMobBanner } from 'react-native-admob'

export default class AdsPartial extends Component {
  render() {
    const adUnitId = `***`;

    return (
      <View style={styles.ads}>
        <AdMobBanner
          adSize='banner'
          adUnitID={adUnitId}
          testDevices={[AdMobBanner.simulatorId]}/>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  ads: {
    padding: 5,
    alignItems: 'center',
    justifyContent: 'center',
    borderColor: '#a7a7ab',
    borderTopWidth: 1,
  },
});

Any update on this at all?

@garyrutland I do not think so. Because I tried everything but the same error continues and this plugin never worked :(

@sbugert Is anyone actively working on this project anymore?
It used to work but doesn't seem to anymore.

Problem in React.propTypes you can import prop-types and change AdMobBanner.propTypes and RNPublisherBanner.propTypes

import PropTypes from 'prop-types';

React.PropTypes.string -> PropTypes.string,
Was this page helpful?
0 / 5 - 0 ratings