Skip to content

Commit

Permalink
feat: up SDK version
Browse files Browse the repository at this point in the history
  • Loading branch information
vtr0n committed Aug 24, 2022
1 parent bc397e2 commit a356259
Show file tree
Hide file tree
Showing 16 changed files with 213 additions and 98 deletions.
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# react-native-yandex-mobile-ads

Implementation Yandex ads for react native
Implementation Yandex Mobile Ads SDK for react native

## Installation

Expand Down Expand Up @@ -37,7 +37,7 @@ $ react-native link react-native-yandex-mobile-ads
## Usage

```tsx
import { BannerView, InterstitialAdManager } from 'react-native-yandex-mobile-ads';
import { BannerView, InterstitialAdManager, RewardedAdManager } from 'react-native-yandex-mobile-ads';

<BannerView
adUnitId={'R-M-DEMO-300x250'}
Expand All @@ -48,16 +48,33 @@ import { BannerView, InterstitialAdManager } from 'react-native-yandex-mobile-ad
onError={(err: any) => console.log('error', err)}
/>

InterstitialAdManager.showAd('R-M-DEMO-320x480')
InterstitialAdManager.showAd('R-M-DEMO-interstitial')
.then((didClick: boolean) => {
console.log('clicked: ' + didClick);
})
.catch((error: any) => {
console.log('error: ' + error);
});

RewardedAdManager.showAd('R-M-DEMO-rewarded-client-side-rtb')
.then((resp) => {
const amount = resp.amount;
const type = resp.type;
const clicked = resp.click;
console.log(
`amount: ${amount}, type: ${type}, clicked: ${clicked}`
);
})
.catch((error: any) => {
console.log('error: ' + error);
});
}}
```

## Contributing
Mobile Ads SDK [documentation](https://yandex.ru/dev/mobile-ads/doc/intro/about.html)
You can look at alternative implementations [react-native-admob](https://github.com/sbugert/react-native-admob),
[react-native-fbads](https://github.com/callstack/react-native-fbads) and implement similar code

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

Expand Down
6 changes: 2 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def safeExtGet(prop, fallback) {

android {
compileSdkVersion safeExtGet('YandexMobileAds_compileSdkVersion', 31)
buildToolsVersion safeExtGet('YandexMobileAds_buildToolsVersion', '29.0.2')
buildToolsVersion safeExtGet('YandexMobileAds_buildToolsVersion', '31.0.0')
defaultConfig {
minSdkVersion safeExtGet('YandexMobileAds_minSdkVersion', 16)
minSdkVersion safeExtGet('YandexMobileAds_minSdkVersion', 24)
targetSdkVersion safeExtGet('YandexMobileAds_targetSdkVersion', 31)
versionCode 1
versionName "1.0"
Expand Down Expand Up @@ -54,10 +54,8 @@ repositories {

dependencies {
def mobileadsVersion = safeExtGet('YandexMobileAds_mobileadsVersion', '5.2.0')
def mobmetrikaVersion = safeExtGet('YandexMobileAds_mobmetrikaVersion', '4.2.0')

//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "com.yandex.android:mobileads:$mobileadsVersion"
implementation "com.yandex.android:mobmetricalib:$mobmetrikaVersion"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.util.TypedValue;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.LifecycleEventListener;
Expand Down Expand Up @@ -121,18 +122,26 @@ public void onAdFailedToLoad(@NonNull AdRequestError adRequestError) {

event.putInt("errorCode", adRequestError.getCode());
event.putString("errorMessage", adRequestError.getDescription());
mEventEmitter.receiveEvent(getId(), "onError", event);
sendEvent("onError", event);

myAdView = null;
}

@Override
public void onLeftApplication() {
mEventEmitter.receiveEvent(getId(), "onLeftApplication", null);
sendEvent("onLeftApplication", null);
}

@Override
public void onReturnedToApplication() {
mEventEmitter.receiveEvent(getId(), "onReturnedToApplication", null);
sendEvent("onReturnedToApplication", null);
}

private void sendEvent(String name, @Nullable WritableMap event) {
ReactContext reactContext = (ReactContext) getContext();
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(
getId(),
name,
event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void onImpression(ImpressionData impressionData) {

@Override
public void onAdClicked() {

mDidClick = true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import androidx.annotation.NonNull;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.WritableMap;
import com.yandex.mobile.ads.common.AdRequest;
import com.yandex.mobile.ads.common.AdRequestError;
import com.yandex.mobile.ads.rewarded.Reward;
Expand Down Expand Up @@ -78,7 +80,7 @@ public void onImpression(ImpressionData impressionData) {

@Override
public void onAdClicked() {

mDidClick = true;
}

@Override
Expand Down Expand Up @@ -111,13 +113,18 @@ public void onAdDismissed() {

@Override
public void onRewarded(@NonNull Reward reward) {
mPromise.resolve(mDidClick);
WritableMap event = Arguments.createMap();

event.putInt("amount", reward.getAmount());
event.putString("type", reward.getType());
event.putBoolean("click", mDidClick);

mPromise.resolve(event);
cleanUp();
}

@Override
public void onLeftApplication() {
mDidClick = true;
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ dependencies {
}

implementation project(':reactnativeyandexmobileads')
implementation 'com.yandex.android:mobileads:4.2.0'
implementation 'com.yandex.android:mobmetricalib:3.20.1'
implementation 'com.yandex.android:mobileads:5.2.0'
}

// Run this once to be able to run the application with BUCK
Expand Down
1 change: 1 addition & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:exported="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
8 changes: 4 additions & 4 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

buildscript {
ext {
buildToolsVersion = "29.0.2"
minSdkVersion = 16
compileSdkVersion = 29
targetSdkVersion = 29
buildToolsVersion = "31.0.0"
minSdkVersion = 24
compileSdkVersion = 31
targetSdkVersion = 31
}
repositories {
google()
Expand Down
39 changes: 22 additions & 17 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@ PODS:
- React-cxxreact (= 0.63.4)
- React-jsi (= 0.63.4)
- React-jsinspector (0.63.4)
- react-native-yandex-mobile-ads (0.3.0):
- react-native-yandex-mobile-ads (0.3.6):
- React-Core
- YandexMobileAds (= 4.3.1)
- YandexMobileAds
- YandexMobileAdsInstream
- React-RCTActionSheet (0.63.4):
- React-Core/RCTActionSheetHeaders (= 0.63.4)
- React-RCTAnimation (0.63.4):
Expand Down Expand Up @@ -248,17 +249,19 @@ PODS:
- React-Core (= 0.63.4)
- React-cxxreact (= 0.63.4)
- React-jsi (= 0.63.4)
- YandexMobileAds (4.3.1):
- YandexMobileAds/Static (= 4.3.1)
- YandexMobileAds/Static (4.3.1):
- YandexMobileMetrica (< 4.0.0, >= 3.14.1)
- YandexMobileMetrica (3.17.0):
- YandexMobileMetrica/Static (= 3.17.0)
- YandexMobileMetrica/Static (3.17.0):
- YandexMobileMetrica/Static/Core (= 3.17.0)
- YandexMobileMetrica/Static/Crashes (= 3.17.0)
- YandexMobileMetrica/Static/Core (3.17.0)
- YandexMobileMetrica/Static/Crashes (3.17.0):
- YandexMobileAds (5.1.0):
- YandexMobileAds/Static (= 5.1.0)
- YandexMobileAds/Static (5.1.0):
- YandexMobileMetrica (< 5.0.0, >= 4.0.0)
- YandexMobileAdsInstream (0.11.0):
- YandexMobileAds (~> 5.1.0)
- YandexMobileMetrica (4.2.0):
- YandexMobileMetrica/Static (= 4.2.0)
- YandexMobileMetrica/Static (4.2.0):
- YandexMobileMetrica/Static/Core (= 4.2.0)
- YandexMobileMetrica/Static/Crashes (= 4.2.0)
- YandexMobileMetrica/Static/Core (4.2.0)
- YandexMobileMetrica/Static/Crashes (4.2.0):
- YandexMobileMetrica/Static/Core
- Yoga (1.14.0)

Expand Down Expand Up @@ -297,6 +300,7 @@ SPEC REPOS:
trunk:
- boost-for-react-native
- YandexMobileAds
- YandexMobileAdsInstream
- YandexMobileMetrica

EXTERNAL SOURCES:
Expand Down Expand Up @@ -372,7 +376,7 @@ SPEC CHECKSUMS:
React-jsi: a0418934cf48f25b485631deb27c64dc40fb4c31
React-jsiexecutor: 93bd528844ad21dc07aab1c67cb10abae6df6949
React-jsinspector: 58aef7155bc9a9683f5b60b35eccea8722a4f53a
react-native-yandex-mobile-ads: e7d932b670bd05ab4579ea0256a37aeb7085ed35
react-native-yandex-mobile-ads: 8a789d8457719482b02b0a3954ffb7aab8db921e
React-RCTActionSheet: 89a0ca9f4a06c1f93c26067af074ccdce0f40336
React-RCTAnimation: 1bde3ecc0c104c55df246eda516e0deb03c4e49b
React-RCTBlob: a97d378b527740cc667e03ebfa183a75231ab0f0
Expand All @@ -383,10 +387,11 @@ SPEC CHECKSUMS:
React-RCTText: 5c51df3f08cb9dedc6e790161195d12bac06101c
React-RCTVibration: ae4f914cfe8de7d4de95ae1ea6cc8f6315d73d9d
ReactCommon: 73d79c7039f473b76db6ff7c6b159c478acbbb3b
YandexMobileAds: 8f9bdf380364875c468ded8f33bf6e9cc711b3a2
YandexMobileMetrica: 9e713c16bb6aca0ba63b84c8d7b8b86d32f4ecc4
YandexMobileAds: 45b76c6321cbfaca2527f99ba280a5381a60a7d1
YandexMobileAdsInstream: 837123da818502bb467e7f4a6aaf5ce83b006b73
YandexMobileMetrica: f5f9c605eaaba33ff6ab2b6bc3259035ca60ed87
Yoga: 4bd86afe9883422a7c4028c00e34790f560923d6

PODFILE CHECKSUM: 033c5c63aa0fd74cc3ae49dd714e9a8fdb0d68ac

COCOAPODS: 1.10.1
COCOAPODS: 1.11.3
8 changes: 8 additions & 0 deletions example/ios/Void.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// Void.swift
// YandexMobileAdsExample
//
// Created by valery on 21.08.2022.
//

import Foundation
Loading

0 comments on commit a356259

Please sign in to comment.