-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(admob, android): unity ads require Activity Context #4921
Conversation
Unity Ads requires an Activity context to load ads.
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/invertase/react-native-firebase/CnSDkVA8ff161FJRamQrrJe1Xzjn |
@mikehardy let me know if there is need for special logging in case of null Activity. |
Codecov Report
@@ Coverage Diff @@
## master #4921 +/- ##
==========================================
+ Coverage 88.50% 88.93% +0.43%
==========================================
Files 109 109
Lines 3721 3721
Branches 348 348
==========================================
+ Hits 3293 3309 +16
+ Misses 385 369 -16
Partials 43 43 |
Thanks for this! I think rather than a regression this was a fix that landed on the v5 branch but never made it to the main branch! That's a shame but at least you are getting it now. More than anything we need the CLA signed, we can't merge until that's done. The details link for the CLA check in the block of checks on the PR has more info to help you get it done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi there - thank you for your patience!
This looks close, and while I think it would work, may I ask you to reshape it just a bit?
Specifically, now that I look closely it appears that getCurrentActivity
being not-null is actually a requirement for the whole thing to work. So the change should not really be so concerned about whether it is null or not, rather since we use the Activity in three places now it should actually store it as a temporary variable, do the null check once, then use the temp variable in all three spots.
Specifically
- the import of Context should not be necessary any more but you may need to import Activity
- the first
if (getCurrentActivity() == null)
check should be changed to (in pseudocode)
Activity currentActivity = getCurrentActivity();
if (currentActivity == null) { /* the existing error handling here, all the same */ }
currentActivity.runOnUiThread(() -> {
// now just use currentActivity in place of getApplicationContext())
}
Unless I am missing something I think this will make for a very clean implementation and is even smaller than the proposed change.
What do you think?
for the avoidance of doubt: I'm +1 on the change idea in general though of course, looking forward to merging a fix here |
@zyzo just in case you didn't see this ⬆️ |
@mikehardy sure, I'll see what I can do tomorrow ! |
@mikehardy ☝️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really clean to me now, thank you!
As soon as CI finishes (it failed on the iOS e2e tests, which obviously has nothing to do with this PR, it should go green in a few minutes now that I've restarted it) I'll merge this and release Thanks @zyzo ! |
Releasing as 10.8.1 right now, thanks! |
Description
Fix Admob crash from UnityAds with Admob Mediation.
Seems like a regression from #1892
Fixes #1792
Related issues
#1792
#1892
Release Summary
Checklist
Android
iOS
e2e
tests added or updated inpackages/\*\*/e2e
jest
tests added or updated inpackages/\*\*/__tests__
Test Plan
Think
react-native-firebase
is great? Please consider supporting the project with any of the below:React Native Firebase
andInvertase
on Twitter