import * as React from 'react'; import { View } from 'react-native'; import type { IViewProps } from '@fluentui-react-native/adapters'; import { useThemeBoundary } from './context'; import { FlexThemeReference } from '../flex/flexThemeReference'; import { flexCoolTheme } from '../themes/flex/flexCoolTheme'; import { RootContext } from './rootContext'; import { createRootInputController, RootInputContext } from './rootInputController'; import { useRootInputProps } from './useRootInputProps'; import { ThemeProvider } from './ThemeProvider'; import type { ThemeProviderProps } from './ThemeProvider'; export interface ThemedRootProps extends IViewProps, Pick { /** * Inherits the nearest theme boundary when omitted, or uses the default Flex * theme when there is no boundary. An explicit theme starts a new appearance * configuration; input modality is still shared with the scene root. */ theme?: ThemeProviderProps['theme']; } const defaultTheme = new FlexThemeReference({ base: flexCoolTheme }); /** * A View that provides a theme and tracks input modality once per scene. */ export const ThemedRoot = React.forwardRef((props, ref) => { const { theme, appearance, appearanceSource, fallbackAppearance, children, ...viewProps } = props; const parentTheme = useThemeBoundary(); const parentController = React.useContext(RootInputContext); const [localController] = React.useState(createRootInputController); const controller = parentController ?? localController; const inheritedTheme = theme === undefined ? parentTheme : undefined; const resolvedFallback = React.useMemo( () => ({ ...inheritedTheme?.fallbackAppearance, ...fallbackAppearance }), [inheritedTheme?.fallbackAppearance, fallbackAppearance], ); const trackingProps = useRootInputProps(viewProps, controller, !parentController); return ( {children} ); }); ThemedRoot.displayName = 'ThemedRoot';