Skip to content
Merged
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
1 change: 1 addition & 0 deletions build/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface ActionSheetProps {
zIndex?: number;
closeOnBgTap?: boolean;
bgTransition?: string;
className?: string;
sheetTransition?: string;
reverse?: boolean;
}
Expand Down
28 changes: 16 additions & 12 deletions build/index.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/index.es.js.map

Large diffs are not rendered by default.

28 changes: 16 additions & 12 deletions build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "actionsheet-react",
"version": "1.0.13",
"version": "1.0.14",
"description": "🌟A lightweight and flexible action sheet component for the web",
"main": "build/index.js",
"module": "build/index.es.js",
Expand Down
30 changes: 16 additions & 14 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ const ActionSheet = React.forwardRef<
zIndex = 998,
closeOnBgTap = true,
bgTransition = "opacity 0.5s ease-in-out, z-index 0.5s ease-in-out",
className="action-sheet",
sheetTransition = "transform 0.3s ease-in-out",
className = "action-sheet",
sheetTransition = "transform 0.5s linear",
reverse = false,
},
ref
): JSX.Element => {
const [show, setShow] = useState(false);
const [pressed, setPressed] = useState(false);
const pressed = useRef(false);
const sheetRef = useRef<HTMLDivElement>(null);
const animationRef = useRef(0);
const masterOffset = useRef(0);
Expand All @@ -76,13 +76,14 @@ const ActionSheet = React.forwardRef<

const requestSheetDown = React.useCallback((): boolean => {
if (null !== sheetRef.current) {
sheetRef.current.style.transition = sheetTransition;
sheetRef.current.style.transform = reverse
? "translate3d(0, -101%, 0)"
: "translate3d(0, 101%, 0)";
return true;
}
return false;
}, [reverse]);
}, [reverse, sheetTransition]);

const requestSheetUp = React.useCallback((): boolean => {
if (null !== sheetRef.current) {
Expand All @@ -101,8 +102,7 @@ const ActionSheet = React.forwardRef<
}, [requestSheetDown, requestSheetUp, show]);

const onSwipeMove = (event: React.TouchEvent<HTMLDivElement>): void => {
event.stopPropagation();
if (pressed) {
if (pressed.current) {
const offset = event.touches[0].clientY - startY.current;
move(offset);
}
Expand All @@ -112,7 +112,7 @@ const ActionSheet = React.forwardRef<
event: React.MouseEvent<HTMLDivElement, MouseEvent>
): void => {
event.stopPropagation();
if (pressed) {
if (pressed.current) {
if (reverse) {
const offset = event.clientY - startY.current;
move(offset);
Expand Down Expand Up @@ -148,24 +148,26 @@ const ActionSheet = React.forwardRef<
};

const onSwipeStart = (event: React.TouchEvent<HTMLDivElement>): void => {
if (sheetRef?.current) sheetRef.current.style.transition = "none";
startY.current = event.touches[0].clientY;
changePressed(true);
};

const onMouseStart = (
event: React.MouseEvent<HTMLDivElement, MouseEvent>
): void => {
if (sheetRef?.current) sheetRef.current.style.transition = "none";
startY.current = event.clientY;
changePressed(true);
};

const changePressed = (x: boolean): void => {
setPressed(x);
pressed.current = x;
};

const onSwipeEnd = (): void => {
cancelAnimationFrame(animationRef.current);
setPressed(false);
changePressed(false);
if (Math.abs(masterOffset.current) > threshold) {
setShow(false);
if (onClose) onClose();
Expand All @@ -186,12 +188,12 @@ const ActionSheet = React.forwardRef<
left: 0,
right: 0,
bottom: 0,
background: "rgba(0, 0, 0, 0.8)",
backgroundColor: "rgba(0, 0, 0, 0.8)",
backfaceVisibility: "hidden",
...bgStyle,
transition: bgTransition,
opacity: show ? opacity : 0,
zIndex: show ? zIndex : -1,
...bgStyle,
}}
></div>
<div
Expand All @@ -217,9 +219,9 @@ const ActionSheet = React.forwardRef<
backgroundColor: "#fbfbfb",
borderTopLeftRadius: 16,
borderTopRightRadius: 16,
...sheetStyle,
touchAction: "none",
zIndex: zIndex + 1,
transition: pressed ? "transform 0.05s linear" : sheetTransition,
...sheetStyle,
}}
onMouseDown={mouseEnable ? onMouseStart : () => undefined}
onMouseMove={mouseEnable ? onMouseMove : () => undefined}
Expand All @@ -228,7 +230,7 @@ const ActionSheet = React.forwardRef<
onTouchMove={touchEnable ? onSwipeMove : () => undefined}
onTouchEnd={touchEnable ? onSwipeEnd : () => undefined}
>
{children ? children : <div style={{ height: 150 }} />}
{children}
</div>
</Fragment>
);
Expand Down