Skip to content
This repository has been archived by the owner on Apr 27, 2022. It is now read-only.

App laggy #10

Closed
ydv0121 opened this issue Aug 17, 2021 · 11 comments
Closed

App laggy #10

ydv0121 opened this issue Aug 17, 2021 · 11 comments

Comments

@ydv0121
Copy link

ydv0121 commented Aug 17, 2021

When AD loads the app is very choppy for some moment.
i have already initialised the AdMob.initialize() at app launch.

@wjaykim
Copy link
Collaborator

wjaykim commented Aug 17, 2021

Hi, thank you for using this library. To find out what's wrong, let me show your code please.

@ydv0121
Copy link
Author

ydv0121 commented Aug 17, 2021

initialisation at root App.js

useEffect(() => { const init = async () => { await AdMob.initialize(); }; init(); }, []);

AD Code on my Home Page -

<BannerAd size={'LARGE_BANNER'} unitId={unitID} onAdFailedToLoad={(error) => console.error(error)} />

problem is that it's hang up for around 10 seconds only. then it work fine after AD rendered.

@wjaykim
Copy link
Collaborator

wjaykim commented Aug 17, 2021

I need more detail. What platform are you experiencing lag, and what version of our package are you using?

@ydv0121
Copy link
Author

ydv0121 commented Aug 17, 2021

"react": "17.0.1",
"react-native": "0.64.2",
"@react-native-admob/admob": "^1.0.1",

i am facing this on Android side.i will try to send video also

@haivle
Copy link

haivle commented Aug 19, 2021

I notice the app super laggy when transitioning between background and foreground. I think some audio sessions of the banners is not closed. U can test it by playing music in background and open the app. The audio from music app will be interrupted

@haivle
Copy link

haivle commented Aug 19, 2021

In my case, using iOS simulator

  1. showing the video ads on splash screen using useRewardedInterstitialAd hook
  2. Close the video
  3. navigate to another screen
    -> the audio session is interupted
  4. make app go to background mode
    -> audio of simulator is laggy, js and ui FPS is dropped to 0
  5. make app to to foreground
    -> notice animation fps is dropped

@haivle
Copy link

haivle commented Aug 19, 2021

when I try to remove all functions and rewardedInterstitialAd from useEffect dependencies, the issue is improved.

const load = useCallback((requestOptions = adRequestOptions) => {
    init();
    rewardedInterstitialAd.load(requestOptions).catch(e => setAdLoadError(e)).then(() => setAdLoaded(true));
  }, [adRequestOptions]);

  const show = useCallback(() => {
    if (adPresented) {
      console.warn('[RNAdMob(RewardedInterstitialAd)] Ad is already presented once.');
    } else if (adLoaded) {
      rewardedInterstitialAd.show().catch(e => setAdPresentError(e)).then(() => setAdPresented(true));
    } else {
      console.warn('[RNAdMob(RewardedInterstitialAd)] Ad is not loaded.');
    }
  }, [adPresented, adLoaded]);

  useEffect(() => {
    if (!rewardedInterstitialAd.requested && loadOnMounted) {
      load();
    }
  }, [loadOnMounted]);
  useEffect(() => {
    if (adLoaded && showOnLoaded) {
      show();
    }
  }, [adLoaded, showOnLoaded]);

  useEffect(() => {
    if (adDismissed && loadOnDismissed) {
      load();
    }
  }, [adDismissed, loadOnDismissed]);

  useEffect(() => {
    const presentListener = rewardedInterstitialAd.addEventListener('adPresented', () => setAdDismissed(false));
    const dismissListener = rewardedInterstitialAd.addEventListener('adDismissed', () => {
      setAdDismissed(true);
      init();
    });
    const rewardListener = rewardedInterstitialAd.addEventListener('rewarded', r => setReward(r));
    return () => {
      presentListener.remove();
      dismissListener.remove();
      rewardListener.remove();
    };
  }, []);

@wjaykim
Copy link
Collaborator

wjaykim commented Aug 19, 2021

I'm investigating this issue's relation with audio.

@wjaykim
Copy link
Collaborator

wjaykim commented Sep 11, 2021

Hi, I made some changes to code. Would you guys try version 1.1.0 and give me feedback? Thank you.

@ydv0121
Copy link
Author

ydv0121 commented Sep 23, 2021

issue solved for me.
closing it

@ydv0121 ydv0121 closed this as completed Sep 23, 2021
@JeffGuKang
Copy link

In my case, loadOnMounted: true makes laggy.

I solved the issue to use loadOnMounted: false option and load RewardedAd in useEffect.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants