-
-
Notifications
You must be signed in to change notification settings - Fork 980
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add state flow charts to Gesture Handler's documentation. (#2817)
## Description Add a flow chart to visualise state changes of gesture components. ## Test plan Run docs locally, go to the `Gesture states & events` article. ### compatible with both Light and Dark modes https://github.com/software-mansion/react-native-gesture-handler/assets/74246391/6c4794ac-3f02-4990-9d42-e8602c6cb10a ### adaptive layout https://github.com/software-mansion/react-native-gesture-handler/assets/74246391/3294d39a-0357-41c4-867c-39b9c3d89781 --------- Co-authored-by: Kacper Kapuściak <[email protected]> Co-authored-by: Patrycja Kalińska <[email protected]>
- Loading branch information
1 parent
d2a464a
commit 7340a7f
Showing
28 changed files
with
1,338 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { useEffect, useState } 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] = useState(false); | ||
|
||
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; |
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,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); | ||
} | ||
} |
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,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; |
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,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); | ||
} |
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,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; | ||
lineBounds: number[]; | ||
} | ||
|
||
export default function CollapsibleCode({ src, lineBounds }: Props) { | ||
const [collapsed, setCollapsed] = useState(true); | ||
|
||
if (!lineBounds) { | ||
return <CodeBlock language="jsx">{src}</CodeBlock>; | ||
} | ||
|
||
const [start, end] = lineBounds; | ||
|
||
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> | ||
); | ||
} |
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,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; | ||
} |
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
27 changes: 27 additions & 0 deletions
27
docs/src/components/InteractiveExample/InteractiveExampleComponent/index.tsx
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,27 @@ | ||
import React from 'react'; | ||
|
||
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> | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
docs/src/components/InteractiveExample/InteractiveExampleComponent/styles.module.css
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,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; | ||
} |
Oops, something went wrong.