Skip to content

Commit

Permalink
chore: fix styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Almouro committed Mar 27, 2024
1 parent 3fd0e29 commit e972906
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 58 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
},
env: {
'jest/globals': true,
node: true,
},
rules: {
'jest/no-identical-title': 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ public void onAdLoaded() {
height = reactViewGroup.getHeight();

adView.addOnLayoutChangeListener(
(v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
WritableMap payload = Arguments.createMap();
payload.putDouble("width", PixelUtil.toDIPFromPixel(right - left));
payload.putDouble("height", PixelUtil.toDIPFromPixel(bottom - top));
sendEvent(reactViewGroup, EVENT_SIZE_CHANGE, payload);
});
(v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
WritableMap payload = Arguments.createMap();
payload.putDouble("width", PixelUtil.toDIPFromPixel(right - left));
payload.putDouble("height", PixelUtil.toDIPFromPixel(bottom - top));
sendEvent(reactViewGroup, EVENT_SIZE_CHANGE, payload);
});
} else {
int left = adView.getLeft();
int top = adView.getTop();
Expand All @@ -232,42 +232,42 @@ public void onAdLoaded() {
adView.layout(left, top, left + width, top + height);
}

WritableMap payload = Arguments.createMap();
WritableMap payload = Arguments.createMap();
payload.putDouble("width", PixelUtil.toDIPFromPixel(width));
payload.putDouble("height", PixelUtil.toDIPFromPixel(height));

sendEvent(reactViewGroup, EVENT_AD_LOADED, payload);
}
sendEvent(reactViewGroup, EVENT_AD_LOADED, payload);
}

@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
int errorCode = loadAdError.getCode();
WritableMap payload = ReactNativeGoogleMobileAdsCommon.errorCodeToMap(errorCode);
sendEvent(reactViewGroup, EVENT_AD_FAILED_TO_LOAD, payload);
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
int errorCode = loadAdError.getCode();
WritableMap payload = ReactNativeGoogleMobileAdsCommon.errorCodeToMap(errorCode);
sendEvent(reactViewGroup, EVENT_AD_FAILED_TO_LOAD, payload);
}

@Override
public void onAdOpened() {
sendEvent(reactViewGroup, EVENT_AD_OPENED, null);
}
@Override
public void onAdOpened() {
sendEvent(reactViewGroup, EVENT_AD_OPENED, null);
}

@Override
public void onAdClosed() {
sendEvent(reactViewGroup, EVENT_AD_CLOSED, null);
}
});
@Override
public void onAdClosed() {
sendEvent(reactViewGroup, EVENT_AD_CLOSED, null);
}
});
if (adView instanceof AdManagerAdView) {
((AdManagerAdView) adView)
.setAppEventListener(
new AppEventListener() {
@Override
public void onAppEvent(@NonNull String name, @Nullable String data) {
WritableMap payload = Arguments.createMap();
payload.putString("name", name);
payload.putString("data", data);
sendEvent(reactViewGroup, EVENT_APP_EVENT, payload);
}
});
.setAppEventListener(
new AppEventListener() {
@Override
public void onAppEvent(@NonNull String name, @Nullable String data) {
WritableMap payload = Arguments.createMap();
payload.putString("name", name);
payload.putString("data", data);
sendEvent(reactViewGroup, EVENT_APP_EVENT, payload);
}
});
}
reactViewGroup.addView(adView);
return adView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@

import android.content.Context;
import android.widget.FrameLayout;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import java.util.List;

/**
* Using FrameLayout instead of ReactViewGroup
*
* This is because in the case of fluid ads,
* - JS side will usually not specify the ad height
* - Also, after loading the fluid ad, we need to measure the ad height and update the layout
* Which isn't possible with ReactViewGroup since it overrides requestLayout by a noop
* <p>This is because in the case of fluid ads, - JS side will usually not specify the ad height -
* Also, after loading the fluid ad, we need to measure the ad height and update the layout Which
* isn't possible with ReactViewGroup since it overrides requestLayout by a noop
*
* See https://github.com/facebook/react-native/issues/17968 for more details
* <p>See https://github.com/facebook/react-native/issues/17968 for more details
*/
public class ReactNativeAdView extends FrameLayout {
private AdRequest request;
Expand All @@ -32,25 +30,29 @@ public void requestLayout() {
}

/**
* This ensures the adview is properly measured and laid out if its layout changed after being loaded
* This happens everytime for fluid ads, but cannot happen for fixed size ads loading additional content
* This ensures the adview is properly measured and laid out if its layout changed after being
* loaded This happens everytime for fluid ads, but cannot happen for fixed size ads loading
* additional content
*
* See https://github.com/facebook/react-native/issues/17968 for more details
* <p>See https://github.com/facebook/react-native/issues/17968 for more details
*/
private final Runnable measureAndLayout = () -> {
/**
* For fluid ads, we usually don't specify the ad height from JS side, so mark it as
* unspecified and let it dynamically determine its size
*
* See https://developers.google.com/ad-manager/mobile-ads-sdk/android/native/styles#fluid_size
*/
int heightMeasureSpec = isFluid ?
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED) :
MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY);

measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY), heightMeasureSpec);
layout(getLeft(), getTop(), getRight(), getTop() + getHeight());
};
private final Runnable measureAndLayout =
() -> {
/**
* For fluid ads, we usually don't specify the ad height from JS side, so mark it as
* unspecified and let it dynamically determine its size
*
* <p>See
* https://developers.google.com/ad-manager/mobile-ads-sdk/android/native/styles#fluid_size
*/
int heightMeasureSpec =
isFluid
? MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
: MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY);

measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY), heightMeasureSpec);
layout(getLeft(), getTop(), getRight(), getTop() + getHeight());
};

public ReactNativeAdView(final Context context) {
super(context);
Expand Down
2 changes: 1 addition & 1 deletion src/common/debounce.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const debounce = <F extends (...args: any[]) => any>(func: F, waitFor: number) => {
export const debounce = <F extends (...args: unknown[]) => unknown>(func: F, waitFor: number) => {
let timeout: ReturnType<typeof setTimeout> | null = null;

const debounced = (...args: Parameters<F>) => {
Expand Down

0 comments on commit e972906

Please sign in to comment.