suna/apps/mobile/components/PanelContainer.tsx

124 lines
3.6 KiB
TypeScript
Raw Permalink Normal View History

2025-06-24 05:15:02 +08:00
import { Message } from '@/api/chat-api';
2025-06-17 04:21:36 +08:00
import { useThemedStyles } from '@/hooks/useThemeColor';
2025-07-11 06:27:59 +08:00
import { useSelectedProject } from '@/stores/ui-store';
2025-06-17 04:21:36 +08:00
import React, { useRef } from 'react';
import { Dimensions, View } from 'react-native';
import { DrawerLayout } from 'react-native-gesture-handler';
import { LeftPanel } from './LeftPanel';
import { RightPanel } from './RightPanel';
const { width: SCREEN_WIDTH } = Dimensions.get('window');
interface PanelContainerProps {
leftPanelVisible: boolean;
rightPanelVisible: boolean;
onCloseLeft: () => void;
onCloseRight: () => void;
onOpenLeft: () => void;
children: React.ReactNode;
2025-06-24 05:15:02 +08:00
messages?: Message[];
2025-06-17 04:21:36 +08:00
}
export const PanelContainer: React.FC<PanelContainerProps> = ({
leftPanelVisible,
rightPanelVisible,
onCloseLeft,
onCloseRight,
onOpenLeft,
children,
2025-06-24 05:15:02 +08:00
messages = [],
2025-06-17 04:21:36 +08:00
}) => {
const leftDrawerRef = useRef<DrawerLayout>(null);
const rightDrawerRef = useRef<DrawerLayout>(null);
2025-07-11 06:27:59 +08:00
const selectedProject = useSelectedProject();
2025-06-17 04:21:36 +08:00
const styles = useThemedStyles((theme) => ({
container: {
flex: 1,
backgroundColor: theme.background,
},
mainContent: {
flex: 1,
},
}));
// Handle drawer state changes
React.useEffect(() => {
if (leftPanelVisible) {
leftDrawerRef.current?.openDrawer();
} else {
leftDrawerRef.current?.closeDrawer();
}
}, [leftPanelVisible]);
React.useEffect(() => {
if (rightPanelVisible) {
rightDrawerRef.current?.openDrawer();
} else {
rightDrawerRef.current?.closeDrawer();
}
}, [rightPanelVisible]);
const leftDrawerContent = (
2025-06-24 05:15:02 +08:00
<LeftPanel isVisible={true} onClose={() => {
leftDrawerRef.current?.closeDrawer();
onCloseLeft();
}} />
2025-06-17 04:21:36 +08:00
);
const rightDrawerContent = (
2025-07-11 06:27:59 +08:00
<RightPanel
isVisible={true}
onClose={onCloseRight}
messages={messages}
sandboxId={selectedProject?.sandbox?.id}
/>
2025-06-17 04:21:36 +08:00
);
const mainContent = (
<View style={styles.mainContent}>
{children}
</View>
);
return (
<View style={styles.container}>
<DrawerLayout
ref={leftDrawerRef}
2025-06-20 06:43:45 +08:00
drawerWidth={300}
2025-06-17 04:21:36 +08:00
drawerPosition="left"
drawerType="slide"
drawerBackgroundColor="transparent"
2025-06-20 06:43:45 +08:00
edgeWidth={75}
2025-06-17 04:21:36 +08:00
renderNavigationView={() => leftDrawerContent}
onDrawerSlide={(position) => {
// Tiny overlay effect on main content
if (position > 0 && !leftPanelVisible) {
onOpenLeft();
}
}}
onDrawerClose={() => {
if (leftPanelVisible) {
onCloseLeft();
}
}}
>
<DrawerLayout
ref={rightDrawerRef}
drawerWidth={SCREEN_WIDTH}
drawerPosition="right"
drawerType="slide"
drawerBackgroundColor="transparent"
renderNavigationView={() => rightDrawerContent}
onDrawerClose={() => {
if (rightPanelVisible) {
onCloseRight();
}
}}
>
{mainContent}
</DrawerLayout>
</DrawerLayout>
</View>
);
};