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

feat(View): increase swipe back zone #5725

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/vkui/src/components/BaseGallery/BaseGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export const BaseGallery = ({
};

const onStart = (e: TouchEvent) => {
e.originalEvent.stopPropagation();
onDragStart?.(e);
setShiftState((prevState) => ({ ...prevState, animation: false }));
};
Expand Down
37 changes: 34 additions & 3 deletions packages/vkui/src/components/View/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ const [activePanel, setActivePanel] = useState('panel1');

**Блокировка свайпа (вариант #1)**

Компоненты, которые сами обрабатывают жесты (например, карта), могут конфликтовать со свайпбеком — повесьте на них свойство `data-vkui-swipe-back={false}`
Компоненты, которые сами обрабатывают жесты (например, карта или кастомный компонент по типу карусели), могут конфликтовать со свайпбеком. Вот как можно это решить:

- либо повесьте на них свойство `data-vkui-swipe-back={false}`;
- либо вызывайте `event.stopPropagation()` на событие `onStartX` компонента [Touch](#/Touch).

<br />

Expand Down Expand Up @@ -141,7 +144,9 @@ const MainPanelContent = ({ onProfileClick }) => {
<PanelHeader>Main</PanelHeader>
<Group>
<div style={{ height: 200 }} />
<CellButton onClick={onProfileClick}>Профиль</CellButton>
<CellButton stopPropagation={false} onClick={onProfileClick}>
Профиль
</CellButton>
<div style={{ height: 600 }} />
</Group>
</React.Fragment>
Expand All @@ -159,7 +164,33 @@ const ProfilePanelContent = ({ onSettingsClick }) => {
</Div>
</Group>
<Group>
<CellButton onClick={onSettingsClick}>Настройки</CellButton>
<CellButton stopPropagation={false} onClick={onSettingsClick}>
Настройки
</CellButton>
</Group>
<Group
header={<Header>Gallery</Header>}
description="Полностью блокирует свайпбэк (за счёт event.stopPropagation() на onStartX компонента Touch)"
>
<Gallery slideWidth="90%" bullets="dark">
<div style={{ backgroundColor: 'var(--vkui--color_background_negative)' }} />
<img src="https://placebear.com/1024/640" style={{ display: 'block' }} />
<div style={{ backgroundColor: 'var(--vkui--color_background_accent)' }} />
</Gallery>
</Group>
<Group
header={<Header>HorizontalScroll</Header>}
description="Свайпбэк срабатывает либо если мы тянем за левый край экрана, либо если позиция горизонтального скролла равна нулю"
>
<HorizontalScroll>
<div style={{ display: 'flex' }}>
{getRandomUsers(15).map((user) => (
<HorizontalCell key={user.id} size="s" header={user.first_name}>
<Avatar size={56} src={user.photo_100} />
</HorizontalCell>
))}
</div>
</HorizontalScroll>
</Group>
</React.Fragment>
);
Expand Down
38 changes: 36 additions & 2 deletions packages/vkui/src/components/View/View.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ import { Meta, StoryObj } from '@storybook/react';
import vkBridge from '@vkontakte/vk-bridge';
import { Platform } from '../../lib/platform';
import { CanvasFullLayout, DisableCartesianParam } from '../../storybook/constants';
import { getRandomUsers } from '../../testing/mock';
import { Alert } from '../Alert/Alert';
import { Avatar } from '../Avatar/Avatar';
import { CellButton } from '../CellButton/CellButton';
import { ConfigProviderOverride } from '../ConfigProvider/ConfigProviderOverride';
import { Div } from '../Div/Div';
import { FormItem } from '../FormItem/FormItem';
import { Gallery } from '../Gallery/Gallery';
import { Group } from '../Group/Group';
import { Header } from '../Header/Header';
import { HorizontalCell } from '../HorizontalCell/HorizontalCell';
import { HorizontalScroll } from '../HorizontalScroll/HorizontalScroll';
import { Input } from '../Input/Input';
import { Panel } from '../Panel/Panel';
import { PanelHeader } from '../PanelHeader/PanelHeader';
Expand All @@ -32,7 +38,9 @@ const MainPanelContent = ({ onProfileClick }: { onProfileClick: () => void }) =>
<React.Fragment>
<PanelHeader>Main</PanelHeader>
<Group>
<CellButton onClick={onProfileClick}>Профиль</CellButton>
<CellButton stopPropagation={false} onClick={onProfileClick}>
Профиль
</CellButton>
</Group>
</React.Fragment>
);
Expand All @@ -49,7 +57,33 @@ const ProfilePanelContent = ({ onSettingsClick }: { onSettingsClick: () => void
</Div>
</Group>
<Group>
<CellButton onClick={onSettingsClick}>Настройки</CellButton>
<CellButton stopPropagation={false} onClick={onSettingsClick}>
Настройки
</CellButton>
</Group>
<Group
header={<Header>Gallery</Header>}
description="Полностью блокирует свайпбэк (за счёт event.stopPropagation() на onStartX компонента Touch)"
>
<Gallery slideWidth="90%" bullets="dark">
<div style={{ backgroundColor: 'var(--vkui--color_background_negative)' }} />
<img src="https://placebear.com/1024/640" style={{ display: 'block' }} />
<div style={{ backgroundColor: 'var(--vkui--color_background_accent)' }} />
</Gallery>
</Group>
<Group
header={<Header>HorizontalScroll</Header>}
description="Свайпбэк срабатывает либо если мы тянем за левый край экрана, либо если позиция горизонтального скролла равна нулю"
>
<HorizontalScroll>
<div style={{ display: 'flex' }}>
{getRandomUsers(15).map((user) => (
<HorizontalCell key={user.id} size="s" header={user.first_name}>
<Avatar size={56} src={user.photo_100} />
</HorizontalCell>
))}
</div>
</HorizontalScroll>
</Group>
</React.Fragment>
);
Expand Down
Loading
Loading