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

Add state flow charts to Gesture Handler's documentation. #2817

Merged
merged 52 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
87d9d73
added basic sandbox environment to GH docs
latekvo Mar 20, 2024
ce70c6d
use composed tap + pan component for flow chart
latekvo Mar 20, 2024
23c0859
first working version
latekvo Mar 22, 2024
e5004df
add distinction for cancelled and failed, added arrow library
latekvo Mar 22, 2024
5847b2e
added connections system, fixed references in docs
latekvo Mar 22, 2024
853730b
fix arrow
latekvo Mar 22, 2024
0cc3ab1
add layout modification
latekvo Mar 22, 2024
a943adf
added vertical layout option
latekvo Mar 22, 2024
67889c9
Add arrow heads, fixed console errors
latekvo Mar 22, 2024
72b4b5a
moved connections and flow logic into a separate library
latekvo Mar 26, 2024
252643d
removed hardcoded id gets, added headers, added tap to the layout
latekvo Mar 26, 2024
b5d4111
cleanup
latekvo Mar 26, 2024
7d29554
fix undetermined state & cleanup
latekvo Mar 26, 2024
cea1b97
fix crash
latekvo Mar 26, 2024
2a49d72
replaced tap with longpress
latekvo Mar 26, 2024
988f30a
Merge branch 'main' into @latekvo/docs_add_state_chart
latekvo Mar 26, 2024
78a239c
remove hard-coded colors, add transitions to colors, cleanup
latekvo Mar 27, 2024
db10c65
Merge branch '@latekvo/docs_add_state_chart' of https://github.com/so…
latekvo Mar 27, 2024
33dcefa
added a layout for mobile devices
latekvo Mar 27, 2024
1707e88
fix broken svg line antialiasing
latekvo Mar 27, 2024
d289eec
fix antialiasing issues
latekvo Mar 27, 2024
4e9398e
fix console errors and reactive styling
latekvo Mar 27, 2024
476f11a
apply review suggestions
latekvo Mar 27, 2024
f1b6921
cleanup
latekvo Mar 28, 2024
fbe7bfd
cleanup
latekvo Mar 28, 2024
6748252
Merge branch 'main' into @latekvo/docs_add_state_chart
latekvo Mar 28, 2024
7267383
UI overhaul
latekvo Mar 28, 2024
3b034ba
Merge branch '@latekvo/docs_add_state_chart' of https://github.com/so…
latekvo Mar 28, 2024
8041151
remove borders from active elements
latekvo Mar 28, 2024
0541488
adjust arrows colors and add custom easing
latekvo Mar 28, 2024
07f69b1
simplify code
latekvo Mar 29, 2024
0918145
Merge current main
kacperkapusciak Apr 4, 2024
3e876ec
Remove redundant comment
kacperkapusciak Apr 4, 2024
78d8532
Simplify some code
kacperkapusciak Apr 4, 2024
6a24f07
Change spring config in example
kacperkapusciak Apr 4, 2024
fc7f281
Hide src buttons when src not provided
kacperkapusciak Apr 4, 2024
d3c0115
Simplify
kacperkapusciak Apr 4, 2024
66e60b2
Remove redundant code
kacperkapusciak Apr 4, 2024
93eab57
Adjust styles
kacperkapusciak Apr 4, 2024
3ed330f
Rename element -> item
kacperkapusciak Apr 4, 2024
d30ade2
Merge current main
kacperkapusciak Apr 5, 2024
7b3dbfe
Rename stuff & cleanup
kacperkapusciak Apr 5, 2024
6211b0c
Bring back some mysterious code to fix a bug
kacperkapusciak Apr 5, 2024
d5649d4
a man's gotta do what a man's gotta do
kacperkapusciak Apr 5, 2024
78e4f2c
Remove a mistake copy-paste
kacperkapusciak Apr 5, 2024
0bcc7c6
Apply suggestions from code review
kacperkapusciak Apr 5, 2024
4fe0baa
Apply suggestions from code review
kacperkapusciak Apr 5, 2024
93eb9bb
Merge branch '@latekvo/docs_add_state_chart' of github.com:software-m…
kacperkapusciak Apr 5, 2024
413bb34
Rename landing example component
kacperkapusciak Apr 5, 2024
c110627
Rename showLines -> lineBounds in CollapsibleCode comp
kacperkapusciak Apr 5, 2024
b81ed47
Remove unused import
kacperkapusciak Apr 5, 2024
357ab4b
Code reformat
kacperkapusciak Apr 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,17 @@ A gesture can be in one of the six possible states:

