1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

fixed slide block transitions

This commit is contained in:
Fedor Katurov 2019-11-07 15:43:39 +07:00
parent d06593b4cb
commit f837924ad4
3 changed files with 56 additions and 47 deletions

View file

@ -76,7 +76,13 @@ const NodeImageSlideBlock: FC<IProps> = ({ node, is_loading, updateLayout }) =>
if (!wrap || !wrap.current) return; if (!wrap || !wrap.current) return;
const { width } = wrap.current.getBoundingClientRect(); const { width } = wrap.current.getBoundingClientRect();
const selected = Math.abs(-offset / width); const selected = Math.abs(-offset / width);
if (is_loading) {
return setHeight((width * 9) / 16);
}
const prev = Math.max(heights[Math.floor(selected)] || 320, 320); const prev = Math.max(heights[Math.floor(selected)] || 320, 320);
const next = Math.max(heights[Math.ceil(selected)] || 320, 320); const next = Math.max(heights[Math.ceil(selected)] || 320, 320);
const now = prev - (prev - next) * (selected % 1); const now = prev - (prev - next) * (selected % 1);
@ -84,7 +90,7 @@ const NodeImageSlideBlock: FC<IProps> = ({ node, is_loading, updateLayout }) =>
if (current !== Math.round(selected)) setCurrent(Math.round(selected)); if (current !== Math.round(selected)) setCurrent(Math.round(selected));
setHeight(now); setHeight(now);
}, [offset, heights, max_height, images]); }, [wrap, offset, heights, max_height, images, is_loading]);
const onDrag = useCallback( const onDrag = useCallback(
event => { event => {
@ -107,6 +113,8 @@ const NodeImageSlideBlock: FC<IProps> = ({ node, is_loading, updateLayout }) =>
); );
const normalizeOffset = useCallback(() => { const normalizeOffset = useCallback(() => {
if (!slide.current || !wrap.current) return;
const { width: wrap_width } = wrap.current.getBoundingClientRect(); const { width: wrap_width } = wrap.current.getBoundingClientRect();
const { width: slide_width } = slide.current.getBoundingClientRect(); const { width: slide_width } = slide.current.getBoundingClientRect();
@ -175,18 +183,16 @@ const NodeImageSlideBlock: FC<IProps> = ({ node, is_loading, updateLayout }) =>
[wrap] [wrap]
); );
if (is_loading) {
return ( return (
<div className={classNames(styles.wrap, { is_loading })} ref={wrap}>
{is_loading && (
<div className={styles.placeholder}> <div className={styles.placeholder}>
<div> <div>
<LoaderCircle size={96} /> <LoaderCircle size={96} />
</div> </div>
</div> </div>
); )}
}
return (
<div className={classNames(styles.wrap, { is_loading })} ref={wrap}>
<ImageSwitcher <ImageSwitcher
total={images.length} total={images.length}
current={current} current={current}
@ -197,7 +203,6 @@ const NodeImageSlideBlock: FC<IProps> = ({ node, is_loading, updateLayout }) =>
<div <div
className={styles.image_container} className={styles.image_container}
style={{ style={{
transition: is_dragging ? 'none' : 'transform 500ms',
height, height,
transform: `translate(${offset}px, 0)`, transform: `translate(${offset}px, 0)`,
width: `${images.length * 100}%`, width: `${images.length * 100}%`,
@ -206,7 +211,8 @@ const NodeImageSlideBlock: FC<IProps> = ({ node, is_loading, updateLayout }) =>
onTouchStart={startDragging} onTouchStart={startDragging}
ref={slide} ref={slide}
> >
{images.map((file, index) => ( {!is_loading &&
images.map((file, index) => (
<div <div
className={classNames(styles.image_wrap, { className={classNames(styles.image_wrap, {
is_active: index === current && loaded[index], is_active: index === current && loaded[index],

View file

@ -17,6 +17,11 @@
overflow: hidden; overflow: hidden;
user-select: none; user-select: none;
will-change: transform, height; will-change: transform, height;
transition: height 500ms, transform 500ms;
&:active {
transition: none;
}
.image { .image {
max-height: 960px; max-height: 960px;
@ -44,10 +49,6 @@
} }
.placeholder { .placeholder {
padding-bottom: 66%;
position: relative;
& > div {
position: absolute; position: absolute;
width: 100%; width: 100%;
height: 100%; height: 100%;
@ -56,10 +57,10 @@
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
opacity: 0.025; background: $content_bg;
} z-index: 1;
svg { svg {
opacity: 0.025;
fill: white; fill: white;
} }
} }

View file

@ -107,15 +107,17 @@ function* onNodeLoad({ id }: ReturnType<typeof nodeLoadNode>) {
data: { node, error }, data: { node, error },
} = yield call(reqWrapper, getNode, { id }); } = yield call(reqWrapper, getNode, { id });
yield put(nodeSetLoading(false));
if (error) { if (error) {
return yield put(nodeSetSaveErrors({ error })); yield put(nodeSetSaveErrors({ error }));
yield put(nodeSetLoading(false));
return;
} }
yield put(nodeSetSaveErrors({})); yield put(nodeSetSaveErrors({}));
yield put(nodeSetCurrent(node)); yield put(nodeSetCurrent(node));
yield put(nodeSetLoading(false));
const { const {
comments: { comments: {
data: { comments }, data: { comments },