Skip to content

Commit d6ef5e2

Browse files
dylancomDominik Hinc
andcommitted
fix: passing native ad request options to native side (split from #782)
Co-authored-by: Dominik Hinc <[email protected]>
1 parent 8a6a13d commit d6ef5e2

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

src/ads/native-ad/NativeAd.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import NativeGoogleMobileAdsNativeModule, {
2727
NativeMediaContent,
2828
} from '../../specs/modules/NativeGoogleMobileAdsNativeModule';
2929
import { NativeAdRequestOptions } from '../../types';
30-
import { validateAdRequestOptions } from '../../validateAdRequestOptions';
30+
import { validateNativeAdRequestOptions } from '../../validateNativeAdRequestOptions';
3131

3232
/**
3333
* A class for loading Native Ads.
@@ -138,7 +138,7 @@ export class NativeAd {
138138

139139
let options = {};
140140
try {
141-
options = validateAdRequestOptions(requestOptions);
141+
options = validateNativeAdRequestOptions(requestOptions);
142142
} catch (e) {
143143
if (e instanceof Error) {
144144
throw new Error(`NativeAd.createForAdRequest(_, *) ${e.message}.`);

src/common/validate.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,12 @@ export function isOneOf(value: unknown, oneOf: unknown[] = []) {
105105
}
106106
return oneOf.includes(value);
107107
}
108+
109+
/**
110+
* Simple is number check
111+
* @param value
112+
* @return {boolean}
113+
*/
114+
export function isNumber(value: unknown) {
115+
return typeof value === 'number';
116+
}

src/validateNativeAdRequestOptions.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2016-present Invertase Limited & Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this library except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
import { isBoolean, isUndefined, isNumber } from './common';
19+
import { validateAdRequestOptions } from './validateAdRequestOptions';
20+
import type { NativeAdRequestOptions } from './types/NativeAdRequestOptions';
21+
22+
export function validateNativeAdRequestOptions(
23+
options?: NativeAdRequestOptions,
24+
): NativeAdRequestOptions {
25+
const base = validateAdRequestOptions(options);
26+
const out: NativeAdRequestOptions = { ...base };
27+
28+
if (!isUndefined(options?.adChoicesPlacement)) {
29+
if (!isNumber(options.adChoicesPlacement)) {
30+
throw new Error("'options.adChoicesPlacement' expected a number value");
31+
}
32+
out.adChoicesPlacement = options.adChoicesPlacement;
33+
}
34+
35+
if (!isUndefined(options?.aspectRatio)) {
36+
if (!isNumber(options.aspectRatio)) {
37+
throw new Error("'options.aspectRatio' expected a number value");
38+
}
39+
out.aspectRatio = options.aspectRatio;
40+
}
41+
42+
if (!isUndefined(options?.startVideoMuted)) {
43+
if (!isBoolean(options.startVideoMuted)) {
44+
throw new Error("'options.startVideoMuted' expected a boolean value");
45+
}
46+
out.startVideoMuted = options.startVideoMuted;
47+
}
48+
49+
return out;
50+
}

0 commit comments

Comments
 (0)