Hooks and types
The hooks for your own parts, the zoom and swipe options, labels, and the types around them.
Everything here is exported from @react-brackets/native. The data types, like Stage, Match and Participant, come from the core and are the same as on the web: see Data model.
usePagination()
Paging for your own round tabs, dots or buttons. Works anywhere inside Bracket.Root. position is a Reanimated shared value that moves under the finger during a swipe, so an indicator built from it in useAnimatedStyle moves on the UI thread. See Navigation and zoom.
const { paged, rounds, page, setPage, previous, next, canPrevious, canNext, position } =
usePagination();paged is true while the bracket shows one round at a time, and false while it shows the whole tree, so controls placed outside the viewport can hide themselves on a wide screen:
function RoundDots() {
const { paged, rounds, page, setPage } = usePagination();
if (!paged) return null;
return rounds.map((round, index) => (
<Pressable key={round.id} onPress={() => setPage(index)}>
<Text>{index === page ? '●' : '○'}</Text>
</Pressable>
));
}Prop
Type
useZoom()
Pan and zoom for your own zoom buttons, anywhere inside Bracket.Root. Returns null while the tree isn't panned and zoomed: in the paged view, or in scroll and fit modes.
const zoom = useZoom();
if (!zoom) return null;
zoom.zoomTo(zoom.maxScale);Prop
Type
useConnector()
The line being drawn, inside renderConnector: its matches, whether it is highlighted, and points, a shared value with where it starts and ends. Use it in a component of your own that draws the line from scratch. See Connector lines.
function Straight() {
const { points } = useConnector();
const line = useAnimatedStyle(() => {
const { start, end, opacity } = points.value;
// A view one point long, stretched with a transform, moves in the same frame as the cards.
return {
opacity,
transform: [
{ translateX: start.x },
{ translateY: start.y },
{ rotate: `${Math.atan2(end.y - start.y, end.x - start.x)}rad` },
{ scaleX: Math.hypot(end.x - start.x, end.y - start.y) },
],
};
});
return (
<Animated.View
style={[
{ position: 'absolute', width: 1, height: 2, backgroundColor: '#a1a1aa' },
{ transformOrigin: 'left center' },
line,
]}
/>
);
}connectorPath(start, end, radius) returns the bracket's own elbow as SVG path data. It runs on the UI thread too, so it works in useAnimatedProps.
Prop
Type
Prop
Type
useBracket()
The bracket's context: the stage, the group, the theme, the labels and the highlight. Use it in your own components inside a card, a round title or anything else inside the bracket.
Prop
Type
useMatch()
The match being drawn, inside renderMatch. Useful in a component of your own deep inside a card, without passing the match down.
function Venue() {
const match = useMatch();
return <Text>{venues[match.id]}</Text>;
}useBracketTheme()
The theme a bracket would use here: the nearest BracketThemeProvider, or the light or dark theme from the system's appearance, with any overrides you pass applied on top. Use it to match your own views to the bracket.
const theme = useBracketTheme();
<View style={{ backgroundColor: theme.colors.surface, borderRadius: theme.radius }} />;ZoomOptions
The zoom option on <Bracket> and Bracket.Root: how pan and zoom behaves in pan-zoom mode. How it feels shows each one in use.
Prop
Type
SwipeOptions
The swipe option: how a swipe pages in the paged view.
Prop
Type
Labels
Every built-in string, for translation and screen readers. Pass any of them to labels. See Right to left.
Prop
Type
Other types
| Type | What it is |
|---|---|
StyleOf<State, Style> | A style, or a function of a part's state that returns one. Every part's style takes it. |
ThemeOverrides | Any values of BracketTheme, with any of its colors. What theme and createTheme take. |
TreeMode | 'scroll' | 'fit' | 'pan-zoom': how the whole tree fits its width. |
BracketLayout | 'standard' | 'mirrored': one tree, or two halves that meet at the final. |
PageHeight | 'contain' | 'follow': how the paged view's height moves between rounds. |
Transform | { scale, x, y }: a zoom and a position, as zoom.initial takes. |