mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-28 12:15:37 +08:00
Support options param for requestIdleCallback
Summary: The `requestIdleCallback` sometimes doesn't work in `Debug JS Remotely` mode if I use real device, the callback will never called. I guess it may be debugger worker and device caused by the time gap, or some cause websocket blocking, so it's just sometimes happening. I think we can support [options](https://developer.mozilla.org/zh-TW/docs/Web/API/Window/requestIdleCallback#Parameters) for that. Added an example `Run requestIdleCallback with timeout option` for Timers of UIExplorer, it use `{ timeout: 100 }` option with burn CPU 100ms, we can see `didTimeout` is true. Closes https://github.com/facebook/react-native/pull/13116 Differential Revision: D4894348 Pulled By: hramos fbshipit-source-id: 29c4c2fe5634b30a8bf8d3495305cd8f635ed922
This commit is contained in:
committed by
Facebook Github Bot
parent
b975342e7b
commit
cf51aee9a0
@@ -52,6 +52,10 @@ class RequestIdleCallbackTester extends React.Component {
|
||||
Burn CPU inside of requestIdleCallback
|
||||
</RNTesterButton>
|
||||
|
||||
<RNTesterButton onPress={this._runWithTimeout.bind(this)}>
|
||||
Run requestIdleCallback with timeout option
|
||||
</RNTesterButton>
|
||||
|
||||
<RNTesterButton onPress={this._runBackground}>
|
||||
Run background task
|
||||
</RNTesterButton>
|
||||
@@ -78,6 +82,16 @@ class RequestIdleCallbackTester extends React.Component {
|
||||
});
|
||||
};
|
||||
|
||||
_runWithTimeout = () => {
|
||||
cancelIdleCallback(this._idleTimer);
|
||||
this._idleTimer = requestIdleCallback((deadline) => {
|
||||
this.setState({
|
||||
message: `${deadline.timeRemaining()}ms remaining in frame, it did timeout: ${deadline.didTimeout ? 'yes' : 'no'}`
|
||||
});
|
||||
}, { timeout: 100 });
|
||||
burnCPU(100);
|
||||
};
|
||||
|
||||
_runBackground = () => {
|
||||
cancelIdleCallback(this._idleTimer);
|
||||
const handler = (deadline) => {
|
||||
|
||||
Reference in New Issue
Block a user