-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
regression on InteractionManager.runAfterInteractions(f), not always calling f #8624
Comments
quick workaround if anyone interested. import { InteractionManager } from "react-native";
export default {
...InteractionManager,
runAfterInteractions: f => {
// ensure f get called, timeout at 500ms
// @gre workaround https://github.com/facebook/react-native/issues/8624
let called = false;
const timeout = setTimeout(() => { called = true; f() }, 500);
InteractionManager.runAfterInteractions(() => {
if (called) return;
clearTimeout(timeout);
f();
});
}
}; |
Summary: Returns a promise-like object with a new cancel function that will dig through the queue and remove relevant tasks before they are executed. Handy when tasks are scheduled in react components but should be cleaned up in unmount. Reviewed By: devknoll Differential Revision: D3406953 fbshipit-source-id: edf1157d831d5d6b63f13ee64cfd1c46843e79fa
I'm also facing this issue in a project. cc @sahrens |
Hmm... it seems different issue where my render method is not called until a touch the screens. Super weird. |
@satya164 I may have seen something similar and using react-native-tab-view. my page won't render if i use scrollview but would work fine without a scrollview! yet to debug. |
@chirag04 I think I've seen this too. If you have a minimal example give me a link and I'll try to debug it. otherwise I'll try setting up one. It's super weird though :/ |
Ok, so seems Edit: Seems if the panHandler gets removed before releasing the touch, it never clears the handle |
@satya164 I had something similar when I upgraded to RN 0.29 with a scrollview on a tab that wasn't primary. The scrollview content wouldn't show until a touch-event happened. But if the tab with the scrollview was active when the app starts it would work just fine. I fixed it by disabling clipping on my scrollview.. Not the best solution but it works temporarly. You could also set |
Getting bit badly by this. |
In my case it was a looping animation (i.e. with the |
This is a major issue for me as well and not consistently reproducible either. I hope someone tracks this down. Every time I think I think it's fixed it rears its ugly head again and causes my components not to load after navigation. |
Has anyone figured out a fix for this issue. I randomly started experiencing this with RN 0.40 Android. It used to work great before. |
Same here, we rely extensively on this callback, and in some unidentified cases, the callback isn't fired (RN 0.39). |
@jqn, no fix but I've been using the workaround described above without issues |
Still having this problem with 0.41 |
@Exilz @jqn @aforty I had this exact issue. Solved it: The callback for For me, a couple of things worked:
Regarding 2: The callback was checking You may have similar looping animations or |
Hey @scarlac, thanks for your thorough explanation. I found out the exact same things, and This really should be documented, I guess a lot of people once struggled with infinite loading and never suspected a looping or unmounted animated component to be the source of their problems... This is a huge "gotcha" 😛 |
That makes sense @scarlac and I agree that it should be documented. However, I've encountered the issue with simply waiting for |
and it's still a breaking changes that |
It was always like that. Don't think it's a breaking change if it does what's it supposed to do, defer callbacks until no animations or touch is active. It' library's responsibility to mark an animation as not interaction of it shouldn't block interaction manager. How'd you specify it on interaction manage's side? How'd it even know what's an interaction or not? I guess it could warn if an animation is running for a long time and it's not able to run the callback. |
It's getting historical now, but I'm pretty sure it was not like that before 0.28 (because I start seeing the bug when migrating to that version, using same code base). maybe it was designed to be like that, but before 0.28 I'm pretty sure the bug was not existing (see my initial message). so I expected runAfterInteractions to execute the callback exactly once but in fact it's 0 or 1 times, randomly depending on user interactions. If the contract runAfterInteractions was from the start, intending to not guarantee callback is called, i'm ok with that, but please we need to make sure the documentation write it down, it's an important disclaimer of using that function. basically it means runAfterInteractions would not be a good candidate to be a "scheduler" function (e.g. that you would give to Relay) in opposite to requestAnimationFrame or setTimeout. |
https://facebook.github.io/react-native/docs/interactionmanager.html#runafterinteractions says that the callback will only be called after all interactions have been completed, and afaik it was the same from start. Of course if the animation never completes it'll never be called. The contract is to wait for animations to finish.
I don't think depending on user interactions is random behaviour. The method name is run after interactions, so it's gonna wait for interactions to complete. And that's what the docs say too.
If you don't need to wait for animations to complete, why use If you faced this in your code after upgrading only react native and nothing else, probably be it's just a bug and has nothing to do with interactions. |
ok, maybe I should just use setTimeout then ;-) Yeah, the method name is run after interactions but it doesn't say it's not guaranteed. Even if it returns a Cancellable, as the caller of runAfterInteractions, you don't own that cancellable, maybe it's cancelled by something else. IMO it's error prone. |
If it is, then it's a bug if I understand correctly |
@gre: no, I'm not sure where you got that. All tasks scheduled with Separately, animations should be stopped when the component being animated unmounts, which should allow |
Here is my condition:
--- Update --- --- Update Again --- let panResponde = PanResponder.create({
onStartShouldSetPanResponder: () => {
return true;
},
onPanResponderGrant: (e, gestureState) => {
// This is the KEY POINT LINE!
this._panResponder = panResponder;
this.setState({pressIn: true});
},
onPanResponderRelease: () => {
// Manually clear the interaction handle.
InteractionManager.clearInteractionHandle(this._panResponder.getInteractionHandle());
},
onPanResponderTerminate: () => {
// Manually clear the interaction handle.
InteractionManager.clearInteractionHandle(this._panResponder.getInteractionHandle());
}
});
```javascript |
Hmm, not sure why that helps - |
What I've seen is if the component unmounts when touch is active, it never clears the handle. |
I just got hit by this. We inject taskScheduler for our relay environment and in some cases the runAfterInteractions callback will never be fired and the screen would never be able to fetch the data (Only happens on android. works fine on ios). I don't have an isolated repro yet. Will debug this now. |
Ok figured it out. So in our case, rnc-archive/react-native-drawer-layout@20212c7#commitcomment-21337227 |
Still having this problem with 0.40, and it occur frequently, i have to remove all of it . |
Still having this problem with 0.45, and it occur frequently when use react-navigation |
0.46 is also affected. |
how to solve the problem?User ‘isInteraction: false’can only solve the problem when you code the animation by your own.How about the animation when you navigate or you click the TouchableOpacity? |
@mjylfz you may use the workaround shared above (second comment on this issue) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions. |
I'm on RN 0.50.3, i'm still seeing this issue. |
this is still happening on RN51 |
Te same issue. I have no animationds, I tried to delete almost everything from render function, but callback from InteractionManager.runAfterInteractions still doesn't run....Any ideas? |
Please post a repro if you face the issue. Replying with "this happens to me" doesn't help and sends notifications to everyone. |
I was planning to use Unfortunately, this is a blocking issue for me. Nevertheless, I will give a try to |
this comment #8624 (comment) can cause some troubles as well |
Could this be related to react-navigation/react-navigation#4144? A solution (implemented in React Navigation) is to save the panResponder and call The problem seems to be that when creating new panResponders in the render method the wrong release-method is called. |
Since RN 0.28,
InteractionManager.runAfterInteractions(f)
happen to sometimes never callf
.I couldn't reproduce it with some simple code, but I have an app that schedule stuff in background when leaving a screen, and use
InteractionManager.runAfterInteractions
when re-entering the screen (which happen during the navigator transition) and sometimesf
is not called.Should we assume that
runAfterInteractions
can sometimes not happen, since it's a cancellable now? (but i'm not using cancel() anywhere in my code)or is this a bug?
Thanks
The text was updated successfully, but these errors were encountered: