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

dragBy: [".pane .draggable"] Not working #239

Open
primeKal opened this issue Jun 18, 2024 · 4 comments
Open

dragBy: [".pane .draggable"] Not working #239

primeKal opened this issue Jun 18, 2024 · 4 comments
Assignees

Comments

@primeKal
Copy link

primeKal commented Jun 18, 2024

Describe the bug
Pane is not draggable by the dragging handle.

To Reproduce
Steps to reproduce the behavior:
Use this react component
// components/MyComponent.tsx

import React, { ReactElement, useContext, useEffect } from "react"
import { useBottomSheet } from "./useBottomSheet"
import { CupertinoSettings } from "cupertino-pane"
import ModalStateContext from "../Map/context"

export interface SheetProps {
  children: ReactElement
  isDisplayed: boolean
  windowHeight: number
}

const BottomSheet = ({ children, isDisplayed, windowHeight }: SheetProps) => {
  const { state } = useContext(ModalStateContext)
  const settings: CupertinoSettings = {
    breaks: {
      top: { enabled: true, height: 400, bounce: false },
      middle: { enabled: true, height: 200, bounce: false },
      bottom: { enabled: true, height: 50, bounce: false },
    },
    topperOverflow: true,
    bottomClose: false,
    freeMode: true,
    buttonDestroy: false,
  }

  const { presentPane, hidePane } = useBottomSheet(
    ".cupertino-pane",
    settings,
    true,
  )
  useEffect(() => {
    if (isDisplayed) {
      presentPane()
    } else {
      hidePane()
    }
  }, [isDisplayed])

  return (
    <>
      <div className="cupertino-pane">
        {children}
      </div>
    </>
  )
}

export default BottomSheet

using this custome hook

// hooks/useCupertinoPane.ts
import { useContext, useEffect, useRef, useState } from "react"
import { CupertinoPane, CupertinoSettings } from "cupertino-pane"
import ModalStateContext from "../Map/context"

export const useBottomSheet = (
  selector: string,
  settings: CupertinoSettings,
  newPane: boolean = false,
) => {
  const paneRef = useRef<CupertinoPane | null>(null)
  const [showContent, setShowContent] = useState(false)
  const { state, dispatch } = useContext(ModalStateContext)

  useEffect(() => {
    if (!paneRef.current && newPane) {
      paneRef.current = new CupertinoPane(selector, {
        ...settings,
        parentElement: "body",
        dragBy: [".pane .draggable"],
        bottomClose: false, 
        events: {
          onDrag: (event) => {
            console.log("drag event")
            if (event.to === "bottom") {
              setShowContent(true)
            } else {
              setShowContent(false)
            }
          },
        },
      })
    }
    return () => {
      paneRef.current?.destroy()
    }
  }, [])

  const presentPane = async () => {
    await paneRef.current?.present({ animate: true })
  }
  const hidePane = async () => {
    console.log("in pane hider")
    paneRef.current?.destroy({ animate: true })
  }
  const updatePaneHeights = async () => {
    console.log("in updating heights")
    await paneRef.current?.updateScreenHeights()
    await paneRef.current?.setBreakpoints({
      top: { enabled: true, height: 800, bounce: false },
      middle: { enabled: true, height: 400, bounce: false },
      bottom: { enabled: true, height: 100, bounce: false },
    })
    await paneRef.current?.moveToBreak("bottom")
  }

  return { presentPane, hidePane, updatePaneHeights }
}

Simply use this component using any component

      <BottomSheet
        isDisplayed={isMobile}
        windowHeight={screenHeight}
      >
        {<div>Hiiii pane</div>}
      </BottomSheet>

Expected behavior
To be dragged by the handle ONLY

Please help me here, any helpful comment is apricated

@primeKal
Copy link
Author

"cupertino-pane": "^1.4.21",
    "react": "^18.2.0",

@roman-rr roman-rr self-assigned this Jun 18, 2024
@roman-rr
Copy link
Collaborator

@primeKal Thank you for issue, I am also received your e-mail. Will check out in 1-2 days.

@primeKal
Copy link
Author

Thank you.

@roman-rr
Copy link
Collaborator

@primeKal Let's go step-by-step to fix this issue.
This is JavaScript playground, and here you might see usage of

{ 
  dragBy: [".pane .draggable"]
}

You can try to experiment and see that it's not a library issue; the JavaScript example works as expected. I'm not sure why the React version isn't working. I guess there is something overlapping the pane container.

To help me, please create and share a reproduction demo as a GitHub repository, or use an online sandbox such as JSFiddle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants