Skip to content

Commit 46a9fe7

Browse files
M-i-k-e-lethanshar
andauthored
Create a Dialog that uses hooks (#2116)
* Create a Dialog that uses hooks * Removed old unused file (HeaderContent) * Move isEmpty check * Move text props to header props and fix api Co-authored-by: Ethan Sharabi <[email protected]>
1 parent 2cadf61 commit 46a9fe7

14 files changed

+281
-340
lines changed

demo/src/screens/incubatorScreens/IncubatorDialogScreen.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const colors: Item[] = [
3434
export default class IncubatorDialogScreen extends Component {
3535
state = {visible: false};
3636
modalProps: ModalProps = {supportedOrientations: ['portrait', 'landscape']};
37-
headerProps: Incubator.DialogHeaderProps = {text: {title: 'Title (swipe here)'}};
37+
headerProps: Incubator.DialogHeaderProps = {title: 'Title (swipe here)'};
3838

3939
renderVerticalItem = ({item}: {item: Item}) => {
4040
return (
@@ -66,7 +66,9 @@ export default class IncubatorDialogScreen extends Component {
6666
return (
6767
<View bg-$backgroundNeutralLight flex padding-20>
6868
<Card height={100} center padding-20>
69-
<Text $textDefault text50>IncubatorDialogScreen</Text>
69+
<Text $textDefault text50>
70+
IncubatorDialogScreen
71+
</Text>
7072
</Card>
7173
<View flex center>
7274
<Button marginV-s5 label="Open Dialog" onPress={this.openDialog}/>

src/incubator/Dialog/DialogHeader.tsx

+32-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@ import {StyleSheet} from 'react-native';
44
import {asBaseComponent} from '../../commons/new';
55
import {Spacings, Colors, BorderRadiuses, Dividers} from 'style';
66
import View from '../../components/view';
7-
import HeaderContent from './HeaderContent';
7+
import Text from '../../components/text';
88
import {DialogHeaderProps} from './types';
99

1010
const DialogHeader = (props: DialogHeaderProps = {}) => {
11-
const {text = {}, renderContent, showKnob = true, showDivider = true, ...others} = props;
11+
const {
12+
title,
13+
titleStyle,
14+
titleProps,
15+
subtitle,
16+
subtitleStyle,
17+
subtitleProps,
18+
renderContent,
19+
showKnob = true,
20+
showDivider = true,
21+
...others
22+
} = props;
1223

1324
const knob = useMemo(() => {
1425
if (showKnob) {
@@ -21,9 +32,26 @@ const DialogHeader = (props: DialogHeaderProps = {}) => {
2132
return renderContent(props);
2233
}
2334

24-
return <HeaderContent text={text}/>;
35+
if (!isEmpty(title) || !isEmpty(subtitle)) {
36+
return (
37+
<View marginH-s5 marginV-s1>
38+
{title && (
39+
<Text $textDefault {...titleProps} marginB-s3 style={titleStyle}>
40+
{title}
41+
</Text>
42+
)}
43+
{subtitle && (
44+
<Text $textDefault {...subtitleProps} marginB-s3 style={subtitleStyle}>
45+
{subtitle}
46+
</Text>
47+
)}
48+
</View>
49+
);
50+
}
51+
52+
return null;
2553
// eslint-disable-next-line react-hooks/exhaustive-deps
26-
}, [renderContent, text]);
54+
}, [renderContent, title, titleStyle, titleProps, subtitle, subtitleStyle, subtitleProps]);
2755

2856
const divider = useMemo(() => {
2957
if (showDivider) {

src/incubator/Dialog/HeaderContent.tsx

-31
This file was deleted.

src/incubator/Dialog/ImperativeDialog.tsx

-126
This file was deleted.

src/incubator/Dialog/dialog.api.json

+18-4
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,33 @@
77
"example": "https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/incubatorScreens/IncubatorDialogScreen.tsx",
88
"props": [
99
{"name": "visible", "type": "boolean", "description": "The visibility of the dialog"},
10-
{"name": "onDismiss", "type": "(props?: ImperativeDialogProps) => void", "description": "Callback that is called after the dialog's dismiss (after the animation has ended)."},
10+
{"name": "headerProps", "type": "DialogHeaderProps", "description": "The Dialog's header (title, subtitle etc)"},
11+
{
12+
"name": "containerStyle",
13+
"type": "ViewStyle",
14+
"description": "The Dialog`s container style (it is set to {position: 'absolute'})"
15+
},
16+
{
17+
"name": "onDismiss",
18+
"type": "(props?: DialogProps) => void",
19+
"description": "Callback that is called after the dialog's dismiss (after the animation has ended)."
20+
},
1121
{
1222
"name": "direction",
1323
"type": "up | down | left | right",
14-
"description": "The direction from which and to which the dialog is animating \\ panning (default bottom).",
24+
"description": "The direction from which and to which the dialog is animating \\ panning (default down).",
1525
"default": "down"
1626
},
1727
{"name": "ignoreBackgroundPress", "type": "boolean", "description": "Whether or not to ignore background press."},
1828
{"name": "modalProps", "type": "ModalProps", "description": "Pass props to the dialog modal"},
19-
{"name": "testID", "type": "string", "description": "Used as a testing identifier"}
29+
{
30+
"name": "testID",
31+
"type": "string",
32+
"description": "Used to locate this view in end-to-end tests\nThe container has the unchanged id.\nCurrently supported inner IDs:\n<TestID>.modal - the Modal's id.\n<TestID>.overlayFadingBackground - the fading background id."
33+
}
2034
],
2135
"snippet": [
22-
"<Dialog",
36+
"<Dialog",
2337
" visible={this.state.visible$1}",
2438
" onDismiss={() => console.log('dismissed')$2}",
2539
" panDirection={PanningProvider.Directions.DOWN$3}",

src/incubator/Dialog/helpers/useAlignmentStyle.tsx

-43
This file was deleted.

src/incubator/Dialog/helpers/useSafeAreaView.tsx

-37
This file was deleted.

0 commit comments

Comments
 (0)