Setting a timer for a long period of time, i.e. multiple minutes

前端 未结 14 1196
面向向阳花
面向向阳花 2020-12-02 12:23

I want to use firebase auth with react native for Login and Signup but I got a yellow error:

Setting a timer for a long p

相关标签:
14条回答
  • 2020-12-02 12:28

    Josh Crowther Software Engineer at Google Said:

    Using multi-step short duration setTimeouts doesn't actually fix the problem though. The Timer module still stays active and the app is still subject to the performance issues indicated in the warning. The issue here is that, we have use cases that require long timers, and react-native doesn't optimize for that use case.

    So the net of all that is: This bug can't be fixed here we can only work around the error there are workarounds available (see Setting a timer for a long period of time, i.e. multiple minutes) that disable the warning. Doing the work to disable the warning in our code, doesn't help the issue (beyond disabling the warning), and adds additional SDK code/weight that is completely unnecessary.

    I'd recommend chiming in on the issue mentioned above (i.e. facebook/react-native#12981) if you aren't comfortable w/ the workaround provided

    0 讨论(0)
  • 2020-12-02 12:28

    I think the most close-aide solution to this problem (until RN fixed this internally) is the solution mentioned here.

    // add this code to your project to reset all timeouts
    const highestTimeoutId = setTimeout(() => ';');
    for (let i = 0; i < highestTimeoutId; i++) {
        clearTimeout(i); 
    }
    

    Being used that - against Firebase call I still receive one yellow box warning (on settimeout), but any concurrent warnings never come thereafter. I'm not sure calling this at which point may not trigger the only warning also, but not any concurrent warning throws anymore after Firebase's async calls.

    0 讨论(0)
  • 2020-12-02 12:32

    Just add these two lines

    import { LogBox } from 'react-native';
    
    LogBox.ignoreLogs(['Setting a timer']);
    
    0 讨论(0)
  • 2020-12-02 12:33

    What I did and it's working with me but still I don't knwo if it's a good practice or not

    Navigated to file

    node_modules\react-native\Libraries\Core\Timers\JSTimers.js

    there is a function const MAX_TIMER_DURATION_MS = 60 * 1000 and I increased the time to be 60 * 100000 and it stopeed appearing

    0 讨论(0)
  • 2020-12-02 12:33

    I'm disabling the warning with this code

    import { YellowBox } from 'react-native';
    YellowBox.ignoreWarnings(['Setting a timer']);
    
    0 讨论(0)
  • 2020-12-02 12:34

    Another approach is to use the react-native-ignore-warnings module.

    https://github.com/jamrizzi/react-native-ignore-warnings

    https://www.npmjs.com/package/react-native-ignore-warnings

    This even works for Expo apps.

    You would use it the following way . . .

    import ignoreWarnings from 'react-native-ignore-warnings';
    
    ignoreWarnings('Setting a timer');
    

    can run with android too..?

    0 讨论(0)
提交回复
热议问题