Skip to content
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

fix: move DelayedFreeze setImmediate into an effect #1980

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/index.native.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import React, { PropsWithChildren, ReactNode } from 'react';
import React, { useEffect, PropsWithChildren, ReactNode } from 'react';
import {
Animated,
Image,
Expand Down Expand Up @@ -194,13 +194,14 @@
// flag used for determining whether freeze should be enabled
const [freezeState, setFreezeState] = React.useState(false);

if (freeze !== freezeState) {
// setImmediate is executed at the end of the JS execution block.
// Used here for changing the state right after the render.
setImmediate(() => {
useEffect(() => {
const id = setImmediate(() => {
setFreezeState(freeze);
});
}
return () => {
clearImmediate(id);
}
}, [freeze])

return <Freeze freeze={freeze ? freezeState : false}>{children}</Freeze>;
}
Expand Down Expand Up @@ -487,7 +488,7 @@
console.warn(
'Importing SearchBar is only valid on iOS and Android devices.'
);
return View as any as ReactNode;

Check warning on line 491 in src/index.native.tsx

View workflow job for this annotation

GitHub Actions / install-and-lint

Unexpected any. Specify a different type
}

return (
Expand Down
Loading