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

[Feature] added args support on open and close events #194

Open
wants to merge 2 commits 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
8 changes: 4 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ interface RBSheetProps {
/**
* Callback function that will be called after the bottom sheet has been opened.
*/
onOpen?: () => void;
onOpen?: (openArgs?:any) => void;

/**
* Callback function that will be called after the bottom sheet has been closed.
*/
onClose?: () => void;
onClose?: (closeArgs?:any) => void;

/**
* Your own compoent.
Expand All @@ -103,12 +103,12 @@ interface RBSheetRef {
/**
* The method to open bottom sheet.
*/
open: () => void;
open: (openArgs?:any) => void;

/**
* The method to close bottom sheet.
*/
close: () => void;
close: (closeArgs?:any) => void;
}

declare const RBSheet: React.ForwardRefExoticComponent<
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const RBSheet = forwardRef((props, ref) => {

// Exposing component methods to parent via useImperativeHandle hook
useImperativeHandle(ref, () => ({
open: () => handleSetVisible(true),
close: () => handleSetVisible(false),
open: (openArgs) => handleSetVisible(true, openArgs),
close: (closeArgs) => handleSetVisible(false, closeArgs),
}));

// Function to create PanResponder
Expand Down Expand Up @@ -83,12 +83,12 @@ const RBSheet = forwardRef((props, ref) => {
const panResponder = useRef(createPanResponder()).current;

// Function to handle the visibility of the modal
const handleSetVisible = visible => {
const handleSetVisible = (visible, otherParams=undefined) => {
if (visible) {
setModalVisible(visible);
// Call onOpen callback if provided
if (typeof onOpen === 'function') {
onOpen();
onOpen(otherParams);
}
// Animate height on open
Animated.timing(animatedHeight, {
Expand All @@ -108,7 +108,7 @@ const RBSheet = forwardRef((props, ref) => {
pan.setValue({x: 0, y: 0});
// Call onClose callback if provided
if (typeof onClose === 'function') {
onClose();
onClose(otherParams);
}
});
}
Expand Down