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

Make Reanimated more compliant with rules of React #5942

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tjzel
Copy link
Contributor

@tjzel tjzel commented Apr 26, 2024

Summary

Test plan


export default function RuntimeTestsRunner() {
const isRenderLocked = useRef<boolean>(false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @Latropos

How to properly define this lock inside this component?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it outdated already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it is 😄

const outRef = ref ?? animatedRef;

// @ts-expect-error TODO: Allow null as `useScrollViewOffset` ref argument.
useScrollViewOffset(null, scrollViewOffset);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @szydlovsky

Pls make it work in useScrollViewOffset (we are prisoners of our own API 💀)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjzel do we really need nullable ref here that badly? Changing it will really complicate the hook implementation. The current native implementation also throws a warning when there is no ref - which I remember may have been your idea. After all, this hook with a null ref does essentially nothing so what do we need it for?

Copy link
Contributor Author

@tjzel tjzel May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely we don't need to use nullable ref here. However:

  1. We shouldn't call this hook conditionally like before.
  2. The user can pass to Animated.ScrollView either:
    2.1 An AnimatedRef - then we have no problems whatsoever.
    2.2 A plain ref from React - then it will cause a runtime error.

In scenario 2.2 we would need to check if the passed ref is not an Animated one. If it's not, my idea would be to pass null to useScrollViewOffset hook as a special case that it shouldn't do anything. Keep in mind that we cannot just pass animatedRef to it as for now, since in this scenario it's never getting attached to anything and causes another error.

I haven't came up with some other solution here that wouldn't be hacky. If you have a better solution though, I'm all ears.

@@ -41,13 +41,16 @@ export function useFrameCallback(
});

useEffect(() => {
// Unregister previous callback.
frameCallbackRegistry.unregisterFrameCallback(ref.current.callbackId);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was unregistering here overlooked or is it not necessary? cc @tomekzaw @piaskowyk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants