Skip to content

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

@primeKal

Description

@primeKal

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions