Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ class ReactNativeGoogleMobileAdsNativeModule(
val mediaAspectRatio = if (requestOptions.hasKey("aspectRatio")) {
when (requestOptions.getInt("aspectRatio")) {
1 -> MediaAspectRatio.ANY
2 -> MediaAspectRatio.PORTRAIT
3 -> MediaAspectRatio.LANDSCAPE
2 -> MediaAspectRatio.LANDSCAPE
3 -> MediaAspectRatio.PORTRAIT
4 -> MediaAspectRatio.SQUARE
else -> MediaAspectRatio.UNKNOWN
}
Expand All @@ -155,8 +155,8 @@ class ReactNativeGoogleMobileAdsNativeModule(
}
val adChoicesPlacement = if (requestOptions.hasKey("adChoicesPlacement")) {
when (requestOptions.getInt("adChoicesPlacement")) {
0 -> NativeAdOptions.ADCHOICES_TOP_RIGHT
1 -> NativeAdOptions.ADCHOICES_TOP_LEFT
0 -> NativeAdOptions.ADCHOICES_TOP_LEFT
1 -> NativeAdOptions.ADCHOICES_TOP_RIGHT
2 -> NativeAdOptions.ADCHOICES_BOTTOM_RIGHT
3 -> NativeAdOptions.ADCHOICES_BOTTOM_LEFT
else -> NativeAdOptions.ADCHOICES_TOP_RIGHT
Expand All @@ -169,8 +169,14 @@ class ReactNativeGoogleMobileAdsNativeModule(
} else {
true
}
val customControlsRequested = if (requestOptions.hasKey("customControlsRequested")) {
requestOptions.getBoolean("customControlsRequested")
} else {
false
}
val videoOptions = VideoOptions.Builder()
.setStartMuted(startVideoMuted)
.setCustomControlsRequested(customControlsRequested)
.build()
val nativeAdOptions = NativeAdOptions.Builder()
// .setReturnUrlsForImageAssets(true)
Expand Down
7 changes: 5 additions & 2 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsNativeModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ - (instancetype)initWithNativeModule:(RNGoogleMobileAdsNativeModule *)nativeModu
}
}
GADNativeAdViewAdOptions *adViewOptions = [[GADNativeAdViewAdOptions alloc] init];
if (requestOptions[@"aspectRatio"]) {
switch ([requestOptions[@"aspectRatio"] intValue]) {
if (requestOptions[@"adChoicesPlacement"]) {
switch ([requestOptions[@"adChoicesPlacement"] intValue]) {
case 0:
adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionTopLeftCorner;
break;
Expand All @@ -182,6 +182,9 @@ - (instancetype)initWithNativeModule:(RNGoogleMobileAdsNativeModule *)nativeModu
if (requestOptions[@"startVideoMuted"]) {
videoOptions.startMuted = [requestOptions[@"startVideoMuted"] boolValue];
}
if (requestOptions[@"customControlsRequested"]) {
videoOptions.customControlsRequested = [requestOptions[@"customControlsRequested"] boolValue];
}

_adLoader = [[GADAdLoader alloc]
initWithAdUnitID:adUnitId
Expand Down
4 changes: 4 additions & 0 deletions src/common/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,7 @@ export function isOneOf(value: unknown, oneOf: unknown[] = []) {
}
return oneOf.includes(value);
}

export function isNumber(value: unknown) {
return typeof value === 'number';
}
8 changes: 8 additions & 0 deletions src/types/NativeAdRequestOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,12 @@ export interface NativeAdRequestOptions extends RequestOptions {
* - When enabled, your app requests that the video should begin with audio muted.
*/
startVideoMuted?: boolean;

/**
* Disables or enables the custom controls for the video.
* - The custom controls are enabled by default.
* - When disabled, your app requests that the video should not have custom controls.
* - When enabled, your app requests that the video should have custom controls.
*/
customControlsRequested?: boolean;
}
34 changes: 32 additions & 2 deletions src/validateAdRequestOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ import {
isString,
isUndefined,
isValidUrl,
isNumber,
} from './common';
import { version } from './version';
import { RequestOptions } from './types/RequestOptions';
import { NativeAdRequestOptions } from './types/NativeAdRequestOptions';

export function validateAdRequestOptions(options?: RequestOptions) {
const out: RequestOptions = {
export function validateAdRequestOptions(options?: RequestOptions & NativeAdRequestOptions) {
const out: RequestOptions & NativeAdRequestOptions = {
requestAgent: `rn-invertase-${version}`,
};

Expand Down Expand Up @@ -136,5 +138,33 @@ export function validateAdRequestOptions(options?: RequestOptions) {
out.publisherProvidedId = options.publisherProvidedId;
}

if (!isUndefined(options?.adChoicesPlacement)) {
if (!isNumber(options.adChoicesPlacement)) {
throw new Error("'options.adChoicesPlacement' expected a number value");
}
out.adChoicesPlacement = options.adChoicesPlacement;
}

if (!isUndefined(options?.aspectRatio)) {
if (!isNumber(options.aspectRatio)) {
throw new Error("'options.aspectRatio' expected a number value");
}
out.aspectRatio = options.aspectRatio;
}

if (!isUndefined(options?.startVideoMuted)) {
if (!isBoolean(options.startVideoMuted)) {
throw new Error("'options.startVideoMuted' expected a boolean value");
}
out.startVideoMuted = options.startVideoMuted;
}

if (!isUndefined(options?.customControlsRequested)) {
if (!isBoolean(options.customControlsRequested)) {
throw new Error("'options.customControlsRequested' expected a boolean value");
}
out.customControlsRequested = options.customControlsRequested;
}

return out;
}
Loading