initialSnap not working with dynamic value in snapPoints
See original GitHub issueHi, When I set
initialSnap={1}
with
const snapPoints = [sheetHeight, 0];
where sheetHeight
comes from the props, the BottomSheet is already open. There is nothing I can do to change it, it seems so.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:7
Top Results From Across the Web
Dynamic Input For Lines Starting with a Snap Not Working
Solved: When trying to draw a line starting with a snap, I want to spcify a defined length of the line with dynamic...
Read more >Snapping to Points on Elements - MicroStation
Snapping to a point on an element at which that element is overlapped by another element(s) can be difficult, especially when working with...
Read more >Using dynamic guides - Corel
For more information about snap points and snapping modes, see Snapping objects. As you drag an object along a dynamic guide, you can...
Read more >React Native snapToOffsets for only one snap and then scroll ...
User a ternary operator in the snapToInterval property with the amount you want the for the first snap and what the snap should...
Read more >Working with the Cursor-Snap System in Altium Designer
Covers user-definable grids and snap guides, as well as object and axis ... an enabled object snap point (and the Axes feature is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The general problem is that, when the sheet height dynamically changes, the positioning of the sheet (at snapPoint 0) is not adjusted – which makes the sheet seem to jump to a snap point value of (heightAfterDynamicChange - heightBeforeDynamicChange).
@kyryloz’s solution works only if the sheet does not have to be rendered at the lower height, but not if both heights represent actual content. I had this problem for a menu which could contain a different number of items, depending on the app state.
The only solution to the problem seems to be to make sure that the highest snap point stays constant. I.e., I would have three snap points, [maxHeight, dynamicHeight, 0], and if the menu opens, I snap to dynamicHeight (so the maxHeight snap point is not actually used). For the case that the user does drag the bottom sheet further up to the maxHeight snap point, I render white space of height (maxHeight - dynamicHeight) below the actual sheet content.
There was a reported issue about unwanted behaviour when snapPoints are not in descending order inside the array (note has already been added to README). If the whole problem is connected to the initial value as @kyryloz stated, @mitschabaude’s solution should work, but it’s also worth to mention that if there’s more than one dynamic snapPoint you should remember to keep them ordered. I think that should be enough.