Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ When using The New Architecture, some legacy code will still be used though. See
| iOS | User Messaging Platform (Turbo Native Module) | ✅ Complete |
| iOS | [EventEmitter](https://github.com/reactwg/react-native-new-architecture/blob/main/docs/turbo-modules.md#add-event-emitting-capabilities) (Turbo Native Module) | ⏳ To-Do |
| iOS | Revenue Precision Constants (Turbo Native Module) | ✅ Complete |
| Android | Mobile Ads SDK Methods (Turbo Native Module) | ⏳ To-Do |
| Android | Banners (Fabric Native Component) | ⏳ To-Do |
| Android | Full Screen Ads (Turbo Native Module) | ⏳ To-Do |
| Android | Mobile Ads SDK Methods (Turbo Native Module) | ✅ Complete |
| Android | Banners (Fabric Native Component) | ✅ Complete |
| Android | Full Screen Ads (Turbo Native Module) | ✅ Complete |
| Android | Native Ads (Turbo Native Module, Fabric Native Component) | ✅ Complete |
| Android | User Messaging Platform (Turbo Native Module) | ⏳ To-Do |
| Android | [EventEmitter](https://github.com/reactwg/react-native-new-architecture/blob/main/docs/turbo-modules.md#add-event-emitting-capabilities) (Turbo Native Module) | ⏳ To-Do |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,39 @@
*
*/

import androidx.annotation.NonNull;

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.ReadableMap;
import io.invertase.googlemobileads.common.RCTConvert;
import io.invertase.googlemobileads.common.ReactNativeEvent;
import io.invertase.googlemobileads.common.ReactNativeEventEmitter;
import io.invertase.googlemobileads.common.ReactNativeJSON;
import io.invertase.googlemobileads.common.ReactNativeMeta;
import io.invertase.googlemobileads.common.ReactNativeModule;
import io.invertase.googlemobileads.common.ReactNativePreferences;

public class ReactNativeAppModule extends ReactNativeModule {
public class ReactNativeAppModule extends ReactContextBaseJavaModule {
static final String NAME = "RNAppModule";
ReactApplicationContext context;

ReactNativeAppModule(ReactApplicationContext reactContext) {
super(reactContext, NAME);
super(reactContext);
context=reactContext;
}

@NonNull
@Override
public String getName() {
return NAME;
}

@Override
public void initialize() {
super.initialize();
ReactNativeEventEmitter.getSharedInstance().attachReactContext(getContext());
ReactNativeEventEmitter.getSharedInstance().attachReactContext(context);
}

@ReactMethod
Expand Down
Original file line number Diff line number Diff line change
@@ -1,73 +1,34 @@
package io.invertase.googlemobileads

/*
* Copyright (c) 2016-present Invertase Limited & Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this library except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import android.app.Activity
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.ReadableMap
import com.google.android.gms.ads.AdLoadCallback
import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.admanager.AdManagerAdRequest
import com.google.android.gms.ads.appopen.AppOpenAd

class ReactNativeGoogleMobileAdsAppOpenModule(reactContext: ReactApplicationContext?) :
ReactNativeGoogleMobileAdsFullScreenAdModule<AppOpenAd>(reactContext, NAME) {
NativeAppOpenModuleSpec(reactContext) {

override fun getAdEventName(): String {
return ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_APP_OPEN
}
private var instance: ReactNativeGoogleMobileAdsAppOpenModuleImpl =
ReactNativeGoogleMobileAdsAppOpenModuleImpl(reactContext)

@ReactMethod
fun appOpenLoad(requestId: Int, adUnitId: String, adRequestOptions: ReadableMap) {
load(requestId, adUnitId, adRequestOptions)
}

@ReactMethod
fun appOpenShow(
requestId: Int, adUnitId: String, showOptions: ReadableMap, promise: Promise
override fun appOpenLoad(
requestId: Double,
adUnitId: String,
requestOptions: ReadableMap?
) {
show(requestId, adUnitId, showOptions, promise)
instance.appOpenLoad(requestId.toInt(), adUnitId, requestOptions ?: Arguments.createMap())
}

override fun loadAd(
activity: Activity,
override fun appOpenShow(
requestId: Double,
adUnitId: String,
adRequest: AdManagerAdRequest,
adLoadCallback: AdLoadCallback<AppOpenAd>
showOptions: ReadableMap?,
promise: Promise
) {
AppOpenAd.load(
activity,
adUnitId,
adRequest,
object :
AppOpenAd.AppOpenAdLoadCallback() {
override fun onAdLoaded(ad: AppOpenAd) {
adLoadCallback.onAdLoaded(ad)
}
override fun onAdFailedToLoad(error: LoadAdError) {
adLoadCallback.onAdFailedToLoad(error)
}
})
instance.appOpenShow(requestId.toInt(), adUnitId, showOptions ?: Arguments.createMap(), promise)
}

companion object {
const val NAME = "RNGoogleMobileAdsAppOpenModule"
const val NAME = NativeAppOpenModuleSpec.NAME
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package io.invertase.googlemobileads

/*
* Copyright (c) 2016-present Invertase Limited & Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this library except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import android.app.Activity
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReadableMap
import com.google.android.gms.ads.AdLoadCallback
import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.admanager.AdManagerAdRequest
import com.google.android.gms.ads.appopen.AppOpenAd

class ReactNativeGoogleMobileAdsAppOpenModuleImpl(reactContext: ReactApplicationContext?) :
ReactNativeGoogleMobileAdsFullScreenAdModule<AppOpenAd>(reactContext) {

override fun getAdEventName(): String {
return ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_APP_OPEN
}

fun appOpenLoad(requestId: Int, adUnitId: String, adRequestOptions: ReadableMap) {
load(requestId, adUnitId, adRequestOptions)
}

fun appOpenShow(
requestId: Int, adUnitId: String, showOptions: ReadableMap, promise: Promise
) {
show(requestId, adUnitId, showOptions, promise)
}

override fun loadAd(
activity: Activity,
adUnitId: String,
adRequest: AdManagerAdRequest,
adLoadCallback: AdLoadCallback<AppOpenAd>
) {
AppOpenAd.load(
activity,
adUnitId,
adRequest,
object :
AppOpenAd.AppOpenAdLoadCallback() {
override fun onAdLoaded(ad: AppOpenAd) {
adLoadCallback.onAdLoaded(ad)
}

override fun onAdFailedToLoad(error: LoadAdError) {
adLoadCallback.onAdFailedToLoad(error)
}
})
}
}
Loading
Loading