Skip to content

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

Description

@minhchienwikipedia

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>
    );
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions