Hi there,
I’ve been struggling with this for a while, so reaching out to the community to see if anyone else has a solution. I implemented Facebook Native Ads according to the documentation and have them showing up in my production app on iOS and Android. I’m on Expo SDK 31. When I navigate away from the screen the ads are on, the app throws this exception and crashes (this is the relevant part of the error):
[16:03:27] Error: Error: Error: Error: Error: Got unexpected null
This error is located at:
in TouchableOpacity (at AdTriggerView.js:52)
in AdTriggerView (at FacebookNativeAdCard.js:30)
in FacebookNativeAdCard (at withNativeAd.js:98)
in CTKNativeAd (at withNativeAd.js:94)
in NativeAdContainer (at HomeScreen.js:56)
Here’s the component that renders the ad:
import React, { PureComponent } from 'react';
import { View, Text } from 'react-native';
import { FacebookAds } from 'expo';
const { AdTriggerView, AdMediaView, AdIconView } = FacebookAds;
class FacebookNativeAdCard extends PureComponent {
render() {
if (!this.props.nativeAd) return null;
const {
advertiserName,
headline,
bodyText,
sponsoredTranslation
} = this.props.nativeAd;
if (!advertiserName || !headline || !bodyText || !sponsoredTranslation) return null;
const { containerStyleSmallHorizontal, imageStyleSmallHorizontal } = styles;
return (
<AdTriggerView style={containerStyleSmallHorizontal}>
<View style={{ flex: 1 }}>
<Text>{advertiserName}</Text>
<Text numberOfLines={4}>{headline}</Text>
<Text>{bodyText}</Text>
<Text>{sponsoredTranslation}</Text>
</View>
<AdMediaView style={imageStyleSmallHorizontal} />
<AdIconView style={{ width: 0, height: 0 }} />
</AdTriggerView>
);
}
}
const styles = {
...
};
export default FacebookAds.withNativeAd(FacebookNativeAdCard);
Even before seeing this error, there seems to be some weird stuff going on with the FacebookAds modules. According to the documentation, you need to include AdMediaView in the child tree for the AdTriggerView to work. But I actually found that the AdIconView also needed to be included. If it wasn’t, the AdMediaView was blank and the AdTriggerView wasn’t clickable. That’s why you see the “height: 0, width: 0” on the AdIconView component in my code. I had to include it in there otherwise nothing would work.
Unfortunately, after getting it to work, it throws the above error when I navigate away from the screen the ads appear.
I was poking around in the AdTriggerView code and there seem to be two places where “nullthrows” is used. I’m guessing one of those is throwing the error. Not sure which one it is or why.
Any idea why this might be happening? Any suggestions on how to resolve or dig in further to pinpoint what’s causing the error?