|
1 | 1 | import { createStyles, useStyles } from '@theme/styles';
|
2 | 2 | import { useAtomValue, useSetAtom } from 'jotai';
|
3 | 3 | import { useLayoutEffect, useRef } from 'react';
|
4 |
| -import { ViewProps } from 'react-native'; |
| 4 | +import { View, ViewProps } from 'react-native'; |
5 | 5 | import { PANES_MOUNTED } from './Panes';
|
6 |
| -import { BREAKPOINTS } from '@theme/styles'; |
7 |
| -import Animated, { FadeIn } from 'react-native-reanimated'; |
8 |
| - |
9 |
| -const MAX_PANES: Record<keyof typeof BREAKPOINTS, number> = { |
10 |
| - compact: 1, |
11 |
| - medium: 1, |
12 |
| - expanded: 2, |
13 |
| - large: 2, |
14 |
| - extraLarge: 3, |
15 |
| - // Injected by unistyles; never actually used |
16 |
| - landscape: 1, |
17 |
| - portrait: 1, |
18 |
| -}; |
| 6 | +import { useNavigationState, useRoute } from '@react-navigation/native'; |
19 | 7 |
|
20 | 8 | export type PaneProps = ViewProps & {
|
21 | 9 | padding?: boolean;
|
22 | 10 | } & ({ fixed: true; flex?: never } | { fixed?: never; flex: true });
|
23 | 11 |
|
24 | 12 | export function Pane({ padding = true, flex, fixed: _, ...props }: PaneProps) {
|
25 |
| - const { styles, breakpoint } = useStyles(stylesheet); |
26 |
| - const order = usePaneMounted(); |
27 |
| - const maxPanes = MAX_PANES[breakpoint]; |
28 |
| - const count = useAtomValue(PANES_MOUNTED); |
| 13 | + const { styles } = useStyles(stylesheet); |
| 14 | + // const order = usePaneMounted(); |
| 15 | + // const maxPanes = MAX_PANES[breakpoint]; |
| 16 | + // const count = useAtomValue(PANES_MOUNTED); |
| 17 | + |
| 18 | + // const withinWindow = (order.current ?? 0) < count - maxPanes; |
| 19 | + // const hidden = count > maxPanes && withinWindow; |
| 20 | + // if (count > maxPanes && withinWindow) |
| 21 | + // return <View style={{ width: 20, backgroundColor: 'red' }} />; |
| 22 | + |
| 23 | + const route = useRoute(); |
| 24 | + const isSelected = useNavigationState((state) => state.routes[state.index].key === route.key); |
29 | 25 |
|
30 |
| - const withinWindow = (order.current ?? 0) < count - maxPanes; |
31 |
| - if (count > maxPanes && withinWindow) return null; |
| 26 | + console.warn(route.name, { isSelected }); |
32 | 27 |
|
33 | 28 | // Flex a fixed pane when it is the only one visible
|
34 |
| - const fixed = !flex && count !== 1; |
| 29 | + const fixed = !flex && !isSelected; |
35 | 30 |
|
36 | 31 | return (
|
37 |
| - <Animated.View |
| 32 | + <View |
38 | 33 | {...props}
|
39 |
| - entering={FadeIn.duration(200)} |
40 | 34 | // exiting depends on how the pane was removed
|
41 | 35 | style={[styles.flex, fixed && styles.fixed, padding && styles.margins, props.style]}
|
42 | 36 | />
|
@@ -68,11 +62,9 @@ function usePaneMounted() {
|
68 | 62 | useLayoutEffect(() => {
|
69 | 63 | if (order.current === null) order.current = count;
|
70 | 64 |
|
71 |
| - setCount((count) => { |
72 |
| - return count + 1; |
73 |
| - }); |
| 65 | + setCount((count) => count + 1); |
74 | 66 |
|
75 |
| - return () => setCount((c) => c - 1); |
| 67 | + return () => setCount((count) => count - 1); |
76 | 68 | }, [count, setCount]);
|
77 | 69 |
|
78 | 70 | return order;
|
|
0 commit comments