Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
dylancom committed May 20, 2024
1 parent 1eaed70 commit ef35a9b
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 50 deletions.
10 changes: 6 additions & 4 deletions RNGoogleMobileAdsExample/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,6 @@ class BannerTest implements Test {
}

render(onMount: (component: any) => void): React.ReactNode {
const reload = () => {
this.bannerRef.current?.reload();
};
return (
<View ref={onMount}>
<BannerAd
Expand All @@ -225,7 +222,12 @@ class BannerTest implements Test {
);
}}
/>
<Button title="reload" onPress={reload} />
<Button
title="reload"
onPress={() => {
this.bannerRef.current?.load();
}}
/>
</View>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class ReactNativeGoogleMobileAdsBannerAdViewManager
private final String EVENT_SIZE_CHANGE = "onSizeChange";
private final String EVENT_APP_EVENT = "onAppEvent";
private final int COMMAND_ID_RECORD_MANUAL_IMPRESSION = 1;
private final int COMMAND_ID_RELOAD = 2;
private final int COMMAND_ID_LOAD = 2;

@Nonnull
@Override
Expand All @@ -88,7 +88,7 @@ public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
public Map<String, Integer> getCommandsMap() {
return MapBuilder.of(
"recordManualImpression", COMMAND_ID_RECORD_MANUAL_IMPRESSION,
"reload", COMMAND_ID_RELOAD);
"load", COMMAND_ID_LOAD);
}

