Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

1.8 KB
Raw Blame
import { Stack } from 'expo-router';
import { useMemo } from 'react';
import { Platform } from 'react-native';
import { useAdaptiveWindow } from '../AdaptiveWindowContext';
import { useTheme } from '@/theme';

export function useSystemNavigationBack() {
  const window = useAdaptiveWindow();
  return Platform.OS === 'ios' && window.barEdge !== 'none';
}

/** Keep real toolbar items: Toolbar.View custom content loses Duo's vertical
 * adaptation and returns to the horizontal header, overlapping the sidebar. */
export function SystemNavigationBack({ onPress, label, disabled = false, close = false, available = true, newTask }: {
  newTask?: { onPress(): void; label: string };
  onPress(): void; label: string; disabled?: boolean; close?: boolean; available?: boolean;
}) {
  const enabled = useSystemNavigationBack();
  const { colors } = useTheme();
  // expo-router applies screen options in a layout effect. Keep this object
  // stable across unrelated store updates, otherwise setOptions can feed a
  // rerender back into this route indefinitely.
  const screenOptions = useMemo(() => ({
    headerShown: enabled && available,
    headerTransparent: true,
    headerShadowVisible: false,
    headerBackVisible: false,
    headerTitle: '',
    headerTintColor: colors.textPrimary,
  }), [available, colors.textPrimary, enabled]);
  return <>
    <Stack.Screen options={screenOptions} />
    {enabled && available ? <Stack.Toolbar placement="left">
      <Stack.Toolbar.Button icon={close ? 'xmark' : 'chevron.backward'}
        accessibilityLabel={label} disabled={disabled} onPress={onPress} />
    </Stack.Toolbar> : null}
    {enabled && available && newTask ? <Stack.Toolbar placement="right">
      <Stack.Toolbar.Button icon="square.and.pencil" accessibilityLabel={newTask.label} onPress={newTask.onPress} />
    </Stack.Toolbar> : null}
  </>;
}