Skip to content

Commit c74cc60

Browse files
chore(dialogs): replaced type with enum and improved conditional render
1 parent b508af7 commit c74cc60

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ export const YourComponent = () => {
402402

403403
| name | description | type | default |
404404
| ------ | ------ | ------ | ----|
405-
| animationType | - | 'slide', 'fade', 'zoom' | 'slide' |
405+
| animationType | - | AnimationType | AnimationType.SLIDE |
406406
| animationDuration | - | number | 330 |
407407

408408
![full screen dialog gif](https://ik.imagekit.io/Computools/rn-material-components/full-screen-dialog.gif?updatedAt=1729261989519)

src/dialogs/basic-dialog/BasicDialog.compoent.tsx renamed to src/dialogs/basic-dialog/BasicDialog.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export const BasicDialog = forwardRef<DialogRef, BasicDialogProps>(
4949
return (
5050
<Dialog ref={ref} style={[style]} {...props}>
5151
{prepend}
52-
{title && <Text style={[headlineSmall, styles.title, {color: surfaceContainer.text}, titleStyle]}>{title}</Text>}
53-
{subtitle && <Text style={[bodyMedium, {color: surfaceContainer.textVariant}, subtitleStyle]}>{subtitle}</Text>}
52+
{title ? <Text style={[headlineSmall, styles.title, {color: surfaceContainer.text}, titleStyle]}>{title}</Text> : null}
53+
{subtitle ? <Text style={[bodyMedium, {color: surfaceContainer.textVariant}, subtitleStyle]}>{subtitle}</Text> : null}
5454
{append}
5555
{firstActionTitle && (
5656
<View style={styles.actions}>

src/dialogs/full-screen-dialog/FullScreenDialog.component.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {useTheme} from '../../theme/useTheme.hook';
88
import {styles} from './full-screen-dialog.styles';
99
import {ModalBackdropWrapper} from '../../modal-backdrop-wrapper/ModalBackdropWrapper.component';
1010

11-
type AnimationType = 'slide' | 'fade' | 'zoom';
11+
export enum AnimationType {
12+
SLIDE = 'SLIDE',
13+
FADE = 'FADE',
14+
ZOOM = 'ZOOM',
15+
}
1216

1317
interface Props extends ViewProps {
1418
animationDuration?: number;
@@ -24,7 +28,7 @@ export interface FullScreenDialogRef {
2428
const ANIMATION_DURATION = 330;
2529

2630
export const FullScreenDialog = forwardRef<FullScreenDialogRef, PropsWithChildren<Props>>(
27-
({children, animationType = 'slide', animationDuration = ANIMATION_DURATION, style, ...props}, ref) => {
31+
({children, animationType = AnimationType.SLIDE, animationDuration = ANIMATION_DURATION, style, ...props}, ref) => {
2832
const [isVisible, setIsVisible] = useState(false);
2933
const [isClosing, setIsClosing] = useState(false);
3034

@@ -46,7 +50,7 @@ export const FullScreenDialog = forwardRef<FullScreenDialogRef, PropsWithChildre
4650
visibility.value = withTiming(1, {duration: animationDuration});
4751
},
4852
close() {
49-
if (animationType === 'zoom') {
53+
if (animationType === AnimationType.ZOOM) {
5054
setIsClosing(true);
5155
}
5256

@@ -66,14 +70,14 @@ export const FullScreenDialog = forwardRef<FullScreenDialogRef, PropsWithChildre
6670
};
6771

6872
switch (animationType) {
69-
case 'slide':
73+
case AnimationType.SLIDE:
7074
return slideAnimStyle;
71-
case 'fade': {
75+
case AnimationType.FADE: {
7276
return {
7377
opacity: visibility.value,
7478
};
7579
}
76-
case 'zoom': {
80+
case AnimationType.ZOOM: {
7781
return isClosing
7882
? slideAnimStyle
7983
: {

src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export {OutlinedCard} from './cards/outlined-card/OutlinedCard.component';
1212
export {ElevatedCard} from './cards/elevated-card/ElevatedCard.cpmponent';
1313

1414
export {Dialog, type DialogRef, type DialogProps} from './dialogs/dialog/Dialog.component';
15-
export {BasicDialog, type BasicDialogProps} from './dialogs/basic-dialog/BasicDialog.compoent';
16-
export {FullScreenDialog, type FullScreenDialogRef} from './dialogs/full-screen-dialog/FullScreenDialog.component';
15+
export {BasicDialog, type BasicDialogProps} from './dialogs/basic-dialog/BasicDialog.component';
16+
export {FullScreenDialog, AnimationType, type FullScreenDialogRef} from './dialogs/full-screen-dialog/FullScreenDialog.component';
1717

1818
export {Snackbar, type SnackbarProps, type SnackbarRef} from './snackbar/Snackbar.component';
1919

0 commit comments

Comments
 (0)