Skip to content
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

[Android] Trigger loadAd to refresh ads getting issue #389

Open
minhchienwikipedia opened this issue Oct 15, 2024 · 0 comments
Open

[Android] Trigger loadAd to refresh ads getting issue #389

minhchienwikipedia opened this issue Oct 15, 2024 · 0 comments

Comments

@minhchienwikipedia
Copy link

minhchienwikipedia commented Oct 15, 2024

When I try to call loadAd to refresh ads my ads are not showing. This issue affect to my requests and show rate on Admob, can you help me fix this. Thanks

Image error:
986e3f75-cce4-4c03-84b9-779fbdfcfb8b

Here my code

const AdmobNative = (
    {
        style,
        disabled,
        onAdLoaded,
        type = 'full',
        adUnitID = CHANGE_LANGUAGE_NATIVE_UNIT_ID,
    }: {
        style?: ViewStyle;
        disabled?: boolean;
        onAdLoaded?: () => void;
        type?: 'full' | 'small' | string;
        adUnitID?: string;
    },
    ref: any,
) => {
    const { disableAdmob } = useAppSelector(state => ({
        disableAdmob: state.config.disableAdmob,
    }));
    const [loaded, setLoaded] = useState(false);
    const nativeAdViewRef: any = useRef();

    useEffect(() => {
        nativeAdViewRef.current?.loadAd();
    }, []);

    useImperativeHandle(
        ref,
        () => ({
            refresh: () => {
                nativeAdViewRef.current?.loadAd();
            },
        }),
        [ref],
    );

    if (disableAdmob || disabled) {
        return null;
    }

    const handleOnAdLoaded = () => {
        onAdLoaded?.();
        setLoaded(true);
    };

    return (
        <NativeAdView
            ref={nativeAdViewRef}
            style={[style, !loaded && styles.opacity]}
            onAdLoaded={handleOnAdLoaded}
            onAdFailedToLoad={onAdLoaded}
            mediationOptions={{ nativeBanner: true }}
            adUnitID={adUnitID}>
            <View
                style={{
                    marginTop: DIMENSION_PADDING_SMALL,
                }}
                row
                alignCenter>
                <IconView style={styles.logo} />
                <View full style={{ marginLeft: DIMENSION_PADDING_SMALL }}>
                    <View row>
                        <AdLabel style={styles.label} />
                        <HeadlineView
                            style={[styles.headLine, styles.txtBold]}
                        />
                    </View>
                    <TaglineView
                        numberOfLines={2}
                        style={[
                            styles.tagLine,
                            { color: COLOR_TEXT_BLACK, fontFamily },
                        ]}
                    />
                </View>
            </View>
            {type === 'full' && (
                <View alignCenter>
                    <NativeMediaView style={styles.img} />
                </View>
            )}
            <CallToActionView
                style={styles.btn}
                buttonAndroidStyle={styles.btnAndroid}
                allCaps
                textStyle={{ ...styles.btnText, ...styles.txtBold }}
            />
        </NativeAdView>
    );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant