TScroller 추가, TBody 수정
This commit is contained in:
@@ -3,6 +3,7 @@ import React from "react";
|
||||
import SpotlightContainerDecorator from "@enact/spotlight/SpotlightContainerDecorator";
|
||||
import css from "./TBody.module.less";
|
||||
import { SpotlightIds } from "../../utils/SpotlightIds";
|
||||
import TScroller from "../TScroller/TScroller";
|
||||
|
||||
const Container = SpotlightContainerDecorator(
|
||||
{ enterTo: "last-focused", preserveId: true },
|
||||
@@ -13,6 +14,7 @@ export default function TBody({
|
||||
children,
|
||||
className,
|
||||
spotlightId = SpotlightIds.TBODY,
|
||||
scrollable = true,
|
||||
...rest
|
||||
}) {
|
||||
return (
|
||||
@@ -21,7 +23,11 @@ export default function TBody({
|
||||
{...rest}
|
||||
className={classNames(css.tBody, className)}
|
||||
>
|
||||
{scrollable ? (
|
||||
<TScroller className={css.tScroller}>{children}</TScroller>
|
||||
) : (
|
||||
{ children }
|
||||
)}
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
.tScroller {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
114
com.twin.app.shoptime/src/components/TScroller/TScroller.jsx
Normal file
114
com.twin.app.shoptime/src/components/TScroller/TScroller.jsx
Normal file
@@ -0,0 +1,114 @@
|
||||
import classNames from "classnames";
|
||||
import React, { useCallback, useEffect, useRef, useState } from "react";
|
||||
import Scroller from "@enact/sandstone/Scroller";
|
||||
import { Job } from "@enact/core/util";
|
||||
import { on, off } from "@enact/core/dispatcher";
|
||||
|
||||
import css from "./TScroller.module.less";
|
||||
|
||||
export default function TScroller({
|
||||
className,
|
||||
children,
|
||||
verticalScrollbar = "hidden",
|
||||
focusableScrollbar = false,
|
||||
direction = "vertical",
|
||||
horizontalScrollbar = "hidden",
|
||||
scrollMode,
|
||||
onScrollStart,
|
||||
onScrollStop,
|
||||
...rest
|
||||
}) {
|
||||
const isScrolling = useRef(false);
|
||||
const scrollPosition = useRef("top");
|
||||
|
||||
const [onMoveScrollBarEffect, setOnMovevScrollBarEffect] = useState(false);
|
||||
const [isMounted, setIsMounted] = useState(false);
|
||||
|
||||
const offMoveScrollBarEffect = new Job((func) => func(), 1000);
|
||||
|
||||
useEffect(() => {
|
||||
setIsMounted(true);
|
||||
|
||||
return () => setIsMounted(false);
|
||||
}, []);
|
||||
|
||||
const handleWheel = useCallback(() => {
|
||||
if (!onMoveScrollBarEffect) {
|
||||
setOnMovevScrollBarEffect(true);
|
||||
|
||||
offMoveScrollBarEffect.current.start(setOnMovevScrollBarEffect);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}, [offMoveScrollBarEffect, onMoveScrollBarEffect]);
|
||||
|
||||
useEffect(() => {
|
||||
on("wheel", handleWheel, document.getElementById("TScroller"));
|
||||
|
||||
return () => {
|
||||
off("wheel", handleWheel, document.getElementById("TScroller"));
|
||||
};
|
||||
}, [handleWheel]);
|
||||
|
||||
const _onScrollStart = useCallback(
|
||||
(e) => {
|
||||
if (onScrollStart) {
|
||||
onScrollStart(e);
|
||||
}
|
||||
|
||||
isScrolling.current = true;
|
||||
},
|
||||
[onScrollStart]
|
||||
);
|
||||
|
||||
const _onScrollStop = useCallback(
|
||||
(e) => {
|
||||
if (onScrollStop) {
|
||||
onScrollStop(e);
|
||||
}
|
||||
|
||||
isScrolling.current = false;
|
||||
|
||||
if (e.reachedEdgeInfo) {
|
||||
if (e.reachedEdgeInfo.top) {
|
||||
scrollPosition.current = "top";
|
||||
} else if (e.reachedEdgeInfo.bottom) {
|
||||
scrollPosition.current = "bottom";
|
||||
} else {
|
||||
scrollPosition.current = "middle";
|
||||
}
|
||||
} else {
|
||||
scrollPosition.current = "middle";
|
||||
}
|
||||
},
|
||||
[onScrollStop]
|
||||
);
|
||||
|
||||
return (
|
||||
<Scroller
|
||||
{...rest}
|
||||
onScrollStart={_onScrollStart}
|
||||
onScrollStop={_onScrollStop}
|
||||
id="TScroller"
|
||||
scrollMode={scrollMode || "translate"}
|
||||
focusableScrollbar={focusableScrollbar}
|
||||
className={classNames(
|
||||
className,
|
||||
isMounted && css.tScroller,
|
||||
onMoveScrollBarEffect ? css.onMove : ""
|
||||
)}
|
||||
direction={direction}
|
||||
horizontalScrollbar={horizontalScrollbar}
|
||||
verticalScrollbar={verticalScrollbar}
|
||||
overscrollEffectOn={{
|
||||
arrowKey: false,
|
||||
drag: false,
|
||||
pageKey: false,
|
||||
track: false,
|
||||
wheel: false,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Scroller>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
@import "../../style/CommonStyle.module.less";
|
||||
@import "../../style/utils.module.less";
|
||||
|
||||
@scrollBar: 0.625rem;
|
||||
@scrollCircle: 1.6667rem;
|
||||
@barColor: transparent;
|
||||
@focusedBarColor: #transparent;
|
||||
@verTrackColor: #f1efec;
|
||||
|
||||
.tScroller {
|
||||
> div:nth-child(2) > div:nth-child(1) {
|
||||
background-color: #fff;
|
||||
width: 8px;
|
||||
border-radius: 40px;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user