Skip to content

[ BUG ] Portal issue on iOS, RN without expo #405

@ndrkltsk

Description

@ndrkltsk

Describe the bug
It seems to be portal related, I currently working with AlertDialog but every component that requires PortalHost has the same issue.
React Native without expo.
Working on iOS, didn't tried Android yet.
While pressing the trigger, the state actually changes, open property goes from false to true, but nothing happens on screen.
I've tested directly using Portal and it seems to work as aspected.

I have <PortalHost/> as last child in my main app.tsx file.

function App() {
  return (
    <>
      <GestureHandlerRootView>
        <SafeAreaProvider>
          <LocalizationProvider>
            <NetworkStatusProvider>
              <QueryProvider>
                <AuthProvider>
                  <ClarityProvider>
                    <NavigationProvider />
                  </ClarityProvider>
                </AuthProvider>
              </QueryProvider>
            </NetworkStatusProvider>
          </LocalizationProvider>
        </SafeAreaProvider>
      </GestureHandlerRootView>
      <PortalHost />
    </>
  );
}

Testing screen with AlertDialog and direct portal test

import React, {useState} from 'react';
import {SafeAreaView, View} from 'react-native';
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from '~/components/ui/alert-dialog';
import {Button} from '~/components/ui/button';
import {Portal} from '@rn-primitives/portal';

import {Text} from '~/components/ui/text/text.component';

export default function TestScreen() {
  const [showPortalTest, setShowPortalTest] = useState(false);

  // Test portal directly
  const togglePortalTest = () => {
    setShowPortalTest(!showPortalTest);
  };

  return (
    <SafeAreaView
      style={{
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        gap: 20,
      }}>
      <AlertDialog>
        <AlertDialogTrigger asChild>
          <Button variant="outline">
            <Text>Show Alert Dialog</Text>
          </Button>
        </AlertDialogTrigger>
        <AlertDialogContent>
          <AlertDialogHeader>
            <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
            <AlertDialogDescription>
              This action cannot be undone. This will permanently delete your
              account and remove your data from our servers.
            </AlertDialogDescription>
          </AlertDialogHeader>
          <AlertDialogFooter>
            <AlertDialogCancel>
              <Text>Cancel</Text>
            </AlertDialogCancel>
            <AlertDialogAction>
              <Text>Continue</Text>
            </AlertDialogAction>
          </AlertDialogFooter>
        </AlertDialogContent>
      </AlertDialog>

      {/* Direct portal test */}
      <Button onPress={togglePortalTest}>
        <Text>Toggle Direct Portal Test</Text>
      </Button>

      {/* Direct portal test */}
      {showPortalTest && (
        <Portal name="test-portal">
          <View
            style={{
              position: 'absolute',
              top: 0,
              left: 0,
              right: 0,
              bottom: 0,
              backgroundColor: 'rgba(0,0,0,0.5)',
              justifyContent: 'center',
              alignItems: 'center',
              zIndex: 1000,
            }}>
            <View
              style={{
                backgroundColor: 'white',
                padding: 20,
                borderRadius: 8,
                margin: 20,
              }}>
              <Text style={{color: 'black', marginBottom: 10}}>
                Portal Test Working!
              </Text>
              <Button onPress={togglePortalTest}>
                <Text>Close Portal Test</Text>
              </Button>
            </View>
          </View>
        </Portal>
      )}
    </SafeAreaView>
  );
}

Pressing on "Show Alert Dialog" button, show nothing, but the state get updated.
Pressing on "Toggle Direct Portal Test" actually shows a Dialog, so I assume that the PortalHost configuration is fine.

Expected behavior
Dialog should appears.

Screenshots
If applicable, add screenshots to help explain your problem.

Platform (please complete the following information):

  • Type: Simulator, Device
  • OS: iOS

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions