Skip to content

Commit b3e6ed3

Browse files
almostintuitiveroychang-synology
authored andcommitted
Fix: make sure requestPromise is only invoked once + crash when isLoaded() is called before requestAd() (sbugert#241)
* Fix: make sure we only invoke requestPromise once * Fix: check if mRewardedVideoAd is not null before calling .isLoaded() * remove newline
1 parent 3c7b7eb commit b3e6ed3

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

android/src/main/java/com/sbugert/rnadmob/RNAdMobInterstitialAdModule.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ public void onAdFailedToLoad(int errorCode) {
8181
WritableMap error = Arguments.createMap();
8282
event.putString("message", errorMessage);
8383
sendEvent(EVENT_AD_FAILED_TO_LOAD, event);
84-
mRequestAdPromise.reject(errorString, errorMessage);
84+
if (mRequestAdPromise != null) {
85+
mRequestAdPromise.reject(errorString, errorMessage);
86+
mRequestAdPromise = null;
87+
}
8588
}
8689
@Override
8790
public void onAdLeftApplication() {
@@ -90,7 +93,10 @@ public void onAdLeftApplication() {
9093
@Override
9194
public void onAdLoaded() {
9295
sendEvent(EVENT_AD_LOADED, null);
93-
mRequestAdPromise.resolve(null);
96+
if (mRequestAdPromise != null) {
97+
mRequestAdPromise.resolve(null);
98+
mRequestAdPromise = null;
99+
}
94100
}
95101
@Override
96102
public void onAdOpened() {

android/src/main/java/com/sbugert/rnadmob/RNAdMobRewardedVideoAdModule.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public void showAd(final Promise promise) {
180180
new Handler(Looper.getMainLooper()).post(new Runnable() {
181181
@Override
182182
public void run() {
183-
if (mRewardedVideoAd.isLoaded()) {
183+
if (mRewardedVideoAd != null && mRewardedVideoAd.isLoaded()) {
184184
mRewardedVideoAd.show();
185185
promise.resolve(null);
186186
} else {
@@ -195,7 +195,11 @@ public void isReady(final Callback callback) {
195195
new Handler(Looper.getMainLooper()).post(new Runnable() {
196196
@Override
197197
public void run() {
198-
callback.invoke(mRewardedVideoAd.isLoaded());
198+
if (mRewardedVideoAd != null) {
199+
callback.invoke(mRewardedVideoAd.isLoaded());
200+
} else {
201+
callback.invoke(false);
202+
}
199203
}
200204
});
201205
}

0 commit comments

Comments
 (0)