Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/components/Portal/Portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Provider as SettingsProvider,
} from '../../core/settings';
import { ThemeProvider, useInternalTheme } from '../../core/theming';
import { ReduceMotionContext } from '../../theme/accessibility/ReduceMotionContext';
import type { ThemeProp } from '../../theme/types';

export type Props = {
Expand Down Expand Up @@ -46,13 +47,16 @@ const Portal = ({ children, theme: themeOverrides }: Props) => {
const { direction } = useLocale();
const settings = React.useContext(SettingsContext);
const manager = React.useContext(PortalContext);
const reduceMotion = React.useContext(ReduceMotionContext);

return (
<PortalConsumer manager={manager}>
<SettingsProvider value={settings}>
<LocaleProvider direction={direction}>
<ThemeProvider theme={theme}>{children}</ThemeProvider>
</LocaleProvider>
<ReduceMotionContext.Provider value={reduceMotion}>
<LocaleProvider direction={direction}>
<ThemeProvider theme={theme}>{children}</ThemeProvider>
</LocaleProvider>
</ReduceMotionContext.Provider>
</SettingsProvider>
</PortalConsumer>
);
Expand Down
4 changes: 3 additions & 1 deletion src/components/Portal/PortalHost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export default class PortalHost extends React.Component<Props> {
} else {
const op: Operation = { type: 'mount', key, children };
const index = this.queue.findIndex(
(o) => o.type === 'mount' || (o.type === 'update' && o.key === key)
(o) =>
(o.type === 'mount' && o.key === key) ||
(o.type === 'update' && o.key === key)
);

if (index > -1) {
Expand Down
18 changes: 18 additions & 0 deletions src/components/__tests__/Portal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { Text } from 'react-native';
import { expect, it, jest } from '@jest/globals';

import { LocaleProvider, useLocale } from '../../core/locale';
import PaperProvider from '../../core/PaperProvider';
import { useInternalTheme } from '../../core/theming';
import { render, screen } from '../../test-utils';
import { useReduceMotion } from '../../theme/accessibility/ReduceMotionContext';
import Dialog from '../Dialog/Dialog';
import Modal from '../Modal';
import Portal from '../Portal/Portal';
Expand Down Expand Up @@ -60,6 +62,22 @@ it('passes local theme overrides and locale to portal content and updates them',
expect(screen.queryByText('2 rtl')).not.toBeOnTheScreen();
});

const PortalReduceMotionContent = () => (
<Text>{`reduce motion: ${useReduceMotion()}`}</Text>
);

it('passes the reduce motion preference to portal content', async () => {
await render(
<PaperProvider reduceMotion="on">
<Portal>
<PortalReduceMotionContent />
</Portal>
</PaperProvider>
);

expect(await screen.findByText('reduce motion: true')).toBeOnTheScreen();
});

it('renders portals in source order when mounted in the same commit', async () => {
await render(
<Portal.Host>
Expand Down
Loading