-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
175 additions
and
11 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsMediaView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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.annotation.SuppressLint | ||
import com.facebook.react.bridge.ReactContext | ||
import com.google.android.gms.ads.nativead.MediaView | ||
|
||
@SuppressLint("ViewConstructor") | ||
class ReactNativeGoogleMobileAdsMediaView( | ||
private val context: ReactContext | ||
): MediaView(context) { | ||
fun setResponseId(responseId: String?) { | ||
val nativeModule = context.getNativeModule(ReactNativeGoogleMobileAdsNativeModule.NAME) as ReactNativeGoogleMobileAdsNativeModule? | ||
nativeModule?.getNativeAd(responseId ?: "")?.let { | ||
this.mediaContent = it.mediaContent | ||
requestLayout() | ||
} | ||
} | ||
|
||
override fun requestLayout() { | ||
super.requestLayout() | ||
post(measureAndLayout) | ||
} | ||
|
||
private val measureAndLayout = Runnable { | ||
measure( | ||
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), | ||
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY) | ||
) | ||
layout(left, top, right, bottom) | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
.../src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsMediaViewManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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 com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.module.annotations.ReactModule | ||
import com.facebook.react.uimanager.ThemedReactContext | ||
import com.facebook.react.uimanager.ViewGroupManager | ||
import com.facebook.react.uimanager.ViewManagerDelegate | ||
import com.facebook.react.uimanager.annotations.ReactProp | ||
import com.facebook.react.viewmanagers.RNGoogleMobileAdsMediaViewManagerDelegate | ||
import com.facebook.react.viewmanagers.RNGoogleMobileAdsMediaViewManagerInterface | ||
|
||
@ReactModule(name = ReactNativeGoogleMobileAdsMediaViewManager.NAME) | ||
class ReactNativeGoogleMobileAdsMediaViewManager( | ||
reactContext: ReactApplicationContext | ||
) : ViewGroupManager<ReactNativeGoogleMobileAdsMediaView>(reactContext), | ||
RNGoogleMobileAdsMediaViewManagerInterface<ReactNativeGoogleMobileAdsMediaView> { | ||
private val delegate: ViewManagerDelegate<ReactNativeGoogleMobileAdsMediaView> = RNGoogleMobileAdsMediaViewManagerDelegate(this) | ||
|
||
override fun getDelegate(): ViewManagerDelegate<ReactNativeGoogleMobileAdsMediaView> = delegate | ||
|
||
override fun getName(): String = NAME | ||
|
||
override fun createViewInstance(context: ThemedReactContext): ReactNativeGoogleMobileAdsMediaView = ReactNativeGoogleMobileAdsMediaView(context) | ||
|
||
@ReactProp(name = "responseId") | ||
override fun setResponseId(mediaView: ReactNativeGoogleMobileAdsMediaView, responseId: String?) { | ||
mediaView.setResponseId(responseId) | ||
} | ||
|
||
companion object { | ||
const val NAME = "RNGoogleMobileAdsMediaView" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters