Skip to content

Commit

Permalink
chore: name is react-native-google-ads, config is app.json
Browse files Browse the repository at this point in the history
Related #2
  • Loading branch information
mikehardy committed Sep 4, 2021
1 parent a0c2041 commit 799fae0
Show file tree
Hide file tree
Showing 90 changed files with 678 additions and 694 deletions.
18 changes: 10 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Introduction

First, thank you for considering contributing to React Native Admob! It's people like you that make the open source community such a great community! 😊
First, thank you for considering contributing to React Native Google Ads! It's people like you that make the open source community such a great community! 😊

We welcome any type of contribution, not just code. You can help with;

- **QA**: file bug reports, the more details you can give the better (e.g. platform versions, screenshots SDK versions & logs)
- **COMING SOON** **Docs**: improve reference coverage, add more examples, fix typos or anything else you can spot.
- At the top of every page on our docs site you can click the `Edit Page` button to go to that pages markdown file or TypeScript definition file, or view the [documents](https://github.com/invertase/react-native-admob/tree/main/docs) directly
- At the top of every page on our docs site you can click the `Edit Page` button to go to that pages markdown file or TypeScript definition file, or view the [documents](https://github.com/invertase/react-native-google-ads/tree/main/docs) directly
- **Community**: presenting the project at meetups, organizing a dedicated meetup for the local community, ...
- **Code**: take a look at the [open issues](issues). Even if you can't write code, commenting on them, showing that you care about a given issue matters.

Expand Down Expand Up @@ -92,13 +92,15 @@ To get started locally the following steps are required:
### Step 1: Clone the repository

```bash
git clone https://github.com/invertase/react-native-admob.git
cd react-native-admob
git clone https://github.com/invertase/react-native-google-ads.git
cd react-native-google-ads
```

### Step 2: Install test project dependencies

COMING SOON apologies
```bash
yarn
```

---

Expand All @@ -119,10 +121,10 @@ in this format; however your commits themselves do not need to follow this forma

#### Examples

- `docs(analytics): added extra example for logEvent`
- `docs(consent, ios): added extra example for GDPR flow on iOS`
- `tests(perf): should throw invalid arg error`
- `fix(firestore,android): fixed NPE crash`
- `feat(functions): add support for function timeouts`
- `fix(insterstial, android): fixed NPE crash`
- `feat(video): add support for video load timeouts`

See the [Conventional Commits](https://www.conventionalcommits.org/) specification for more information.

Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<!-- <a href="https://rnfirebase.io">
<img width="160px" src="https://i.imgur.com/JIyBtKW.png"><br/>
</a> -->
<h2 align="center">React Native Admob</h2>
<h2 align="center">React Native Google Ads</h2>
</p>

<p align="center">
<a href="https://www.npmjs.com/package/@invertase/react-native-admob"><img src="https://img.shields.io/npm/dm/@invertase/react-native-admob.svg?style=flat-square" alt="NPM downloads"></a>
<a href="https://www.npmjs.com/package/@invertase/react-native-admob"><img src="https://img.shields.io/npm/v/@invertase/react-native-admob.svg?style=flat-square" alt="NPM version"></a>
<a href="/LICENSE"><img src="https://img.shields.io/npm/l/@invertase/react-native-admob.svg?style=flat-square" alt="License"></a>
<a href="https://www.npmjs.com/package/@invertase/react-native-google-ads"><img src="https://img.shields.io/npm/dm/@invertase/react-native-google-ads.svg?style=flat-square" alt="NPM downloads"></a>
<a href="https://www.npmjs.com/package/@invertase/react-native-google-ads"><img src="https://img.shields.io/npm/v/@invertase/react-native-google-ads.svg?style=flat-square" alt="NPM version"></a>
<a href="/LICENSE"><img src="https://img.shields.io/npm/l/@invertase/react-native-google-ads.svg?style=flat-square" alt="License"></a>
</p>

<p align="center">
Expand All @@ -19,12 +19,12 @@

---

**React Native Admob** is a module connecting you to Google AdMob services; a light-weight JavaScript layer connecting you to the native AdMob SDKs for both iOS and Android.
**React Native Admob** is a module connecting you to Google Mobile Ads services; a light-weight JavaScript layer connecting you to the native Google-Mobile-Ads SDKs for both iOS and Android.

React Native AdMob is built with three key principals in mind;
React Native Google Ads is built with three key principals in mind;

- 🧪 **Well tested**
- the module is extensively tested to >95% coverage
- the module is extensively tested to >95% coverage (getting there after moving from react-native-firebase!)
- 👁 **Well typed**
- first class support for Typescript included
- 📄 **Well documented**
Expand All @@ -42,10 +42,10 @@ COMING SOON (sorry)

<!-- - [Overview](https://rnfirebase.io) -->

- [Issues](https://github.com/invertase/react-native-admob/issues)
- [PRs](https://github.com/invertase/react-native-admob/pulls)
- [Issues](https://github.com/invertase/react-native-google-ads/issues)
- [PRs](https://github.com/invertase/react-native-google-ads/pulls)
<!-- - [Documentation](https://rnfirebase.io) -->
- [Community](https://github.com/invertase/react-native-admob/blob/master/CONTRIBUTING.md)
- [Community](https://github.com/invertase/react-native-google-ads/blob/master/CONTRIBUTING.md)
- [Code of Conduct](https://github.com/invertase/meta/blob/master/CODE_OF_CONDUCT.md)

## License
Expand Down
24 changes: 12 additions & 12 deletions RNAdMob.podspec → RNGoogleAds.podspec
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
require 'json'
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

admob_sdk_version = package['sdkVersions']['ios']['admob']
google_ads_sdk_version = package['sdkVersions']['ios']['googleAds']

Pod::Spec.new do |s|
s.name = "RNAdMob"
s.name = "RNGoogleAds"

s.version = package["version"]
s.description = package["description"]
s.summary = <<-DESC
A well tested feature rich AdMob implementation for React Native, supporting iOS & Android.
#{package["description"]}
DESC
s.homepage = "http://invertase.io/oss/react-native-admob"
s.homepage = "http://invertase.io/oss/react-native-google-ads"
s.license = package['license']
s.authors = "Invertase Limited"
s.source = { :git => "https://github.com/invertase/react-native-admob.git", :tag => "v#{s.version}" }
s.source = { :git => "#{package["repository"]["url"]}.git", :tag => "v#{s.version}" }
s.social_media_url = 'http://twitter.com/invertaseio'
s.ios.deployment_target = "10.0"
s.source_files = 'ios/**/*.{h,m}'
Expand All @@ -25,17 +25,17 @@ Pod::Spec.new do |s|
# Other dependencies
s.dependency 'PersonalizedAdConsent', '~> 1.0.5'

if defined?($RNAdMobSDKVersion)
Pod::UI.puts "#{s.name}: Using user specified Google Mobile-Ads SDK version '#{$RNAdMobSDKVersion}'"
admob_sdk_version = $RNAdMobSDKVersion
if defined?(RNGoogleAdsSDKVersion)
Pod::UI.puts "#{s.name}: Using user specified Google Mobile-Ads SDK version '#{RNGoogleAdsSDKVersion}'"
google_ads_sdk_version = $RNGoogleAdsSDKVersion
end

# AdMob dependencies
s.dependency 'Google-Mobile-Ads-SDK', admob_sdk_version
s.dependency 'Google-Mobile-Ads-SDK', google_ads_sdk_version

if defined?($RNAdMobAsStaticFramework)
Pod::UI.puts "#{s.name}: Using overridden static_framework value of '#{$RNAdMobAsStaticFramework}'"
s.static_framework = $RNAdMobAsStaticFramework
if defined?(RNGoogleAdsAsStaticFramework)
Pod::UI.puts "#{s.name}: Using overridden static_framework value of '#{$RNGoogleAdsAsStaticFramework}'"
s.static_framework = $RNGoogleAdsAsStaticFramework
else
s.static_framework = false
end
Expand Down
2 changes: 1 addition & 1 deletion __tests__/consent.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AdsConsent } from '../lib';

describe('Admob AdsConsent', function () {
describe('Google Ads AdsConsent', function () {
describe('requestInfoUpdate', function () {
it('throws if publisherIds is not an array', function () {
// @ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions __tests__/admob.test.ts → __tests__/googleAds.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import admob, { AdMobTypes } from '../lib';
import admob, { GoogleAdsTypes } from '../lib';

describe('Admob', function () {
describe('setRequestConfiguration()', function () {
Expand All @@ -14,7 +14,7 @@ describe('Admob', function () {
expect(() =>
admob.setRequestConfiguration({
maxAdContentRating:
'Y' as AdMobTypes.MaxAdContentRating[keyof AdMobTypes.MaxAdContentRating],
'Y' as GoogleAdsTypes.MaxAdContentRating[keyof GoogleAdsTypes.MaxAdContentRating],
}),
).toThrowError(
"setRequestConfiguration(*) 'requestConfiguration.maxAdContentRating' expected on of MaxAdContentRating.G, MaxAdContentRating.PG, MaxAdContentRating.T or MaxAdContentRating.MA",
Expand Down
2 changes: 1 addition & 1 deletion __tests__/interstitial.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InterstitialAd } from '../lib';

describe('Admob Interstitial', function () {
describe('Google Ads Interstitial', function () {
describe('createForAdRequest', function () {
it('throws if adUnitId is invalid', function () {
// @ts-ignore
Expand Down
27 changes: 14 additions & 13 deletions android/admob-json.gradle → android/app-json.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import groovy.json.JsonOutput
import groovy.json.JsonSlurper

String fileName = "admob.json"
String jsonRoot = "react-native"
String fileName = "app.json"
String jsonRoot = "react-native-google-ads"
String jsonRaw = "GOOGLE_ADS_JSON_RAW"

File jsonFile = null
File parentDir = rootProject.projectDir
Expand All @@ -17,20 +18,20 @@ for (int i = 0; i <= 3; i++) {
}

if (jsonFile != null && jsonFile.exists()) {
rootProject.logger.info ":${project.name} admob.json found at ${jsonFile.toString()}"
rootProject.logger.info ":${project.name} ${fileName} found at ${jsonFile.toString()}"
Object json = null

try {
json = new JsonSlurper().parseText(jsonFile.text)
} catch (Exception ignored) {
rootProject.logger.warn ":${project.name} failed to parse admob.json found at ${jsonFile.toString()}."
rootProject.logger.warn ":${project.name} failed to parse ${fileName} found at ${jsonFile.toString()}."
rootProject.logger.warn ignored.toString()
}

if (json && json[jsonRoot]) {
String jsonStr = JsonOutput.toJson(JsonOutput.toJson(json[jsonRoot]))

rootProject.ext.admobJson = [
rootProject.ext.googleAdsJson = [
raw: json[jsonRoot],
isFlagEnabled: { key, defaultValue ->
if (json[jsonRoot] == null || json[jsonRoot][key] == null) return defaultValue
Expand All @@ -42,27 +43,27 @@ if (jsonFile != null && jsonFile.exists()) {
}
]

rootProject.logger.info ":${project.name} found react-native json root in admob.json, creating admob build config"
rootProject.logger.info ":${project.name} found ${jsonRoot} json root in ${fileName}, creating app build config"
android {
defaultConfig {
buildConfigField "String", "ADMOB_JSON_RAW", jsonStr
buildConfigField "String", jsonRaw, jsonStr
}
}
} else {
rootProject.ext.admobJson = false
rootProject.logger.info ":${project.name} admob.json found with no react-native config, skipping"
rootProject.ext.googleAdsJson = false
rootProject.logger.info ":${project.name} ${fileName} found with no ${jsonRoot} config, skipping"
android {
defaultConfig {
buildConfigField "String", "ADMOB_JSON_RAW", '"{}"'
buildConfigField "String", jsonRaw, '"{}"'
}
}
}
} else {
rootProject.ext.admobJson = false
rootProject.logger.info ":${project.name} no admob.json found, skipping"
rootProject.ext.googleAdsJson = false
rootProject.logger.info ":${project.name} no ${fileName} found, skipping"
android {
defaultConfig {
buildConfigField "String", "ADMOB_JSON_RAW", '"{}"'
buildConfigField "String", jsonRaw, '"{}"'
}
}
}
26 changes: 13 additions & 13 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
}

dependencies {
classpath("com.android.tools.build:gradle:7.0.1")
classpath("com.android.tools.build:gradle:7.0.2")
}
}
}
Expand All @@ -21,7 +21,7 @@ plugins {
}

def packageJson = PackageJson.getForProject(project)
def admobVersion = packageJson['sdkVersions']['android']['admob']
def googleAdsVersion = packageJson['sdkVersions']['android']['googleAds']
def jsonMinSdk = packageJson['sdkVersions']['android']['minSdk']
def jsonTargetSdk = packageJson['sdkVersions']['android']['targetSdk']
def jsonCompileSdk = packageJson['sdkVersions']['android']['compileSdk']
Expand All @@ -39,8 +39,8 @@ project.ext {
buildTools: jsonBuildTools
],

admob: [
sdk: admobVersion,
googleAds: [
sdk: googleAdsVersion,
],

ads : [
Expand All @@ -50,26 +50,26 @@ project.ext {
])
}

apply from: file("./admob-json.gradle")
apply from: file("./app-json.gradle")

def admobJSONAdmobAppIDString = ""
def admobJSONAdmobDelayAppMeasurementInitBool = false
def appJSONGoogleAdsAppIDString = ""
def appJSONGoogleAdsDelayAppMeasurementInitBool = false

if (rootProject.ext.admobJson) {
admobJSONAdmobAppIDString = rootProject.ext.admobJson.getStringValue("android_app_id", "")
admobJSONAdmobDelayAppMeasurementInitBool = rootProject.ext.admobJson.isFlagEnabled("delay_app_measurement_init", false)
if (rootProject.ext.googleAdsJson) {
appJSONGoogleAdsAppIDString = rootProject.ext.appJSON.getStringValue("android_app_id", "")
appJSONGoogleAdsDelayAppMeasurementInitBool = rootProject.ext.appJSON.isFlagEnabled("delay_app_measurement_init", false)
}

if (!admobJSONAdmobAppIDString) {
if (!appJSONGoogleAdsAppIDString) {
// todo throw a build error?
}

android {
defaultConfig {
multiDexEnabled true
manifestPlaceholders = [
admobJSONAdmobAppID : admobJSONAdmobAppIDString,
admobJSONAdmobDelayAppMeasurementInit: admobJSONAdmobDelayAppMeasurementInitBool
appJSONGoogleAdsAppID : appJSONGoogleAdsAppIDString,
appJSONGoogleAdsDelayAppMeasurementInit: appJSONGoogleAdsDelayAppMeasurementInitBool
]
}
lintOptions {
Expand Down
2 changes: 1 addition & 1 deletion android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = '@invertase_react-native-admob'
rootProject.name = '@invertase_react-native-google-ads'
6 changes: 3 additions & 3 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.invertase.admob">
package="io.invertase.googleads">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
Expand All @@ -9,9 +9,9 @@
<application>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="${admobJSONAdmobAppID}"/>
android:value="${appJSONGoogleAdsAppID}"/>
<meta-data
android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT"
android:value="${admobJSONAdmobDelayAppMeasurementInit}"/>
android:value="${appJSONGoogleAdsDelayAppMeasurementInit}"/>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.invertase.admob;
package io.invertase.googleads;

/*
* Copyright (c) 2016-present Invertase Limited & Contributors
Expand Down Expand Up @@ -34,8 +34,8 @@
import java.util.Map;
import javax.annotation.Nonnull;

public class ReactNativeAdMobBannerAdViewManager extends SimpleViewManager<ReactViewGroup> {
private static final String REACT_CLASS = "ReactNativeAdMobBannerView";
public class ReactNativeGoogleAdsBannerAdViewManager extends SimpleViewManager<ReactViewGroup> {
private static final String REACT_CLASS = "ReactNativeGoogleAdsBannerView";
private String EVENT_AD_LOADED = "onAdLoaded";
private String EVENT_AD_FAILED_TO_LOAD = "onAdFailedToLoad";
private String EVENT_AD_OPENED = "onAdOpened";
Expand Down Expand Up @@ -90,12 +90,12 @@ public void setUnitId(ReactViewGroup reactViewGroup, String value) {

@ReactProp(name = "request")
public void setRequest(ReactViewGroup reactViewGroup, ReadableMap value) {
request = ReactNativeAdMobCommon.buildAdRequest(value);
request = ReactNativeGoogleAdsCommon.buildAdRequest(value);
}

@ReactProp(name = "size")
public void setSize(ReactViewGroup reactViewGroup, String value) {
size = ReactNativeAdMobCommon.getAdSize(value, reactViewGroup);
size = ReactNativeGoogleAdsCommon.getAdSize(value, reactViewGroup);

int width;
int height;
Expand Down Expand Up @@ -161,7 +161,7 @@ public void onAdLoaded() {

@Override
public void onAdFailedToLoad(int errorCode) {
WritableMap payload = ReactNativeAdMobCommon.errorCodeToMap(errorCode);
WritableMap payload = ReactNativeGoogleAdsCommon.errorCodeToMap(errorCode);
sendEvent(reactViewGroup, EVENT_AD_FAILED_TO_LOAD, payload);
}

Expand Down
Loading

0 comments on commit 799fae0

Please sign in to comment.