Skip to content

Commit 323c02b

Browse files
M-i-k-e-lethanshar
andauthored
Feat/modal migrate to typescript (#920)
* Rename modal/TopBar from .js to .tsx * Some work on Modal.TopBar typescript * Rename modal/index from .js to .tsx * Modal to typescript * Rename ModalScreen from .js to .tsx * Fix typings exports and move screen to ts * Ignore weird TS issue * ModalPropTypes --> ModalProps + ModalTopBarPropTypes -> ModalTopBarProps * Use typeof Modal Co-authored-by: Ethan Sharabi <[email protected]>
1 parent f4f6d52 commit 323c02b

File tree

10 files changed

+230
-138
lines changed

10 files changed

+230
-138
lines changed

demo/src/screens/componentScreens/ModalScreen.js renamed to demo/src/screens/componentScreens/ModalScreen.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@ import {Alert, StyleSheet} from 'react-native';
33
import {Navigation} from 'react-native-navigation';
44
import {Colors, Carousel, PageControl, Modal, View, Text} from 'react-native-ui-lib'; // eslint-disable-line
55

6+
interface ModalScreenPropTypes {
7+
componentId: string;
8+
}
9+
10+
interface State {
11+
currentPage?: number;
12+
}
613

7-
export default class ModalScreen extends Component {
14+
export default class ModalScreen extends Component<ModalScreenPropTypes, State> {
815

916
static options() {
1017
return {
@@ -15,7 +22,7 @@ export default class ModalScreen extends Component {
1522
};
1623
}
1724

18-
constructor(props) {
25+
constructor(props: ModalScreenPropTypes) {
1926
super(props);
2027

2128
this.state = {
@@ -40,11 +47,11 @@ export default class ModalScreen extends Component {
4047
<Carousel onChangePage={currentPage => this.setState({currentPage})} containerStyle={{flex: 1}}>
4148
<View bg-green50 flex style={styles.page}>
4249
<Modal.TopBar
43-
title='modal title'
50+
title="modal title"
4451
onCancel={() => this.closeScreen()}
4552
onDone={() => Alert.alert('done')}
4653
doneButtonProps={{
47-
disabled: true,
54+
disabled: true
4855
}}
4956
/>
5057
<View padding-20>
@@ -59,11 +66,11 @@ export default class ModalScreen extends Component {
5966

6067
<View bg-violet80 flex style={styles.page}>
6168
<Modal.TopBar
62-
title='another example'
69+
title="another example"
6370
onCancel={() => Alert.alert('cancel')}
6471
onDone={() => Alert.alert('done')}
6572
cancelIcon={null}
66-
cancelLabel='back'
73+
cancelLabel="back"
6774
/>
6875
<View padding-20>
6976
<Text text70>
@@ -75,11 +82,11 @@ export default class ModalScreen extends Component {
7582

7683
<View bg-orange70 flex style={styles.page}>
7784
<Modal.TopBar
78-
title='last one'
85+
title="last one"
7986
onCancel={() => Alert.alert('cancel')}
8087
onDone={() => Alert.alert('done')}
8188
cancelIcon={null}
82-
cancelLabel='back'
89+
cancelLabel="back"
8390
/>
8491
<View padding-20>
8592
<Text text70>
@@ -90,7 +97,7 @@ export default class ModalScreen extends Component {
9097

9198
<View bg-dark70 flex style={styles.page}>
9299
<Modal.TopBar
93-
title='Custom Style'
100+
title="Custom Style"
94101
onCancel={() => Alert.alert('cancel')}
95102
onDone={() => Alert.alert('done')}
96103
doneButtonProps={{color: Colors.orange30}}

generatedTypes/components/button/index.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export declare type ButtonPropTypes = TouchableOpacityProps & TypographyModifier
8686
/**
8787
* Additional styles for label text
8888
*/
89-
labelStyle?: TextStyle;
89+
labelStyle?: StyleProp<TextStyle>;
9090
/**
9191
* Props that will be passed to the button's Text label.
9292
*/
@@ -420,7 +420,7 @@ declare const _default: React.ComponentClass<(Pick<import("react-native").Toucha
420420
/**
421421
* Additional styles for label text
422422
*/
423-
labelStyle?: TextStyle | undefined;
423+
labelStyle?: StyleProp<TextStyle>;
424424
/**
425425
* Props that will be passed to the button's Text label.
426426
*/
@@ -577,7 +577,7 @@ declare const _default: React.ComponentClass<(Pick<import("react-native").Toucha
577577
/**
578578
* Additional styles for label text
579579
*/
580-
labelStyle?: TextStyle | undefined;
580+
labelStyle?: StyleProp<TextStyle>;
581581
/**
582582
* Props that will be passed to the button's Text label.
583583
*/
@@ -734,7 +734,7 @@ declare const _default: React.ComponentClass<(Pick<import("react-native").Toucha
734734
/**
735735
* Additional styles for label text
736736
*/
737-
labelStyle?: TextStyle | undefined;
737+
labelStyle?: StyleProp<TextStyle>;
738738
/**
739739
* Props that will be passed to the button's Text label.
740740
*/
@@ -891,7 +891,7 @@ declare const _default: React.ComponentClass<(Pick<import("react-native").Toucha
891891
/**
892892
* Additional styles for label text
893893
*/
894-
labelStyle?: TextStyle | undefined;
894+
labelStyle?: StyleProp<TextStyle>;
895895
/**
896896
* Props that will be passed to the button's Text label.
897897
*/
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from 'react';
2+
import { StyleProp, TextStyle, ImageSourcePropType } from 'react-native';
3+
import { ButtonPropTypes } from '../../components/button';
4+
export interface ModalTopBarProps {
5+
/**
6+
* title to display in the center of the top bar
7+
*/
8+
title?: string;
9+
/**
10+
* title custom style
11+
*/
12+
titleStyle?: StyleProp<TextStyle>;
13+
/**
14+
* done action props (Button props)
15+
*/
16+
doneButtonProps?: Omit<ButtonPropTypes, 'onPress'>;
17+
/**
18+
* done action label
19+
*/
20+
doneLabel?: string;
21+
/**
22+
* done action icon
23+
*/
24+
doneIcon?: ImageSourcePropType;
25+
/**
26+
* done action callback
27+
*/
28+
onDone?: (props: any) => void;
29+
/**
30+
* cancel action props (Button props)
31+
*/
32+
cancelButtonProps?: Omit<ButtonPropTypes, 'onPress'>;
33+
/**
34+
* cancel action label
35+
*/
36+
cancelLabel?: string;
37+
/**
38+
* cancel action icon
39+
*/
40+
cancelIcon?: ImageSourcePropType;
41+
/**
42+
* cancel action callback
43+
*/
44+
onCancel?: (props: any) => void;
45+
/**
46+
* whether to include status bar or not (height claculations)
47+
*/
48+
includeStatusBar?: boolean;
49+
}
50+
declare const _default: React.ComponentClass<ModalTopBarProps & {
51+
useCustomTheme?: boolean | undefined;
52+
}, any>;
53+
export default _default;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React, { Component } from 'react';
2+
import { ModalProps as RNModalProps, GestureResponderEvent } from 'react-native';
3+
import TopBar, { ModalTopBarProps } from './TopBar';
4+
export { ModalTopBarProps };
5+
export interface ModalProps extends RNModalProps {
6+
/**
7+
* Blurs the modal background when transparent (iOS only)
8+
*/
9+
enableModalBlur?: boolean;
10+
/**
11+
* A custom view to use as a BlueView instead of the default one
12+
*/
13+
blurView?: JSX.Element;
14+
/**
15+
* allow dismissing a modal when clicking on its background
16+
*/
17+
onBackgroundPress?: (event: GestureResponderEvent) => void;
18+
/**
19+
* the background color of the overlay
20+
*/
21+
overlayBackgroundColor?: string;
22+
/**
23+
* The modal's end-to-end test identifier
24+
*/
25+
testID?: string;
26+
/**
27+
* Overrides the text that's read by the screen reader when the user interacts with the element. By default, the
28+
* label is constructed by traversing all the children and accumulating all the Text nodes separated by space.
29+
*/
30+
accessibilityLabel?: string;
31+
}
32+
/**
33+
* @description: Component that present content on top of the invoking screen
34+
* @extends: Modal
35+
* @extendslink: https://facebook.github.io/react-native/docs/modal.html
36+
* @gif: https://media.giphy.com/media/3oFzmfSX8KgvctI4Ks/giphy.gif
37+
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/ModalScreen.js
38+
*/
39+
declare class Modal extends Component<ModalProps> {
40+
static displayName: string;
41+
static TopBar: typeof TopBar;
42+
renderTouchableOverlay(): JSX.Element | undefined;
43+
render(): JSX.Element;
44+
}
45+
declare const _default: React.ComponentClass<typeof Modal & {
46+
useCustomTheme?: boolean | undefined;
47+
}, any>;
48+
export default _default;

generatedTypes/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export {default as RadioButton, RadioButtonPropTypes} from './components/radioBu
2121
export {default as RadioGroup, RadioGroupPropTypes} from './components/radioButton/RadioGroup';
2222
export {default as TabBar} from './components/TabBar';
2323
export {default as Fader, FaderProps} from './components/fader';
24+
export {default as Modal, ModalProps, ModalTopBarProps} from './components/modal';
2425

2526
/* All components with manual typings */
2627
export {
@@ -64,7 +65,6 @@ export {
6465
Constants,
6566
LogService,
6667
LoaderScreen,
67-
Modal,
6868
StateScreen,
6969
WheelPicker,
7070
WheelPickerProps,

src/components/button/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export type ButtonPropTypes = TouchableOpacityProps &
109109
/**
110110
* Additional styles for label text
111111
*/
112-
labelStyle?: TextStyle;
112+
labelStyle?: StyleProp<TextStyle>;
113113
/**
114114
* Props that will be passed to the button's Text label.
115115
*/

0 commit comments

Comments
 (0)