-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Add support for AlarmManager in Timing to allow proper handling of long timers #12981
Comments
Great improvement! |
this would help with socket.io which keeps a timer of |
And Firebase which is also using long timers. |
I am getting following warning while using firebase library
How to get rid of this warning... |
I am getting following warning while using firebase library too. Somebody know how to solve this problem? |
I am also getting this warning with firebase.
|
Same issue ( "dependencies": {
"apisauce": "0.11.0",
"format-json": "1.0.3",
"lodash": "4.17.4",
"markdown-it": "^8.3.1",
"native-base": "^2.1.3",
"normalizr": "^3.2.2",
"prop-types": "^15.5.10",
"querystringify": "1.0.0",
"ramda": "0.23.0",
"react": "16.0.0-alpha.6",
"react-markdown": "^2.5.0",
"react-native": "0.44.0",
"react-native-animatable": "1.2.0",
"react-native-config": "0.4.2",
"react-native-device-info": "0.10.2",
"react-native-drawer": "2.3.0",
"react-native-htmlview": "0.9.0",
"react-native-i18n": "1.0.0",
"react-native-linear-gradient": "^2.0.0",
"react-native-photo-view": "^1.2.0",
"react-native-router-flux": "3.39.1",
"react-native-scrollable-tab-view": "*",
"react-native-share": "^1.0.20",
"react-native-vector-icons": "4.1.1",
"react-navigation": "^1.0.0-beta.9",
"react-redux": "5.0.4",
"redux": "3.6.0",
"redux-persist": "4.6.0",
"redux-saga": "0.15.3",
"reduxsauce": "0.4.1",
"seamless-immutable": "7.1.2"
},
"devDependencies": {
"ava": "^0.18.2",
"babel-eslint": "^7.1.1",
"babel-preset-es2015": "^6.18.0",
"enzyme": "^2.6.0",
"husky": "^0.13.1",
"ignite-animatable": "^0.3.1",
"ignite-dev-screens": "^2.0.0-beta.9",
"ignite-i18n": "^0.1.1",
"ignite-ir-boilerplate-2016": "^0.2.2",
"ignite-vector-icons": "^0.2.1",
"mockery": "^2.0.0",
"nyc": "^10.1.2",
"react-addons-test-utils": "^15.3.1",
"react-dom": "^15.4.0",
"react-native-mock": "^0.3.1",
"reactotron-apisauce": "^1.7.0",
"reactotron-react-native": "^1.7.0",
"reactotron-redux": "^1.7.0",
"reactotron-redux-saga": "^1.7.0",
"snazzy": "^6.0.0",
"standard": "^8.6.0"
} |
I'm experiencing a similar issue using 0.44.0 on Android. I am also not using firebase:
|
Hi there guys.. was wondering Is there any quick work around for this. I'm using:
Its very annoying popping out while I'm developing.. is there anyway I can hide the warning for now?? |
Same issue here with firebase 3.9.0 |
If it bothers you just add |
@skv-headless Opinion incoming. :) In my opinion that attitude towards problems needs to go away. I've been seeing it pop up more often and it's causing people to ignore warnings. They're warnings. They warn you. Don't ignore them, do something. I've seen apps where all warnings just get ignored, even deprecation notices. Then your app breaks and you're left wondering why. In this case, you can configure these timeouts and lower them, or setup a different approach of dealing with them. Maybe even poke the maintainers of the libraries and ask them to help come up with a solution. My advise, is to follow this thread until someone smart comes up with an actual solution, so you can then educate yourself with that answer. And then maybe, in the meantime (if you can't / don't want to teckle the issue) ignore the warnings. TL;DR; Yes, you can ignore the warnings temporarily. Just check in every now and then to see what the status is and if there's any action required. |
@imamatory I think is by Rectotron |
If so, this warning can be simply ignored. |
@imamatory I hope the real solution is just as easy |
Hi, I think I found the solution: |
@nicolasZZ hi, Thanks for the solution. but Is that a good practice to modify the |
@nicolasZZ @AmroAly In my mind this solution is not a good practice because it is very unstable, the best is ignore the alert while the official solution is released. console.ignoredYellowBox = [
'Setting a timer'
] the @skv-headless's solution is good but in my case only works with "enter" between of the parenthesis |
@rigobcastro Thanks that hides the annoying alerts. |
@DZuz14 it would be awesome if you could sent a PR or atleast get the conversation started. Thanks 👍 |
hi~ I found this solution personal server nodejs and scoket.io const express = require('express')
const app = express()
const server = require('http').Server(app)
const io = require('socket.io')(server, {pingTimeout: 30000}) Thanks! |
I have a simple react native project for android and I'm using firebase auth with react native for Login and Signup, but I got that yellow error, What should I do? Link of my Question in stackoverslow (https://stackoverflow.com/questions/44603362/setting-a-timer-for-a-long-period-of-time-i-e-multiple-minutes ) |
Thank You @DZuz14
I want to use firebase auth with react native for Login and Signup but I got That yellow error, I asked stackoverflow through this link: (https://stackoverflow.com/questions/44603362/setting-a-timer-for-a-long-period-of-time-i-e-multiple-minutes) |
Thanks @DZuz14 So if you look into the npm package called So I guess we have to convince the Firebase guys actually to change to your approach and distribute a package made especially for |
@BerndWessels https://www.npmjs.com/package/react-native-firebase Have you looked at this? Says it allows firebase to run on the native thread. Not sure how true that is, but might be worth a look. You might even be using that, I'm not sure. |
@DZuz14 Thanks, I'll check that out. |
Where should I add this I tried in Screen file and action file, still not working |
Just put it somewhere in your App.js file. I put it in my constructor for example. |
I think whoever is using Firebase can solve this problem configuring the persistence of app after (signIn / signUp) *after create a new user, he will be automatically sign in https://firebase.google.com/docs/auth/web/auth-state-persistence so... after auth a user, a time variable is created. the default for firebase is a you can change using: or using a localStorage... |
Until they solve it in a definitive way... import { YellowBox } from "react-native"; Once solved, the junk code is removed and voila! |
This can be solved with RxJS. Basically splits your import { of, range } from 'rxjs';
import {
concatMap,
delay,
filter,
mapTo,
switchMap,
tap,
} from 'rxjs/operators';
// ~ setTimeout(..., 5200);
const source = of(5200).pipe(
switchMap(duration => {
const times = Math.floor(duration / 1000); // = 5
const remainder = duration % 1000; // = 200
return range(1, times).pipe(
concatMap(i => of(i).pipe(delay(1000))),
tap(console.log),
filter(i => i === times),
delay(remainder),
tap(console.log),
mapTo('Done !'),
);
}),
);
source.subscribe(console.log);
1 // After 1s
2 // After 2s
3 // After 3s
4 // After 4s
5 // After 5s
5 // After 5s + 200 ms
'Done !' |
Great! How about for Firestore though? |
if you are using the old firebase SDK migrate to the firestore admin SDK. most issues will be solved |
Still nobody is able to solve this issue. #shame on you developers ;p |
Never shame open source contributors. It's a shame this has not been fixed but the source is open, if you know how to solve it I'm sure they would appreciate a pull-request. That said why on earth is this issue closed. |
Because it should be fixed in the offending libraries. And the offending libraries don't see a problem with the way it has been implemented. So nobody will fix it because both sides don't think it's broken. They can be shamed a little bit for this 😄 |
Guys, I think this hasn't been "resolved" for the simple reason that it is an extremely bad idea to use long timers. If you want to run timers in background / events in the future, you will need a native library to do so. This is also specifically difficult on both platforms due to background execution constraints. |
Based on @eightyfive 's comment we made a drop in replacement for rxjs6 Still a question remains, can someone explain if the "Timer module" stays locked when using smaller intervals? Basically just causing the timer to halt when the app is not in the foreground. Or does this just hide the problem? import { switchMap, concatMap, delay as nativeDelay, mapTo, filter, switchMapTo, repeat } from 'rxjs/operators'
import { range, of, race, throwError, TimeoutError } from 'rxjs'
const TIMER_INTERVAL = 1000
const reactNativeTimer = (duration) => {
const times = Math.floor(duration / TIMER_INTERVAL)
const remainder = duration % TIMER_INTERVAL
if (times < 1) {
return of(true).pipe(nativeDelay(remainder))
}
return range(1, times).pipe(
concatMap(i => of(i).pipe(nativeDelay(TIMER_INTERVAL))),
filter(i => i === times),
nativeDelay(remainder)
)
}
/**
* React Native compatible version of delay pipe
* @param {number} duration in ms
*/
export const delay = (duration) => {
return (source) => {
return source.pipe(
switchMap(next =>
reactNativeTimer(duration).pipe(mapTo(next))
)
)
}
}
/**
* React Native compatible version of timeout pipe
* @param {number} duration in ms
*/
export const timeout = (duration) => {
return (source) => {
const timeoutTimer = reactNativeTimer(duration).pipe(
switchMapTo(throwError(new TimeoutError()))
)
return race(source, timeoutTimer)
}
}
/**
* React Native compatible version of interval
* @param {number} duration in ms
*/
export const interval = (duration) => {
return reactNativeTimer(duration).pipe(
repeat()
)
} |
The funny thing about it, that everyone in this thread discussing workaround to ignore this warning. #front-end #millennials |
This #millenial would like to point out that:
That said I will again point out this issue should not be closed, it is marked |
- Auto logout is not very fancy, and should be refactored in the future facebook/react-native#12981 * 4_Shop_App/App.js - Imported a new component a Wrapper just to have access to our store * 4_Shop_App/navigation/ShopNavigator.js - Create this new component to check first (after the splash screen) if there is a logged user. if not redirect to Auth screen - We need to create this component to have access to our store - With the help of useRef hook, we can have access to the properties of the component * 4_Shop_App/navigation/ShopNavigator.js - Added a react component to the side drawer, so we can click to logout - Added our StartupScreen as the first screen of the stack * 4_Shop_App/store/actions/auth.js - Changed SIGNUP and LOGIN to AUTHENTICATE - Added a helper function authenticate() to dispatch the (userId, token, expiryTime) - Added a logout(), inside this function we call AsyncStorage.removeItem('') to remove the item from our local storage - Added a auto logout, it checks for the expiration date, and creates a setTimeout with the remaining time - Added a saveDataToStorage() to save the user info in the local storage * 4_Shop_App/store/reducers/auth.js - Removed the cases LOGIN and SIGNUP - Added LOGOUT -> basically sets to the initial state * 4_Shop_App/screens/StartupScreen.js - This is the first page of the app - It's very fast, and we wont see it (it's just an ActivityIndicator) - Basically it checks if there is a user in the local storage - if yes, checks the expiration date - if everything is ok, redirects to "Shop" screen - if no, or expiration date is expired - redirects to "Auth" screen
For firebase/firestore users: I simply reverted to using the REST endpoints directly for firestore calls. Since I only needed auth and firestore, that solved my problems rather easily. Snippet here: |
…nutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See facebook/react-native#12981 for more info. (Saw setTimeout with duration 446716ms)' warning
I did it inside App() as follows: import { YellowBox } from 'react-native'; Remeber |
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
there is a function |
Hey there, Thanks <3 |
Hey all, we're deciding to lock this issue. I know this problem is frustrating for many of you and I want to take the time to help understand why we're making this decision. How timers work on Android in React NativeReact Native has a custom implementation of JS timers like What happens if I set a timer with a long interval?Here's my understanding, from reading the code and testing it out a bit:
Why shouldn't we call timers with long intervals?I think this is primarily a correctness issue, and less about performance. The issue is that you can't rely on long timers if the user backgrounds your app. If you don't mind having your timer get activated later when the app is foregrounded again, then I think ignoring the YellowBox warning is a good idea. On the other hand, if your timer expects to be called for the lifetime of a session, and shouldn't be triggered again on foreground, you'll need to do something to make sure the timer is ignored on foreground. How do I use third-party libraries like Socket.io and Firebase that set long timers?I don't know the details of these third-party libraries. It ultimately comes down to the question above. If these third-party libraries will have issues dealing with timers being resolved on foreground, then you'll need to figure out a way to fix that. Some comments above propose ways of doing this for Firebase, for instance. Ultimately, though, you may be better served by relying on a library that's developed specifically with React Native in mind. On the other hand, if the third-party library has no issues with timers being resolved on foreground, then you can ignore the error. Why can't
|
Setting timers for multiple minutes isn't handled properly in React Native on Android: it keeps the Timing module awake instead of relying on the system waking us up when the timer should go off.
We should explore setting a cut off at which we delegate to AlarmManager and Handler.postDelayed instead of handling the timers using framecallbacks.
The text was updated successfully, but these errors were encountered: