@@ -14,6 +14,7 @@ import {
1414} from './contexts' ;
1515import { HasNativeAd , NativeAd } from './nativeAd' ;
1616import AdsManager from './NativeAdsManager' ;
17+ import { areSetsEqual } from '../util/areSetsEqual' ;
1718
1819interface NativeAdViewProps {
1920 adsManager : string ;
@@ -89,35 +90,36 @@ export default <T extends HasNativeAd>(
8990 ) ;
9091 }
9192
92- public componentDidUpdate (
93- prevProps : AdWrapperProps ,
94- prevState : AdWrapperState ,
95- ) {
93+ public componentDidUpdate ( _ : AdWrapperProps , prevState : AdWrapperState ) {
9694 if (
97- this . state . mediaViewNodeHandle !== - 1 ||
98- this . state . adIconViewNodeHandle !== - 1 ||
99- this . state . clickableChildren . size > 0
95+ this . state . mediaViewNodeHandle === - 1 ||
96+ this . state . adIconViewNodeHandle === - 1
10097 ) {
101- const mediaViewNodeHandleChanged =
102- this . state . mediaViewNodeHandle !== prevState . mediaViewNodeHandle ;
103- const adIconViewNodeHandleChanged =
104- this . state . adIconViewNodeHandle !== prevState . adIconViewNodeHandle ;
105- const clickableChildrenChanged = [
106- ...prevState . clickableChildren ,
107- ] . filter ( child => ! this . state . clickableChildren . has ( child ) ) ;
108-
109- if (
110- mediaViewNodeHandleChanged ||
111- adIconViewNodeHandleChanged ||
112- clickableChildrenChanged
113- ) {
114- AdsManager . registerViewsForInteractionAsync (
115- findNodeHandle ( this . nativeAdViewRef ! ) ! ,
116- this . state . mediaViewNodeHandle ,
117- this . state . adIconViewNodeHandle ,
118- [ ...this . state . clickableChildren ] ,
119- ) ;
120- }
98+ // Facebook's SDK requires both MediaView and AdIconView references in order to register
99+ // interactable views. If one of them is missing, we can't proceed with the registration.
100+ return ;
101+ }
102+
103+ const mediaViewNodeHandleChanged =
104+ this . state . mediaViewNodeHandle !== prevState . mediaViewNodeHandle ;
105+ const adIconViewNodeHandleChanged =
106+ this . state . adIconViewNodeHandle !== prevState . adIconViewNodeHandle ;
107+ const clickableChildrenChanged = areSetsEqual (
108+ prevState . clickableChildren ,
109+ this . state . clickableChildren ,
110+ ) ;
111+
112+ if (
113+ mediaViewNodeHandleChanged ||
114+ adIconViewNodeHandleChanged ||
115+ clickableChildrenChanged
116+ ) {
117+ AdsManager . registerViewsForInteractionAsync (
118+ findNodeHandle ( this . nativeAdViewRef ! ) ! ,
119+ this . state . mediaViewNodeHandle ,
120+ this . state . adIconViewNodeHandle ,
121+ [ ...this . state . clickableChildren ] ,
122+ ) ;
121123 }
122124 }
123125
0 commit comments