## State flows

The most typical flow of state is when a gesture picks up on an initial touch event, then recognizes it, then acknowledges its ending and resets itself back to the initial state.

The flow looks as follows (longer arrows represent that there are possibly more touch events received before the state changes):

[`UNDETERMINED`](#undetermined) -> [`BEGAN`](#began) ------> [`ACTIVE`](#active) ------> [`END`](#end) -> [`UNDETERMINED`](#undetermined)
import ComposedGesture from '@site/src/examples/ComposedGesture';

Another possible flow is when a handler receives touches that cause a recognition failure:

[`UNDETERMINED`](#undetermined) -> [`BEGAN`](#began) ------> [`FAILED`](#failed) -> [`UNDETERMINED`](#undetermined)
The most typical flow of state is when a gesture picks up on an initial touch event, then recognizes it, then acknowledges its ending and resets itself back to the initial state.

At last, when a handler does properly recognize the gesture but then is interrupted by the touch system the gesture recognition is canceled and the flow looks as follows:
The flow looks as follows:

[`UNDETERMINED`](#undetermined) -> [`BEGAN`](#began) ------> [`ACTIVE`](#active) ------> [`CANCELLED`](#cancelled) -> [`UNDETERMINED`](#undetermined)
<InteractiveExample
component={<ComposedGesture />}
label="Drag or long-press the circle"
larger={true}
/>

## Events

Expand Down
6 changes: 3 additions & 3 deletions docs/docs/gestures/state-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sidebar_position: 15

### `begin()`

Transition the gesture to the [`BEGAN`](/docs/fundamentals/states-events.md#began) state. This method will have no effect if the gesture has already activated or finished.
Transition the gesture to the [`BEGAN`](/docs/fundamentals/states-events#began) state. This method will have no effect if the gesture has already activated or finished.

### `activate()`

Expand All @@ -20,8 +20,8 @@ If the gesture is [`exclusive`](/docs/fundamentals/gesture-composition) with ano

### `end()`

Transition the gesture to the [`END`](/docs/fundamentals/states-events.md#end) state. This method will have no effect if the handler has already finished.
Transition the gesture to the [`END`](/docs/fundamentals/states-events#end) state. This method will have no effect if the handler has already finished.

### `fail()`

Transition the gesture to the [`FAILED`](/docs/fundamentals/states-events.md#failed) state. This method will have no effect if the handler has already finished.
Transition the gesture to the [`FAILED`](/docs/fundamentals/states-events#failed) state. This method will have no effect if the handler has already finished.
40 changes: 40 additions & 0 deletions docs/src/components/AnimableIcon/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { useEffect } from 'react';
import styles from './styles.module.css';
import clsx from 'clsx';
import { useColorMode } from '@docusaurus/theme-common';

export const Animation = {
FADE_IN_OUT: styles.iconClicked,
};

interface Props {
icon: JSX.Element;
iconDark?: JSX.Element;
animation: string;
onClick: (actionPerformed, setActionPerformed) => void;
}

const AnimableIcon = ({
icon,
iconDark,
animation = Animation.FADE_IN_OUT,
onClick,
}: Props): JSX.Element => {
const { colorMode } = useColorMode();
const [actionPerformed, setActionPerformed] = React.useState(false);
kacperkapusciak marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
const timeout = setTimeout(() => setActionPerformed(false), 1000);
return () => clearTimeout(timeout);
}, [actionPerformed]);

return (
<div
onClick={() => onClick(actionPerformed, setActionPerformed)}
className={clsx(styles.actionIcon, actionPerformed && animation)}>
{colorMode === 'light' ? icon : iconDark || icon}
</div>
);
};

export default AnimableIcon;
27 changes: 27 additions & 0 deletions docs/src/components/AnimableIcon/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.actionIcon {
display: flex;
align-items: center;
justify-content: center;

padding: 0.25em;
cursor: pointer;

border: 1px solid transparent;
border-radius: 3px;
}

.iconClicked {
animation: 1s iconClick;
}

@keyframes iconClick {
0% {
border: 1px solid var(--swm-interactive-copy-button-off);
}
50% {
border: 1px solid var(--swm-interactive-copy-button-on);
}
100% {
border: 1px solid var(--swm-interactive-copy-button-off);
}
}
33 changes: 33 additions & 0 deletions docs/src/components/CollapseButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import styles from './styles.module.css';
import Arrow from '@site/static/img/Arrow.svg';
import ArrowDark from '@site/static/img/Arrow-dark.svg';
import { useColorMode } from '@docusaurus/theme-common';
import clsx from 'clsx';

const CollapseButton: React.FC<{
label: string;
labelCollapsed: string;
collapsed: boolean;
onCollapse: () => void;
className?: string;
}> = ({ label, labelCollapsed, collapsed, onCollapse, className }) => {
const { colorMode } = useColorMode();

return (
<div
className={clsx(styles.collapseButton, className)}
data-collapsed={collapsed}
onClick={() => onCollapse()}>
{colorMode === 'light' ? (
<Arrow className={styles.arrow} />
) : (
<ArrowDark className={styles.arrow} />
)}

<button>{collapsed ? labelCollapsed : label}</button>
</div>
);
};

export default CollapseButton;
29 changes: 29 additions & 0 deletions docs/src/components/CollapseButton/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.collapseButton {
display: flex;
align-items: center;
cursor: pointer;
}

.collapseButton button {
background-color: transparent;
border: none;
padding: 0;

font-family: var(--swm-body-font);
font-size: 16px;
color: var(--ifm-font-color-base);
cursor: pointer;
}

.arrow {
height: 12px;
width: 12px;
margin-right: 1rem;
margin-top: 2px;

transition: var(--swm-expandable-transition);
}

.collapseButton[data-collapsed='false'] .arrow {
transform: rotate(180deg);
}
36 changes: 36 additions & 0 deletions docs/src/components/CollapsibleCode/index.tsx
kacperkapusciak marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { useState } from 'react';
import CodeBlock from '@theme/CodeBlock';
import styles from './styles.module.css';

import CollapseButton from '@site/src/components/CollapseButton';

interface Props {
src: string;
showLines: number[];
kacperkapusciak marked this conversation as resolved.
Show resolved Hide resolved
}

export default function CollapsibleCode({ src, showLines }: Props) {
const [collapsed, setCollapsed] = useState(true);

if (!showLines) {
return <CodeBlock language="jsx">{src}</CodeBlock>;
}

const [start, end] = showLines;

const codeLines = src.split('\n');
const linesToShow = codeLines.slice(start, end + 1).join('\n');

return (
<div className={styles.container}>
<CollapseButton
label="Collapse the full code"
labelCollapsed="Expand the full code"
collapsed={collapsed}
onCollapse={() => setCollapsed(!collapsed)}
className={styles.collapseButton}
/>
<CodeBlock language="jsx">{collapsed ? linesToShow : src}</CodeBlock>
</div>
);
}
15 changes: 15 additions & 0 deletions docs/src/components/CollapsibleCode/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.container {
background-color: var(--swm-off-background);
border-radius: 0;
border: 1px solid var(--swm-border);
margin-bottom: 1em;
}

.container pre,
.container code {
border: none;
}

.collapseButton {
padding: 1em 0 0 1em;
}
kacperkapusciak marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import clsx from 'clsx';
kacperkapusciak marked this conversation as resolved.
Show resolved Hide resolved

import BrowserOnly from '@docusaurus/BrowserOnly';
import styles from './styles.module.css';

interface Props {
component: React.ReactNode;
label?: string;
idx?: number;
}

export default function InteractiveExampleComponent({
component,
label,
idx,
}: Props) {
return (
<BrowserOnly fallback={<div>Loading...</div>}>
{() => (
<div className={styles.container}>
<React.Fragment key={idx}>{component}</React.Fragment>
{label && <div className={styles.label}>{label}</div>}
</div>
)}
</BrowserOnly>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.container {
display: flex;
flex-direction: column;
height: 100%;
justify-content: center;
contain: content;
align-items: center;
background-color: none;
margin-bottom: var(--ifm-leading);
}

.label {
text-align: center;
font-size: 1rem;
}
Loading
Loading