Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

FixsnapToPosition function call, right away after the mount.#1623

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
beqramo wants to merge2 commits intogorhom:v4
base:v4
Choose a base branch
Loading
frombeqramo:master

Conversation

@beqramo
Copy link
Contributor

@beqramobeqramo commentedNov 8, 2023
edited
Loading

Fixes:#1294

Motivation

WhensnapToPosition gets called right away after a mount,animatedContainerHeight has an initial value of -999, if the prop didn't get passed. It is happening as the package can't calculate height right away on the mount. in simple termsonLayout function takes time to be called and to update the value ofanimatedContainerHeight

That means thatsnapToPosition causes some problems.
To fix the issue, we need to wait for the update of the value ofanimatedContainerHeight and then continue calculating thenextPosition value fromnormalizeSnapPoint function.

Because of that, I added a listener if I see thatanimatedContainerHeight still has an initial value. after I receive the update, I'm following the same process as it was before.

I was forced to update the Reanimated package due to the recent addition of the listener feature. I've been using the updated Reanimated package in my production app for a while now, and it's been working seamlessly, so it shouldn't be a problem.

Thank you.

MBach reacted with thumbs up emoji
@gorhomgorhom self-assigned thisNov 26, 2023
@gorhomgorhom added the v4Written in Reanimated v2 labelNov 26, 2023

/**
* mark the new position as temporary.
* Checks whether the library has measured the container's height or if it was passed from props.
Copy link
Owner

Choose a reason for hiding this comment

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

why not early exit this method , and ensure to listen toisLayoutCalculated ?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I don't believe exiting from a function in that manner is correct. The caller has requested to open the bottom sheet, and the caller doesn't have any information on whether the package is ready or undergoing some heavy operations.

Regarding listening to isLayoutCalculated, if I understood it correctly, it seems more appropriate. I will update it after we know precisely whether there is a problem or not.

For more details on these matters, please refer to the comment section below.

@gorhom
Copy link
Owner

thanks@beqramo for submitting this PR, but i think it is not about layout not being ready,isLayoutCalculated is responsible to trigger the on mount animation, which waits till container height to be calculated before it become truthful

@gorhom
Copy link
Owner

could you please provide a reproducible sample code of the issue ?

@henrymoulton
Copy link

Noticed Reanimated 3 has an unreleased PR related to a race conditionsoftware-mansion/react-native-reanimated#5224 - wonder if there's a relation to this issue.

@beqramo
Copy link
ContributorAuthor

beqramo commentedNov 27, 2023
edited
Loading

Hi, thanks for your feedback,@gorhom.

I will try to provide more context before presenting the conclusions:

When snapToPosition is called from the ref right away after mount:

useEffect(()=>{sheetRef.current?.snapToPosition(400);},[]);

At that time, SOMETIMES, the value of isLayoutCalculated is false. Why?

The value of isLayoutCalculated changes after the onLayout callback gets called (when the component is rendered and we have sizes and other details about the container).
We are facing some kind of race condition; sometimes, onLayout is getting called first, and isLayoutCalculated and consecutively, animatedContainerHeight do have correct values.
It is like, in short, which one will get called first? useEffect or onLayout?

What are the solutions? (Sorted from worse to best solution)

  1. To have some kind of callback prop like "onReady" that will indicate the parent component that the bottom-sheet is ready.
  2. Return a specific value like "not_ready" when it will be triggered from the ref, right away after mount.
  3. Take ownership of the problem from the library side; the library needs to automatically wait for the completion of all height calculation processes.

Reproducible sample code:
I first faced this problem on my app. When searching for solutions, I found that another developer already had thesame problem.

Other than that I will drop my code snippet too:

constsheetRef=useRef<BottomSheet>(null);useEffect(()=>{// call right after mountsheetRef.current?.snapToPosition(400);},[]);return<BottomSheetref={sheetRef}snapPoints={[10]}index={-1}><Columnmt={7}px={5}stretch>{/* children here*/}</Column></BottomSheet>

Thank you.

Hope I will not waste your time.

@beqramo
Copy link
ContributorAuthor

beqramo commentedNov 27, 2023
edited
Loading

@henrymoulton Thanks for the info,
I think that one is a different issue from this.
From the funny side: I think I was facing that issue too and I'm happy that it is resolved and you informed me about it, waiting for the release.

Thank you

@henrymoulton
Copy link

@beqramo can you confirm it still happens if you're using Reanimated V2?

@beqramo
Copy link
ContributorAuthor

Hi@henrymoulton,

I am currently using my fork, and I haven't encountered the issue. Additionally, I am utilizing reanimated version 3. If you wish to test it, the problem might be more noticeable on low-end devices, particularly Android.

The issue you mentioned seems slightly different here. The problem lies in the synchronization of theonLayout andsnapToPosition functions. The challenge arises because the first function is not synchronous, and its trigger can be delayed. That creates problem ifsnapToPosition gets called right away on parent component mount.

Thank you.

CostasCF and MBach reacted with thumbs up emoji

@MBach
Copy link

Seems interesting! I'd like to see this PR merged if possible

@jspizziri
Copy link

@gorhom , this is still an issue inv5. It's very difficult to reproduce as it depends on execution order so it can vary from device to device, platform to platform, and codebase to codebase.

It would seem that a simple solution could simply be to provide a callback on the BottomSheet like:onReady which triggers onceisLayoutCalculated istrue. Either that or queuing up calls to snap and then executing them once theisLayoutCalculated istrue.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@gorhomgorhomgorhom left review comments

Assignees

@gorhomgorhom

Labels

v4Written in Reanimated v2

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[v4] | [v2] snapToPosition opening bottomsheet to maximum screen height and snapToIndex not working

5 participants

@beqramo@gorhom@henrymoulton@MBach@jspizziri

[8]ページ先頭

©2009-2025 Movatter.jp