Skip to content

Commit

Permalink
disallow banner views from having subviews
Browse files Browse the repository at this point in the history
  • Loading branch information
koenpunt committed Sep 29, 2017
1 parent ea1151a commit 9b7ae3a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
Expand All @@ -10,8 +11,8 @@
import com.facebook.react.bridge.ReadableNativeArray;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.facebook.react.views.view.ReactViewGroup;
Expand All @@ -26,8 +27,6 @@

class ReactAdView extends ReactViewGroup {

private Context mContext;

protected AdView adView;

String adUnitID;
Expand Down Expand Up @@ -154,7 +153,7 @@ public void setAdSize(AdSize adSize) {
}
}

public class RNAdMobBannerViewManager extends SimpleViewManager<ReactAdView> {
public class RNAdMobBannerViewManager extends ViewGroupManager<ReactAdView> {

public static final String REACT_CLASS = "RNGADBannerView";

Expand Down Expand Up @@ -185,6 +184,11 @@ protected ReactAdView createViewInstance(ThemedReactContext themedReactContext)
return adView;
}

@Override
public void addView(ReactAdView parent, View child, int index) {
throw new RuntimeException("RNAdMobBannerView cannot have subviews");
}

@Override
@Nullable
public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
Expand Down
Expand Up @@ -2,7 +2,7 @@

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
Expand All @@ -11,8 +11,8 @@
import com.facebook.react.bridge.ReadableNativeArray;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.facebook.react.views.view.ReactViewGroup;
Expand All @@ -28,8 +28,6 @@

class ReactPublisherAdView extends ReactViewGroup implements AppEventListener {

private Context mContext;

protected PublisherAdView adView;

String[] testDevices;
Expand Down Expand Up @@ -188,7 +186,7 @@ public void onAppEvent(String name, String info) {
}
}

public class RNPublisherBannerViewManager extends SimpleViewManager<ReactPublisherAdView> {
public class RNPublisherBannerViewManager extends ViewGroupManager<ReactPublisherAdView> {

public static final String REACT_CLASS = "RNDFPBannerView";

Expand Down Expand Up @@ -221,6 +219,11 @@ protected ReactPublisherAdView createViewInstance(ThemedReactContext themedReact
return adView;
}

@Override
public void addView(ReactPublisherAdView parent, View child, int index) {
throw new RuntimeException("RNPublisherBannerView cannot have subviews");
}

@Override
@Nullable
public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
Expand Down
10 changes: 10 additions & 0 deletions ios/RNDFPBannerView.m
Expand Up @@ -3,9 +3,11 @@
#if __has_include(<React/RCTBridgeModule.h>)
#import <React/RCTBridgeModule.h>
#import <React/UIView+React.h>
#import <React/RCTLog.h>
#else
#import "RCTBridgeModule.h"
#import "UIView+React.h"
#import "RCTLog.h"
#endif

#include "RCTConvert+GADAdSize.h"
Expand Down Expand Up @@ -41,6 +43,14 @@ - (instancetype)initWithFrame:(CGRect)frame
return self;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-missing-super-calls"
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex
{
RCTLogError(@"RNDFPBannerView cannot have subviews");
}
#pragma clang diagnostic pop

- (void)loadBanner {
GADRequest *request = [GADRequest request];
request.testDevices = _testDevices;
Expand Down
10 changes: 10 additions & 0 deletions ios/RNGADBannerView.m
Expand Up @@ -3,9 +3,11 @@
#if __has_include(<React/RCTBridgeModule.h>)
#import <React/RCTBridgeModule.h>
#import <React/UIView+React.h>
#import <React/RCTLog.h>
#else
#import "RCTBridgeModule.h"
#import "UIView+React.h"
#import "RCTLog.h"
#endif

@implementation RNGADBannerView
Expand Down Expand Up @@ -34,6 +36,14 @@ - (instancetype)initWithFrame:(CGRect)frame
return self;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-missing-super-calls"
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex
{
RCTLogError(@"RNGADBannerView cannot have subviews");
}
#pragma clang diagnostic pop

- (void)loadBanner
{
if(self.onSizeChange) {
Expand Down

0 comments on commit 9b7ae3a

Please sign in to comment.