Skip to content

Commit 3a6276d

Browse files
authored
Typescript migration fixes - PanningViews and Modal (wix#929)
1 parent becea39 commit 3a6276d

12 files changed

+51
-37
lines changed

generatedTypes/components/modal/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ declare class Modal extends Component<ModalProps> {
4242
renderTouchableOverlay(): JSX.Element | undefined;
4343
render(): JSX.Element;
4444
}
45-
declare const _default: React.ComponentClass<typeof Modal & {
45+
declare const _default: React.ComponentClass<ModalProps & {
4646
useCustomTheme?: boolean | undefined;
47-
}, any>;
47+
}, any> & typeof Modal;
4848
export default _default;

generatedTypes/components/panningViews/panDismissibleView.d.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import React from 'react';
22
import { StyleProp, ViewStyle } from 'react-native';
3-
import { PanningDirections, PanAmountsProps } from './panningProvider';
3+
import { PanningDirections, PanningProviderDirection, PanAmountsProps } from './panningProvider';
44
export interface DismissibleAnimationPropTypes {
55
/**
66
* The return animation speed (default is 20)
77
*/
8-
speed: number;
8+
speed?: number;
99
/**
1010
* The return animation bounciness (default is 6)
1111
*/
12-
bounciness: number;
12+
bounciness?: number;
1313
/**
1414
* The dismiss animation duration (default is 280)
1515
*/
16-
duration: number;
16+
duration?: number;
1717
}
1818
export interface PanDismissibleViewPropTypes {
1919
/**
@@ -24,7 +24,7 @@ export interface PanDismissibleViewPropTypes {
2424
* The directions of the allowed pan (default allows all directions)
2525
* Types: UP, DOWN, LEFT and RIGHT (using PanningProvider.Directions.###)
2626
*/
27-
directions?: PanningDirections[];
27+
directions?: PanningDirections[] | PanningProviderDirection[];
2828
/**
2929
* onDismiss callback
3030
*/
@@ -35,7 +35,7 @@ export interface PanDismissibleViewPropTypes {
3535
* bounciness - the animation bounciness (default is 6)
3636
* duration - the dismiss animation duration (default is 280)
3737
*/
38-
animationOptions: DismissibleAnimationPropTypes;
38+
animationOptions?: DismissibleAnimationPropTypes;
3939
/**
4040
* Override the default threshold (height/2 and width/2) with different values.
4141
*/

generatedTypes/components/panningViews/panGestureView.d.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export declare enum GestureDirections {
44
UP = "up",
55
DOWN = "down"
66
}
7-
export interface PanGestureViewPropTypes {
7+
export interface PanGestureViewProps {
88
/**
99
* Additional styling
1010
*/
@@ -18,9 +18,7 @@ export interface PanGestureViewPropTypes {
1818
*/
1919
direction?: GestureDirections;
2020
}
21-
declare const _default: React.ComponentClass<PanGestureViewPropTypes & {
22-
useCustomTheme?: boolean | undefined; /**
23-
* onDismiss callback
24-
*/
21+
declare const _default: React.ComponentClass<PanGestureViewProps & {
22+
useCustomTheme?: boolean | undefined;
2523
}, any>;
2624
export default _default;

generatedTypes/components/panningViews/panListenerView.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { PanningDirections, PanDirectionsProps, PanAmountsProps } from './panningProvider';
2+
import { PanningDirections, PanDirectionsProps, PanAmountsProps, PanningProviderDirection } from './panningProvider';
33
import { ViewPropTypes } from '../view';
44
interface PanningPropTypes {
55
/**
@@ -46,7 +46,7 @@ export interface PanListenerViewPropTypes extends PanningPropTypes, ViewPropType
4646
* The directions of the allowed pan (default allows all directions)
4747
* Types: UP, DOWN, LEFT and RIGHT (using PanningProvider.Directions.###)
4848
*/
49-
directions?: PanningDirections[];
49+
directions?: PanningDirections[] | PanningProviderDirection[];
5050
/**
5151
* The sensitivity beyond which a pan is no longer considered a single click (default is 5)
5252
*/

generatedTypes/components/panningViews/panningProvider.d.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { Component } from 'react';
2+
/**
3+
* @deprecated Please transition to PanningDirections
4+
*/
5+
export declare type PanningProviderDirection = 'up' | 'down' | 'left' | 'right';
26
export declare enum PanningDirections {
37
UP = "up",
48
DOWN = "down",
@@ -10,8 +14,8 @@ export interface PanLocationProps {
1014
top?: number;
1115
}
1216
export interface PanDirectionsProps {
13-
x?: PanningDirections;
14-
y?: PanningDirections;
17+
x?: PanningDirections | PanningProviderDirection;
18+
y?: PanningDirections | PanningProviderDirection;
1519
}
1620
export interface PanAmountsProps {
1721
x?: number;

generatedTypes/index.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ export {default as RadioGroup, RadioGroupPropTypes} from './components/radioButt
2222
export {default as TabBar} from './components/TabBar';
2323
export {default as Fader, FaderProps, FaderPosition} from './components/fader';
2424
export {default as Modal, ModalProps, ModalTopBarProps} from './components/modal';
25+
export {default as PanGestureView, PanGestureViewProps} from './components/panningViews/panGestureView';
2526
export {default as PanningContext} from './components/panningViews/panningContext';
2627
export {default as asPanViewConsumer} from './components/panningViews/asPanViewConsumer';
2728
export {
2829
default as PanningProvider,
2930
PanningDirections,
3031
PanLocationProps,
3132
PanAmountsProps,
32-
PanDirectionsProps
33+
PanDirectionsProps,
34+
PanningProviderDirection
3335
} from './components/panningViews/panningProvider';
3436
export {default as PanListenerView, PanListenerViewPropTypes} from './components/panningViews/panListenerView';
3537
export {default as PanResponderView, PanResponderViewPropTypes} from './components/panningViews/panResponderView';

src/components/modal/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@ const styles = StyleSheet.create({
102102

103103
Modal.TopBar = TopBar;
104104

105-
export default asBaseComponent<typeof Modal>(Modal);
105+
export default asBaseComponent<ModalProps, typeof Modal>(Modal);

src/components/panningViews/panDismissibleView.tsx

+10-8
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ import React, {PureComponent} from 'react';
33
import {Animated, LayoutChangeEvent, StyleProp, ViewStyle} from 'react-native';
44
import {Constants} from '../../helpers';
55
import asPanViewConsumer from './asPanViewConsumer';
6-
import PanningProvider, {PanningDirections, PanAmountsProps, PanDirectionsProps} from './panningProvider';
6+
import PanningProvider, {PanningDirections, PanningProviderDirection, PanAmountsProps, PanDirectionsProps} from './panningProvider';
77

88
export interface DismissibleAnimationPropTypes {
99
/**
1010
* The return animation speed (default is 20)
1111
*/
12-
speed: number;
12+
speed?: number;
1313
/**
1414
* The return animation bounciness (default is 6)
1515
*/
16-
bounciness: number;
16+
bounciness?: number;
1717
/**
1818
* The dismiss animation duration (default is 280)
1919
*/
20-
duration: number;
20+
duration?: number;
2121
}
2222

2323
export interface PanDismissibleViewPropTypes {
@@ -29,7 +29,7 @@ export interface PanDismissibleViewPropTypes {
2929
* The directions of the allowed pan (default allows all directions)
3030
* Types: UP, DOWN, LEFT and RIGHT (using PanningProvider.Directions.###)
3131
*/
32-
directions?: PanningDirections[];
32+
directions?: PanningDirections[] | PanningProviderDirection[];
3333
/**
3434
* onDismiss callback
3535
*/
@@ -40,7 +40,7 @@ export interface PanDismissibleViewPropTypes {
4040
* bounciness - the animation bounciness (default is 6)
4141
* duration - the dismiss animation duration (default is 280)
4242
*/
43-
animationOptions: DismissibleAnimationPropTypes;
43+
animationOptions?: DismissibleAnimationPropTypes;
4444
/**
4545
* Override the default threshold (height/2 and width/2) with different values.
4646
*/
@@ -224,7 +224,8 @@ class PanDismissibleView extends PureComponent<Props, State> {
224224
};
225225

226226
resetPosition = () => {
227-
const {speed, bounciness} = this.props.animationOptions;
227+
const {animationOptions} = this.props;
228+
const {speed, bounciness} = animationOptions || DEFAULT_ANIMATION_OPTIONS;
228229
const toX = -this.left;
229230
const toY = -this.top;
230231
const animations: Animated.CompositeAnimation[] = [];
@@ -333,7 +334,8 @@ class PanDismissibleView extends PureComponent<Props, State> {
333334
};
334335

335336
_animateDismiss = (isRight?: boolean, isDown?: boolean) => {
336-
const {duration} = this.props.animationOptions;
337+
const {animationOptions} = this.props;
338+
const {duration} = animationOptions || DEFAULT_ANIMATION_OPTIONS;
337339
const animations: Animated.CompositeAnimation[] = [];
338340
let toX;
339341
let toY;

src/components/panningViews/panGestureView.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export enum GestureDirections {
2020
DOWN = 'down'
2121
}
2222

23-
export interface PanGestureViewPropTypes {
23+
export interface PanGestureViewProps {
2424
/**
2525
* Additional styling
2626
*/
@@ -46,10 +46,10 @@ interface State {
4646
/**
4747
* @description: PanGestureView component for drag and swipe gestures (supports only vertical gestures at the moment)
4848
*/
49-
class PanGestureView extends Component<PanGestureViewPropTypes, State> {
49+
class PanGestureView extends Component<PanGestureViewProps, State> {
5050
static displayName = 'PanGestureView'
5151

52-
static defaultProps: Partial<PanGestureViewPropTypes> = {
52+
static defaultProps: Partial<PanGestureViewProps> = {
5353
direction: GestureDirections.DOWN
5454
};
5555

@@ -59,7 +59,7 @@ class PanGestureView extends Component<PanGestureViewPropTypes, State> {
5959
private swipe?: boolean;
6060
private layout?: LayoutRectangle;
6161

62-
constructor(props: PanGestureViewPropTypes) {
62+
constructor(props: PanGestureViewProps) {
6363
super(props);
6464

6565
this.state = {
@@ -199,4 +199,4 @@ class PanGestureView extends Component<PanGestureViewPropTypes, State> {
199199
}
200200
}
201201

202-
export default asBaseComponent<PanGestureViewPropTypes>(PanGestureView);
202+
export default asBaseComponent<PanGestureViewProps>(PanGestureView);

src/components/panningViews/panListenerView.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import asPanViewConsumer from './asPanViewConsumer';
1010
import PanningProvider, {
1111
PanningDirections,
1212
PanDirectionsProps,
13-
PanAmountsProps
13+
PanAmountsProps,
14+
PanningProviderDirection
1415
} from './panningProvider';
1516
import View, {ViewPropTypes} from '../view';
1617

@@ -54,7 +55,7 @@ export interface PanListenerViewPropTypes extends PanningPropTypes, ViewPropType
5455
* The directions of the allowed pan (default allows all directions)
5556
* Types: UP, DOWN, LEFT and RIGHT (using PanningProvider.Directions.###)
5657
*/
57-
directions?: PanningDirections[];
58+
directions?: PanningDirections[] | PanningProviderDirection[];
5859
/**
5960
* The sensitivity beyond which a pan is no longer considered a single click (default is 5)
6061
*/

src/components/panningViews/panningProvider.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import React, {Component} from 'react';
22
import PanningContext from './panningContext';
33

4+
/**
5+
* @deprecated Please transition to PanningDirections
6+
*/
7+
export type PanningProviderDirection = 'up' | 'down' | 'left' | 'right';
8+
49
export enum PanningDirections {
510
UP = 'up',
611
DOWN = 'down',
@@ -14,8 +19,8 @@ export interface PanLocationProps {
1419
}
1520

1621
export interface PanDirectionsProps {
17-
x?: PanningDirections;
18-
y?: PanningDirections;
22+
x?: PanningDirections | PanningProviderDirection;
23+
y?: PanningDirections | PanningProviderDirection;
1924
}
2025

2126
export interface PanAmountsProps {

src/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ export {default as RadioGroup, RadioGroupPropTypes} from './components/radioButt
2323
export {default as TabBar} from './components/TabBar';
2424
export {default as Fader, FaderProps, FaderPosition} from './components/fader';
2525
export {default as Modal, ModalProps, ModalTopBarProps} from './components/modal';
26+
export {default as PanGestureView, PanGestureViewProps} from './components/panningViews/panGestureView';
2627
export {default as PanningContext} from './components/panningViews/panningContext';
2728
export {default as asPanViewConsumer} from './components/panningViews/asPanViewConsumer';
2829
export {
2930
default as PanningProvider,
3031
PanningDirections,
3132
PanLocationProps,
3233
PanAmountsProps,
33-
PanDirectionsProps
34+
PanDirectionsProps,
35+
PanningProviderDirection
3436
} from './components/panningViews/panningProvider';
3537
export {default as PanListenerView, PanListenerViewPropTypes} from './components/panningViews/panListenerView';
3638
export {default as PanResponderView, PanResponderViewPropTypes} from './components/panningViews/panResponderView';

0 commit comments

Comments
 (0)