Skip to content

Commit

Permalink
fix!: move GAM-exclusive FLUID type to new GAMBanner const
Browse files Browse the repository at this point in the history
  • Loading branch information
dylancom authored and mikehardy committed Jan 10, 2023
1 parent 5f9b5c2 commit 85545f6
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 11 deletions.
29 changes: 29 additions & 0 deletions __tests__/banner.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { render } from '@testing-library/react-native';
import { BannerAd, BannerAdSize } from '../src';

const MOCK_ID = 'MOCK_ID';

describe('Google Mobile Ads Banner', function () {
it('throws if no unit ID was provided.', function () {
let errorMsg;
try {
render(<BannerAd unitId="" size={BannerAdSize.BANNER} />);
} catch (e) {
errorMsg = e.message;
}
expect(errorMsg).toEqual("BannerAd: 'unitId' expected a valid string unit ID.");
});

it('throws if size does not exist.', function () {
let errorMsg;
try {
render(<BannerAd unitId={MOCK_ID} size="NON_EXISTENT_SIZE" />);
} catch (e) {
errorMsg = e.message;
}
expect(errorMsg).toEqual(
"BannerAd: 'size(s)' expected a valid BannerAdSize or custom size string.",
);
});
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"@semantic-release/github": "^8.0.6",
"@semantic-release/npm": "^9.0.1",
"@semantic-release/release-notes-generator": "^10.0.3",
"@testing-library/react-native": "^11.5.0",
"@types/jest": "^29.2.0",
"@types/node": "^18.11.7",
"@types/react": "^18.0.24",
Expand All @@ -142,6 +143,7 @@
"react": "^18.2.0",
"react-native": "0.70.4",
"react-native-builder-bob": "^0.20.0",
"react-test-renderer": "^18.2.0",
"rimraf": "^3.0.2",
"semantic-release": "^19.0.5",
"shelljs": "^0.8.5",
Expand Down
14 changes: 9 additions & 5 deletions src/BannerAdSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ export enum BannerAdSize {
*/
INLINE_ADAPTIVE_BANNER = 'INLINE_ADAPTIVE_BANNER',

/**
* A dynamically sized banner that matches its parent's width and expands/contracts its height to match the ad's content after loading completes.
*/
FLUID = 'FLUID',

/**
* IAB wide skyscraper ad size (160x600 density-independent pixels). This size is currently not supported by the Google Mobile Ads network; this is intended for mediation ad networks only.
*/
WIDE_SKYSCRAPER = 'WIDE_SKYSCRAPER',
}

export const GAMBannerAdSize = {
...BannerAdSize,

/**
* A dynamically sized banner that matches its parent's width and expands/contracts its height to match the ad's content after loading completes.
*/
FLUID: 'FLUID',
} as const;
8 changes: 5 additions & 3 deletions src/ads/BaseAd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import React, { useState, useEffect } from 'react';
import { NativeMethods, requireNativeComponent } from 'react-native';
import { isFunction } from '../common';
import { NativeError } from '../internal/NativeError';
import { BannerAdSize } from '../BannerAdSize';
import { BannerAdSize, GAMBannerAdSize } from '../BannerAdSize';
import { validateAdRequestOptions } from '../validateAdRequestOptions';
import { GAMBannerAdProps } from '../types/BannerAdProps';
import { RequestOptions } from '../types/RequestOptions';
Expand Down Expand Up @@ -58,7 +58,9 @@ export const BaseAd = React.forwardRef<GoogleMobileAdsBannerView, GAMBannerAdPro
useEffect(() => {
if (
sizes.length === 0 ||
!sizes.every(size => size in BannerAdSize || sizeRegex.test(size))
!sizes.every(
size => size in BannerAdSize || size in GAMBannerAdSize || sizeRegex.test(size),
)
) {
throw new Error("BannerAd: 'size(s)' expected a valid BannerAdSize or custom size string.");
}
Expand Down Expand Up @@ -113,7 +115,7 @@ export const BaseAd = React.forwardRef<GoogleMobileAdsBannerView, GAMBannerAdPro
}
}

const style = sizes.includes(BannerAdSize.FLUID)
const style = sizes.includes(GAMBannerAdSize.FLUID)
? {
width: '100%',
height: dimensions[1],
Expand Down
4 changes: 2 additions & 2 deletions src/types/BannerAdProps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BannerAdSize } from '../BannerAdSize';
import { BannerAdSize, GAMBannerAdSize } from '../BannerAdSize';
import { AppEvent } from './AppEvent';
import { RequestOptions } from './RequestOptions';

Expand Down Expand Up @@ -111,7 +111,7 @@ export interface GAMBannerAdProps extends Omit<BannerAdProps, 'size'> {
*
* Inventory must be available for the banner sizes specified, otherwise a no-fill error will be sent to `onAdFailedToLoad`.
*/
sizes: BannerAdSize[] | string[];
sizes: typeof GAMBannerAdSize[keyof typeof GAMBannerAdSize][] | string[];

/**
* Whether to enable the manual impression counting.
Expand Down
25 changes: 24 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2808,6 +2808,13 @@
dependencies:
"@sinonjs/commons" "^1.7.0"

"@testing-library/react-native@^11.5.0":
version "11.5.0"
resolved "https://registry.yarnpkg.com/@testing-library/react-native/-/react-native-11.5.0.tgz#b043c5db7b15eca42a65e95d3f3ae196fab9493b"
integrity sha512-seV+qebsbX4E5CWk/wizU1+2wVLsPyqEzG7sTgrhJ81cgAawg7ay06fIZR9IS75pDeWn2KZVd4mGk1pjJ3i3Zw==
dependencies:
pretty-format "^29.0.0"

"@tootallnate/once@2":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf"
Expand Down Expand Up @@ -9335,7 +9342,7 @@ [email protected]:
shell-quote "^1.6.1"
ws "^7"

"react-is@^16.12.0 || ^17.0.0 || ^18.0.0", react-is@^18.0.0:
"react-is@^16.12.0 || ^17.0.0 || ^18.0.0", react-is@^18.0.0, react-is@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"
integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==
Expand Down Expand Up @@ -9443,6 +9450,15 @@ react-shallow-renderer@^16.15.0:
object-assign "^4.1.1"
react-is "^16.12.0 || ^17.0.0 || ^18.0.0"

react-test-renderer@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-18.2.0.tgz#1dd912bd908ff26da5b9fca4fd1c489b9523d37e"
integrity sha512-JWD+aQ0lh2gvh4NM3bBM42Kx+XybOxCpgYK7F8ugAlpaTSnWsX+39Z4XkOykGZAHrjwwTZT3x3KxswVWxHPUqA==
dependencies:
react-is "^18.2.0"
react-shallow-renderer "^16.15.0"
scheduler "^0.23.0"

react@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
Expand Down Expand Up @@ -9858,6 +9874,13 @@ scheduler@^0.22.0:
dependencies:
loose-envify "^1.1.0"

scheduler@^0.23.0:
version "0.23.0"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.23.0.tgz#ba8041afc3d30eb206a487b6b384002e4e61fdfe"
integrity sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==
dependencies:
loose-envify "^1.1.0"

semantic-release@^19.0.5:
version "19.0.5"
resolved "https://registry.yarnpkg.com/semantic-release/-/semantic-release-19.0.5.tgz#d7fab4b33fc20f1288eafd6c441e5d0938e5e174"
Expand Down

0 comments on commit 85545f6

Please sign in to comment.