Skip to content

Dialogs

Overview

Dialogs are interactive UI elements used to display critical information, request user input, or facilitate decision-making processes in your application. This library provides several dialog components, including:

  • Basic Dialog: A simple and flexible dialog with customizable actions.
  • Full-Screen Dialog: A dialog that covers the entire screen, suitable for tasks requiring more space.
  • Dialog: A wrapper component for creating custom dialogs with full control.

Basic Dialog

A ready-to-use dialog component that comes with common properties and functionality.

basic dialog

Properties

namedescriptiontypedefault
titleDialog title textstring-
subtitleDialog subtitle textstring-
firstActionTitleTitle of the first action buttonstring-
secondActionTitleTitle of the second action buttonstring-
onFirstActionPressCallback for the first action button()() => void
onSecondActionPressCallback for the second action button() => void-
titleStyleStyle for the title textTextStyle-
subtitleStyleStyle for the subtitle textTextStyle-
prependComponent to prepend contentReactNde-
appendComponent to append contentReactNde-

Full-Screen Dialog

A dialog that occupies the full screen, ideal for tasks that require more space

full screen dialog

Properties

namedescriptiontypedefault
animationTypeType of animation: SLIDE, FADE or ZOOMAnimationTypeAnimationType.SLIDE
animationDurationAnimation duration (ms)number330

Dialog

The Dialog component serves as a wrapper for creating custom dialogs. You can use it in conjunction with your own components to design a dialog tailored to your application's needs.

Methods

namedescriptionparametersreturns
showDisplays the dialog.nonevoid
closeHides the dialog.nonevoid
isShowedChecks whether the dialog is currently visible on the screen.noneboolean

Properties

namedescriptiontypedefault
animationDurationAppearance/disappearance animation duration.number220

Usage Example

typescript
import React, { useRef } from 'react';
import { Button } from 'react-native';
import { Dialog, type DialogRef } from '@computools/react-native-material-components';

export const YourComponent = () => {
  const dialogRef = useRef<DialogRef>(null);

  return (
    <>
      {/* Rest of your app code */}
      <Button title="Show Dialog" onPress={() => dialogRef.current?.show()} />
      <Dialog ref={dialogRef}>
        <YourDialogContent />
      </Dialog>
      {/* Rest of your app code */}
    </>
  );
};

Troubleshooting

  • Modal Unexpectedly Reappears

In certain scenarios, a modal might reappear after being closed, particularly if actions such as navigation are triggered during or immediately after its closure. This behavior occurs due to race conditions in the UI thread.

Solution: Use InteractionManager.runAfterInteractions to delay actions until ongoing interactions are completed.

Fix Example

typescript
const onSubmitPress = async () => {
  const isSuccessfullySignedOut = await signOut();

  if (isSuccessfullySignedOut) {
    InteractionManager.runAfterInteractions(() => {
      navigation.dispatch(
        CommonActions.reset({
          index: 0,
          routes: [{ name: MainStackRoutes.Welcome }],
        })
      );
    });
  }
};