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

Adjust onSettle index of BottomSheet #946

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion example/src/BottomSheetExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ const BottomSheetExample: React.FC = () => {
const bottomSheetRef = React.useRef<any>();
return (
<View style={{ flex: 1 }}>
<BottomSheet style={{ alignItems: "center" }} ref={bottomSheetRef}>
<BottomSheet
style={{ alignItems: "center" }}
ref={bottomSheetRef}
onSettle={(newIndex: number) => {
try {
console.log("onSettle", newIndex);
} catch (error) {
console.error("Error in onSettle:", error);
}
}}
>
<Text>This is a bottom Sheet</Text>
</BottomSheet>
<Button
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/BottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const BottomSheet = React.forwardRef<BottomSheetComponent, BottomSheetProps>(
borderWidth,
borderColor: borderColor ?? theme.colors.border.brand,
}}
onChange={(index) => onSettle?.(mappedSnapPoints.length - index - 1)}
onChange={(index) => onSettle?.(index)}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is the issue. Looking at the linear issue (and testing on my own), seems the bottom sheet has 4 snap points, even though by default there should only be 3 (top, middle, bottom). I think this inconsistency is what is leading to the incorrect index, but the existing logic for this is still correct.

Copy link
Collaborator

@YoussefHenna YoussefHenna Aug 28, 2024

Choose a reason for hiding this comment

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

Seems there's always an additional snap point for some reason, hmm..

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can investigate this later today, but let me know if you have any idea why this could be happening.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ya, I will investigate more today 🙏 thanks for point out

>
<BottomSheetScrollView
contentContainerStyle={[styles.contentContainerStyle, style]}
Expand Down
Loading