-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new
extra
package docs to repo and update installation process …
…docs (#257) * move bottomSheet * add categories * Add new useCarousel doc * switch to related guidelines * Add Carousel docs * update carousel guideline links * update accessibilityActions type * improved wording * improved installation instructions * update to Arguments for hook * Add new useKeyboard doc
- Loading branch information
Showing
10 changed files
with
280 additions
and
5 deletions.
There are no files selected for viewing
File renamed without changes.
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,93 @@ | ||
import { Required } from '@site/src/components'; | ||
|
||
# Carousel | ||
|
||
AMA Provides an accessible Carousel component built on top | ||
of [React Native FlatList](https://reactnative.dev/docs/flatlist) | ||
using the [useCarousel](./../hooks/useCarousel.md) hook. | ||
|
||
## Example | ||
|
||
```tsx {2-15,22-23} | ||
import { Carousel } from '@react-native-ama/extras'; | ||
|
||
const Component = () => { | ||
const data = [ | ||
{ key: '1', image: image_1 }, | ||
{ key: '2', image: image_2 }, | ||
{ key: '3', image: image_3 }, | ||
]; | ||
const ref = React.useRef<FlatList<(typeof data)[number]>>(null); | ||
|
||
const renderItem: ListRenderItem<(typeof data)[number]> = ({ item }) => { | ||
return <Image source={item.image} resizeMode="cover" />; | ||
}; | ||
|
||
return ( | ||
<Carousel | ||
ref={ref} | ||
accessibilityLabel="Carousel of dog portraits" | ||
data={data} | ||
renderItem={renderItem} | ||
/> | ||
); | ||
}; | ||
``` | ||
|
||
## Accessibility | ||
|
||
- Provides / abstracts `accessibilityActions` array to Carousel with `increment` and `decrement` actions | ||
- Provides / abstracts `onAccessibilityAction` handler to Carousel to manage the `AccessibilityActionEvent` change and scroll to the new index in the FlatList | ||
- Provides / abstracts `accessibilityRole` to Carousel as `adjustable`/ `slider` | ||
|
||
## Props | ||
|
||
### <Required /> `ref` | ||
|
||
The carousel reference provides access to underlying `FlatList` methods and is required for accessibility actions to work on iOS. | ||
|
||
| Type | Default | | ||
| ------------------------------------ | --------- | | ||
| React.RefObject\<FlatList\<ItemT\>\> | undefined | | ||
|
||
### <Required /> `accessibilityLabel` | ||
|
||
The `accessibilityLabel` is required and should describe what the carousel displays, this is announced by the screen reader when the element gains focus, then it announces its role ('adjustable'). | ||
|
||
| Type | Default | | ||
| ------ | --------- | | ||
| string | undefined | | ||
|
||
### <Required /> `data` (Inherited from FlatList) | ||
|
||
An array (or array-like list) of items to render. Other data types can be used by targeting VirtualizedList directly. | ||
|
||
| Type | Default | | ||
| --------------------------------------- | --------- | | ||
| ArrayLike\<ItemT\> \| null \| undefined | undefined | | ||
|
||
### <Required /> `renderItem` (Inherited from FlatList) | ||
|
||
Takes an item from data and renders it into the list. Typical usage: | ||
|
||
```tsx | ||
const renderItem = ({item}) => ( | ||
<TouchableOpacity onPress={() => onPress(item)}> | ||
<Text>{item.title}</Text> | ||
</TouchableOpacity> | ||
); | ||
|
||
... | ||
|
||
<FlatList data={[{title: 'Title Text', key: 'item1'}]} renderItem={renderItem} /> | ||
``` | ||
|
||
Provides additional metadata like `index` if you need it. | ||
|
||
| Type | Default | | ||
| -------------------------------------------- | --------- | | ||
| ListRenderItem\<ItemT\> \| null \| undefined | undefined | | ||
|
||
## Related guidelines | ||
|
||
- [Carousel](/guidelines/carousel) |
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,5 @@ | ||
{ | ||
"label": "Components", | ||
"collapsible": true, | ||
"collapsed": false | ||
} |
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,5 @@ | ||
{ | ||
"label": "Hooks", | ||
"collapsible": true, | ||
"collapsed": false | ||
} |
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,49 @@ | ||
import { Required } from '@site/src/components' | ||
|
||
# useCarousel | ||
|
||
`useCarousel` is a hook that provides `a11yProps` for creating carousels from FlatLists or ScrollViews. | ||
|
||
:::info | ||
|
||
`a11yProps` here is an object that contains all the necessary accessibility props to make an accessible carousel, those being the role, actions and the onAction handler. See [Carousel guidelines](/guidelines/carousel) for more information. | ||
|
||
::: | ||
|
||
## Usage | ||
|
||
```tsx {2-4,8-10} | ||
import { useCarousel } from '@react-native-ama/extras'; | ||
|
||
const ExampleCarousel = props => { | ||
const ref = React.useRef<FlatList>(null); | ||
const a11yProps = useCarousel({ | ||
data: props.data, | ||
flatListRef: ref, | ||
}); | ||
|
||
return <FlatList ref={ref} {...props} {...a11yProps} />; | ||
}; | ||
``` | ||
|
||
## Arguments | ||
|
||
### <Required /> `data` | ||
|
||
The data passed to the Scrollable component, used to calculate the number of items in the carousel. | ||
|
||
| Type | Default | | ||
| ------------------------------------- | --------- | | ||
| ArrayLike\<any\> \| null \| undefined | undefined | | ||
|
||
### <Required /> `flatListRef` | ||
|
||
The ref passed to the FlatList or ScrollView, used to scroll to index's when accessibility actions are performed. | ||
|
||
| Type | Default | | ||
| ------------------------------------ | --------- | | ||
| React.Ref\<FlatList\<any\> \| null\> | undefined | | ||
|
||
## Related guidelines | ||
|
||
- [Carousel](/guidelines/carousel) |
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,104 @@ | ||
import { Required } from '@site/src/components' | ||
|
||
# useKeyboard | ||
|
||
`useKeyboard` is a hook that provides Reanimated shared values for the current and final heights of the keyboard, along with a boolean shared value indicating whether the keyboard is visible. These properties are `keyboardHeight`, `keyboardFinalHeight`, and `isKeyboardVisible` and can be utilized when building animations. | ||
|
||
:::info | ||
|
||
This hook is provided for convenience, however it is not necessary for accessibility or part of the official AMA guidelines. | ||
|
||
::: | ||
|
||
## Usage | ||
|
||
```tsx {2-5,12-24} | ||
import { useKeyboard } from '@react-native-ama/extras'; | ||
import Animated, { | ||
useAnimatedStyle, | ||
useDerivedValue, | ||
} from 'react-native-reanimated'; | ||
|
||
const Example = props => { | ||
const { keyboardHeight, keyboardFinalHeight, isKeyboardVisible } = | ||
useKeyboard(props.shouldHandleKeyboardEvents); | ||
|
||
// Do something with values | ||
const maxHeightValue = useDerivedValue(() => { | ||
return maxHeight - keyboardHeight.value; | ||
}, [keyboardHeight, maxHeight]); | ||
|
||
const animatedStyle = useAnimatedStyle(() => { | ||
const keyboard = keyboardHeight.value; | ||
|
||
return { | ||
transform: [{ translateY: translateY.value - keyboard }], | ||
maxHeight: maxHeightValue.value, | ||
}; | ||
}, [maxHeightValue, translateY, keyboardHeight]); | ||
|
||
return <Animated.View style={[animatedStyle]} />; | ||
}; | ||
``` | ||
|
||
## Arguments | ||
|
||
### `shouldHandleKeyboardEvents` _(optional)_ | ||
|
||
The data passed to the Scrollable component, used to calculate the number of items in the carousel. | ||
|
||
| Type | Default | | ||
| ------- | ------- | | ||
| boolean | true | | ||
|
||
## Returns | ||
|
||
### `keyboardHeight` | ||
|
||
A Reanimated shared value representing the current height of the keyboard. | ||
|
||
| Type | Initial | | ||
| --------------------- | ------- | | ||
| SharedValue\<number\> | 0 | | ||
|
||
> You can access data stored in the shared value with either its value property or get and set methods. | ||
### `keyboardFinalHeight` | ||
|
||
A Reanimated shared value representing the final height of the keyboard. When the keyboard is not visible, this value will be 0. | ||
|
||
| Type | Initial | | ||
| --------------------- | ------- | | ||
| SharedValue\<number\> | 0 | | ||
|
||
> You can access data stored in the shared value with either its value property or get and set methods. | ||
### `isKeyboardVisible` | ||
|
||
A Reanimated shared value representing whether the keyboard is visible. | ||
|
||
| Type | Initial | | ||
| ---------------------- | ------- | | ||
| SharedValue\<boolean\> | false | | ||
|
||
> You can access data stored in the shared value with either its value property or get and set methods. | ||
### Related | ||
|
||
:::note SharedValue type | ||
|
||
```ts | ||
interface SharedValue<Value = unknown> { | ||
value: Value; | ||
get(): Value; | ||
set(value: Value | ((value: Value) => Value)): void; | ||
addListener: (listenerID: number, listener: (value: Value) => void) => void; | ||
removeListener: (listenerID: number) => void; | ||
modify: ( | ||
modifier?: <T extends Value>(value: T) => T, | ||
forceUpdate?: boolean, | ||
) => void; | ||
} | ||
``` | ||
|
||
::: |
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