Skip to content

Commit 1e6486f

Browse files
authored
Fix/drawer types source (#1069)
* Removing Drawer manual typings * Adding 'customValue' prop to pass with props on callbacks; adding props' type declaration * fix for generated types * exporting DrawerItemProps; removing manual typings from index
1 parent 5930ea5 commit 1e6486f

File tree

8 files changed

+53
-70
lines changed

8 files changed

+53
-70
lines changed

generatedTypes/components/drawer/Swipeable.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component } from 'react';
22
import { Animated } from 'react-native';
3-
export declare type PropType = {
3+
declare type Props = {
44
children: any;
55
friction: number;
66
leftThreshold?: number;
@@ -42,7 +42,8 @@ declare type StateType = {
4242
rightOffset: number | typeof undefined;
4343
rowWidth: number | typeof undefined;
4444
};
45-
export default class Swipeable extends Component<PropType, StateType> {
45+
export declare type SwipeableProps = Props;
46+
export default class Swipeable extends Component<Props, StateType> {
4647
static displayName: string;
4748
static defaultProps: {
4849
friction: number;
@@ -51,7 +52,7 @@ export default class Swipeable extends Component<PropType, StateType> {
5152
fullLeftThreshold: number;
5253
fullRightThreshold: number;
5354
};
54-
constructor(props: PropType);
55+
constructor(props: Props);
5556
_handleDrag: (e: any) => void;
5657
getTransX: () => Animated.AnimatedInterpolation;
5758
getShowLeftAction: () => Animated.Value | Animated.AnimatedInterpolation;

generatedTypes/components/drawer/index.d.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { PureComponent, RefObject } from 'react';
22
import { Animated, ViewStyle, TextStyle } from 'react-native';
3-
import Swipeable, { PropType as SwipeableProps } from './Swipeable';
3+
import Swipeable, { SwipeableProps } from './Swipeable';
44
interface ItemProps {
55
width?: number;
66
background?: string;
@@ -11,7 +11,7 @@ interface ItemProps {
1111
style?: ViewStyle;
1212
testID?: string;
1313
}
14-
interface DrawerProps {
14+
interface Props {
1515
/**
1616
* The drawer animation bounciness
1717
*/
@@ -92,14 +92,27 @@ interface DrawerProps {
9292
* Style
9393
*/
9494
style?: ViewStyle;
95+
/**
96+
* Callback for open action
97+
*/
98+
onSwipeableWillOpen?: Function;
99+
/**
100+
* Callback for close action
101+
*/
102+
onSwipeableWillClose?: Function;
103+
/**
104+
* Custom value of any type to pass on to the component and receive back in the action callbacks
105+
*/
106+
customValue?: any;
95107
}
108+
export declare type DrawerProps = Props;
96109
/**
97110
* @description: Drawer Component
98111
* @important: If your app works with RNN, your screen must be wrapped
99112
* with gestureHandlerRootHOC from 'react-native-gesture-handler'. see
100113
* @importantLink: https://kmagiera.github.io/react-native-gesture-handler/docs/getting-started.html#with-wix-react-native-navigation-https-githubcom-wix-react-native-navigation
101114
*/
102-
declare class Drawer extends PureComponent<DrawerProps> {
115+
declare class Drawer extends PureComponent<Props> {
103116
static displayName: string;
104117
static defaultProps: {
105118
itemsTintColor: string;
@@ -137,7 +150,7 @@ declare class Drawer extends PureComponent<DrawerProps> {
137150
private renderAction;
138151
render(): JSX.Element;
139152
}
140-
declare const _default: React.ComponentClass<DrawerProps & {
153+
declare const _default: React.ComponentClass<Props & {
141154
useCustomTheme?: boolean | undefined;
142155
}, any> & typeof Drawer;
143156
export default _default;

generatedTypes/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export {default as TouchableOpacity, TouchableOpacityProps} from './components/t
3535
export {default as Button, ButtonPropTypes, ButtonProps} from './components/button';
3636
export {default as Checkbox, CheckboxPropTypes, CheckboxProps} from './components/checkbox';
3737
export {default as Chip, ChipPropTypes, ChipProps} from './components/chip';
38+
export {default as Drawer, DrawerProps, DrawerItemProps} from './components/drawer';
3839
export {default as FloatingButton, FloatingButtonProps} from './components/floatingButton';
3940
export {default as Image, ImageProps} from './components/image';
4041
export {default as Overlay, OverlayTypes} from './components/overlay';
@@ -67,7 +68,6 @@ export {default as Carousel, CarouselProps} from './components/carousel';
6768
export {
6869
ActionSheet,
6970
ConnectionStatusBar,
70-
Drawer,
7171
FeatureHighlight,
7272
Hint,
7373
BaseInput,

src/components/drawer/Swipeable.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if (!Math.sign) {
2323
};
2424
}
2525

26-
export type PropType = {
26+
type Props = {
2727
children: any,
2828
friction: number,
2929
leftThreshold?: number,
@@ -58,6 +58,7 @@ export type PropType = {
5858
containerStyle?: Object,
5959
childrenContainerStyle?: Object
6060
};
61+
6162
type StateType = {
6263
dragX: Animated.Value,
6364
rowTranslation: Animated.Value,
@@ -66,7 +67,9 @@ type StateType = {
6667
rowWidth: number | typeof undefined
6768
};
6869

69-
export default class Swipeable extends Component<PropType, StateType> {
70+
export type SwipeableProps = Props;
71+
72+
export default class Swipeable extends Component<Props, StateType> {
7073
static displayName = 'IGNORE';
7174
static defaultProps = {
7275
friction: 1,
@@ -83,7 +86,7 @@ export default class Swipeable extends Component<PropType, StateType> {
8386
// _showRightAction: ?Animated.Interpolation | ?Animated.Value;
8487
// _rightActionTranslate: ?Animated.Interpolation;
8588

86-
constructor(props: PropType) {
89+
constructor(props: Props) {
8790
super(props);
8891

8992
const dragX = new Animated.Value(0);

src/components/drawer/index.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {extractAccessibilityProps} from '../../commons/modifiers';
88
import {Constants} from '../../helpers';
99
import {Colors} from '../../style';
1010
import View from '../view';
11-
import Swipeable, {PropType as SwipeableProps} from './Swipeable';
11+
import Swipeable, {SwipeableProps} from './Swipeable';
12+
1213

1314
const DEFAULT_BG = Colors.blue30;
1415
const DEFAULT_BOUNCINESS = 0;
@@ -24,7 +25,7 @@ interface ItemProps {
2425
testID?: string;
2526
}
2627

27-
interface DrawerProps {
28+
interface Props {
2829
/**
2930
* The drawer animation bounciness
3031
*/
@@ -105,15 +106,30 @@ interface DrawerProps {
105106
* Style
106107
*/
107108
style?: ViewStyle;
109+
/**
110+
* Callback for open action
111+
*/
112+
onSwipeableWillOpen?: Function;
113+
/**
114+
* Callback for close action
115+
*/
116+
onSwipeableWillClose?: Function;
117+
/**
118+
* Custom value of any type to pass on to the component and receive back in the action callbacks
119+
*/
120+
customValue?: any;
108121
}
109122

123+
export type DrawerProps = Props;
124+
export type DrawerItemProps = ItemProps;
125+
110126
/**
111127
* @description: Drawer Component
112128
* @important: If your app works with RNN, your screen must be wrapped
113129
* with gestureHandlerRootHOC from 'react-native-gesture-handler'. see
114130
* @importantLink: https://kmagiera.github.io/react-native-gesture-handler/docs/getting-started.html#with-wix-react-native-navigation-https-githubcom-wix-react-native-navigation
115131
*/
116-
class Drawer extends PureComponent<DrawerProps> {
132+
class Drawer extends PureComponent<Props> {
117133
static displayName = 'Drawer';
118134

119135
static defaultProps = {
@@ -204,7 +220,7 @@ class Drawer extends PureComponent<DrawerProps> {
204220

205221
private animateItem({rowWidth, leftWidth, dragX, released, resetItemPosition}: any) {
206222
const toValue = resetItemPosition ? 0 : dragX ? dragX - leftWidth : rowWidth * 0.6 - leftWidth;
207-
223+
208224
Animated.timing(this.leftActionX, {
209225
toValue,
210226
easing: Easing.bezier(0.25, 1, 0.5, 1),

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ export {default as Carousel, CarouselProps} from './components/carousel';
6060

6161
//================ Manual typings (all those exports should be removed one day) ==========
6262
export {
63-
ActionSheet, ConnectionStatusBar, ChipsInput, Drawer,
64-
FeatureHighlight, Hint, BaseInput, TextArea, TextField, MaskedInput, ListItem,
65-
Picker, PickerProps, ProgressBar, Slider,
66-
GradientSlider, ColorSliderGroup, Stepper, TagsInput, SharedTransition, StackAggregator, Toast,
67-
WheelPickerDialog, Assets, BaseComponent, PureBaseComponent, UIComponent, forwardRef, AvatarHelper,
63+
ActionSheet, ConnectionStatusBar, ChipsInput,
64+
FeatureHighlight, Hint, BaseInput, TextArea, TextField, MaskedInput, ListItem, Picker,
65+
PickerProps, ProgressBar, Slider, GradientSlider, ColorSliderGroup, Stepper,
66+
TagsInput, SharedTransition, StackAggregator, Toast, WheelPickerDialog, Assets,
67+
BaseComponent, PureBaseComponent, UIComponent, forwardRef, AvatarHelper,
6868
LogService, LoaderScreen, StateScreen, WheelPicker, WheelPickerProps, ColorPicker
6969
} from '../typings';

typings/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export * from './commons';
44
export * from './components';
55
export * from './helpers';
66
export * from './incubator';
7-
export * from './interactableComponents';
87
export * from './nativeComponents';
98
export * from './services';
109
export * from './generatedTypes';

typings/interactableComponents/index.d.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)