diff --git a/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsNativeModule.kt b/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsNativeModule.kt index f1fb2194..54702b12 100644 --- a/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsNativeModule.kt +++ b/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsNativeModule.kt @@ -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 } @@ -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 @@ -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) diff --git a/ios/RNGoogleMobileAds/RNGoogleMobileAdsNativeModule.mm b/ios/RNGoogleMobileAds/RNGoogleMobileAdsNativeModule.mm index 217b970b..50882179 100644 --- a/ios/RNGoogleMobileAds/RNGoogleMobileAdsNativeModule.mm +++ b/ios/RNGoogleMobileAds/RNGoogleMobileAdsNativeModule.mm @@ -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; @@ -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 diff --git a/src/common/validate.ts b/src/common/validate.ts index 941943e7..4b84f09e 100644 --- a/src/common/validate.ts +++ b/src/common/validate.ts @@ -105,3 +105,7 @@ export function isOneOf(value: unknown, oneOf: unknown[] = []) { } return oneOf.includes(value); } + +export function isNumber(value: unknown) { + return typeof value === 'number'; +} diff --git a/src/types/NativeAdRequestOptions.ts b/src/types/NativeAdRequestOptions.ts index 255355f0..e76b624b 100644 --- a/src/types/NativeAdRequestOptions.ts +++ b/src/types/NativeAdRequestOptions.ts @@ -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; } diff --git a/src/validateAdRequestOptions.ts b/src/validateAdRequestOptions.ts index 820a3fb4..e7d50c76 100644 --- a/src/validateAdRequestOptions.ts +++ b/src/validateAdRequestOptions.ts @@ -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}`, }; @@ -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; }