@Override
Expand All @@ -102,7 +102,7 @@ public void receiveCommand(
if (adView instanceof AdManagerAdView) {
((AdManagerAdView) adView).recordManualImpression();
}
} else if (commandIdInt == COMMAND_ID_RELOAD) {
} else if (commandIdInt == COMMAND_ID_LOAD) {
BaseAdView adView = getAdView(reactViewGroup);
AdRequest request = reactViewGroup.getRequest();
adView.loadAd(request);
Expand Down
4 changes: 2 additions & 2 deletions docs/displaying-ads.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ import { BannerAd, BannerAdSize, TestIds } from 'react-native-google-mobile-ads'
const adUnitId = __DEV__ ? TestIds.ADAPTIVE_BANNER : 'ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy';

function App() {
const bannerRef = useRef<BannerAd>(null);
const bannerRef = useRef < BannerAd > null;
const appState = useRef(AppState.currentState);

// WKWebView can terminate if app is in a "suspended state", resulting in an empty banner when app returns to foreground.
Expand All @@ -415,7 +415,7 @@ function App() {
useEffect(() => {
const subscription = AppState.addEventListener('change', nextAppState => {
if (appState.current.match(/background/) && nextAppState === 'active') {
bannerRef.current?.reload();
bannerRef.current?.load();
}
appState.current = nextAppState;
});
Expand Down
2 changes: 1 addition & 1 deletion ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
@property(nonatomic, copy) RCTBubblingEventBlock onNativeEvent;

- (void)requestAd;
- (void)load;
- (void)recordManualImpression;
- (void)reload;

@end

Expand Down
9 changes: 2 additions & 7 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,10 @@ - (void)requestAd {
}];
}
};
[_banner loadRequest:[RNGoogleMobileAdsCommon buildAdRequest:_request]];
[self sendEvent:@"onSizeChange"
payload:@{
@"width" : @(_banner.bounds.size.width),
@"height" : @(_banner.bounds.size.height),
}];
[self loadAd];
}

- (void)reload {
- (void)loadAd {
[_banner loadRequest:[RNGoogleMobileAdsCommon buildAdRequest:_request]];
[self sendEvent:@"onSizeChange"
payload:@{
Expand Down
40 changes: 15 additions & 25 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,27 @@ - (void)requestAd {
[self addSubview:_banner];
_banner.adUnitID = _unitId;
[self setRequested:YES];
[_banner loadRequest:[RNGoogleMobileAdsCommon buildAdRequest:_request]];
if (_eventEmitter != nullptr) {
std::dynamic_pointer_cast<const facebook::react::RNGoogleMobileAdsBannerViewEventEmitter>(
_eventEmitter)
->onNativeEvent(facebook::react::RNGoogleMobileAdsBannerViewEventEmitter::OnNativeEvent{
.type = "onSizeChange",
.width = _banner.bounds.size.width,
.height = _banner.bounds.size.height});
}
[self load];
}
}

- (void)load {
[_banner loadRequest:[RNGoogleMobileAdsCommon buildAdRequest:_request]];
if (_eventEmitter != nullptr) {
std::dynamic_pointer_cast<const facebook::react::RNGoogleMobileAdsBannerViewEventEmitter>(
_eventEmitter)
->onNativeEvent(facebook::react::RNGoogleMobileAdsBannerViewEventEmitter::OnNativeEvent{
.type = "onSizeChange",
.width = _banner.bounds.size.width,
.height = _banner.bounds.size.height});
}
}

- (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args {
if ([commandName isEqual:@"recordManualImpression"]) {
[self recordManualImpression];
} else if ([commandName isEqual:@"reload"]) {
[self reload];
} else if ([commandName isEqual:@"load"]) {
[self load];
}
}

Expand All @@ -172,20 +176,6 @@ - (void)recordManualImpression {
}
}

- (void)reload {
if ([_banner class] == [GAMBannerView class]) {
[_banner loadRequest:[RNGoogleMobileAdsCommon buildAdRequest:_request]];
if (_eventEmitter != nullptr) {
std::dynamic_pointer_cast<const facebook::react::RNGoogleMobileAdsBannerViewEventEmitter>(
_eventEmitter)
->onNativeEvent(facebook::react::RNGoogleMobileAdsBannerViewEventEmitter::OnNativeEvent{
.type = "onSizeChange",
.width = _banner.bounds.size.width,
.height = _banner.bounds.size.height});
}
}
}

#pragma mark - Events

- (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {
Expand Down
4 changes: 2 additions & 2 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ @implementation RNGoogleMobileAdsBannerViewManager
#endif
}

RCT_EXPORT_METHOD(reload : (nonnull NSNumber *)reactTag) {
RCT_EXPORT_METHOD(load : (nonnull NSNumber *)reactTag) {
#if !TARGET_OS_MACCATALYST
[self.bridge.uiManager
addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
Expand All @@ -64,7 +64,7 @@ @implementation RNGoogleMobileAdsBannerViewManager
RCTLogError(@"Cannot find NativeView with tag #%@", reactTag);
return;
}
[banner reload];
[banner load];
}];
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions src/ads/BannerAd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import GoogleMobileAdsBannerView, { Commands } from './GoogleMobileAdsBannerView
export class BannerAd extends React.Component<BannerAdProps> {
private ref = createRef<React.ElementRef<typeof GoogleMobileAdsBannerView>>();

reload() {
load() {
if (this.ref.current) {
Commands.reload(this.ref.current);
Commands.load(this.ref.current);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ads/GAMBannerAd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export class GAMBannerAd extends React.Component<GAMBannerAdProps> {
}
}

reload() {
load() {
if (this.ref.current) {
Commands.reload(this.ref.current);
Commands.load(this.ref.current);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ads/GoogleMobileAdsBannerViewNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export type ComponentType = HostComponent<NativeProps>;

interface NativeCommands {
recordManualImpression: (viewRef: React.ElementRef<ComponentType>) => void;
reload: (viewRef: React.ElementRef<ComponentType>) => void;
load: (viewRef: React.ElementRef<ComponentType>) => void;
}

export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['recordManualImpression', 'reload'],
supportedCommands: ['recordManualImpression', 'load'],
});

export default codegenNativeComponent<NativeProps>(
Expand Down

0 comments on commit ef35a9b

Please sign in to comment.