forked from RSSNext/Follow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: modal structure, add z-index 1001, fixed RSSNext#896
Signed-off-by: Innei <tukon479@gmail.com>
- Loading branch information
Showing
9 changed files
with
206 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
apps/renderer/src/components/ui/modal/stacked/internal/use-animate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { useAnimationControls } from "framer-motion" | ||
import { useCallback, useEffect } from "react" | ||
|
||
import { nextFrame } from "~/lib/dom" | ||
|
||
import { modalMontionConfig } from "../constants" | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const useModalAnimate = (isTop: boolean) => { | ||
const animateController = useAnimationControls() | ||
useEffect(() => { | ||
nextFrame(() => { | ||
animateController.start(modalMontionConfig.animate) | ||
}) | ||
}, [animateController]) | ||
const noticeModal = useCallback(() => { | ||
animateController | ||
.start({ | ||
scale: 1.05, | ||
transition: { | ||
duration: 0.06, | ||
}, | ||
}) | ||
.then(() => { | ||
animateController.start({ | ||
scale: 1, | ||
}) | ||
}) | ||
}, [animateController]) | ||
|
||
useEffect(() => { | ||
if (isTop) return | ||
animateController.start({ | ||
scale: 0.96, | ||
y: 10, | ||
}) | ||
return () => { | ||
try { | ||
animateController.stop() | ||
animateController.start({ | ||
scale: 1, | ||
y: 0, | ||
}) | ||
} catch { | ||
/* empty */ | ||
} | ||
} | ||
}, [isTop]) | ||
|
||
return { | ||
noticeModal, | ||
animateController, | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
apps/renderer/src/components/ui/modal/stacked/internal/use-drag.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useDragControls } from "framer-motion" | ||
import type { PointerEventHandler, RefObject } from "react" | ||
import { useCallback } from "react" | ||
|
||
import { useResizeableModal } from "../hooks" | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const useModalResizeAndDrag = ( | ||
modalElementRef: RefObject<HTMLDivElement>, | ||
{ | ||
resizeable, | ||
draggable, | ||
}: { | ||
resizeable: boolean | ||
draggable: boolean | ||
}, | ||
) => { | ||
const dragController = useDragControls() | ||
const { | ||
handleResizeStop, | ||
handleResizeStart, | ||
relocateModal, | ||
preferDragDir, | ||
isResizeable, | ||
resizeableStyle, | ||
} = useResizeableModal(modalElementRef, { | ||
enableResizeable: resizeable, | ||
dragControls: dragController, | ||
}) | ||
|
||
const handleDrag: PointerEventHandler<HTMLDivElement> = useCallback( | ||
(e) => { | ||
if (draggable) { | ||
dragController.start(e) | ||
} | ||
}, | ||
[dragController, draggable], | ||
) | ||
|
||
return { | ||
handleDrag, | ||
handleResizeStart, | ||
handleResizeStop, | ||
relocateModal, | ||
preferDragDir, | ||
isResizeable, | ||
resizeableStyle, | ||
|
||
dragController, | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
apps/renderer/src/components/ui/modal/stacked/internal/use-select.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useCallback, useRef } from "react" | ||
|
||
import { nextFrame } from "~/lib/dom" | ||
|
||
/** | ||
* @internal | ||
* | ||
* Handle select text in modal | ||
*/ | ||
export const useModalSelect = () => { | ||
const isSelectingRef = useRef(false) | ||
const handleSelectStart = useCallback(() => { | ||
isSelectingRef.current = true | ||
}, []) | ||
const handleDetectSelectEnd = useCallback(() => { | ||
nextFrame(() => { | ||
if (isSelectingRef.current) { | ||
isSelectingRef.current = false | ||
} | ||
}) | ||
}, []) | ||
|
||
return { | ||
isSelectingRef, | ||
handleSelectStart, | ||
handleDetectSelectEnd, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.