add types for react-native-swiper, fix types for react-navigation (#16552)

* add missing types which lists in the docs but not in the propTypes of src

* fix types in react-navigation

* fix `Definitions by`

* Update index.d.ts

* Update index.d.ts

* stash

* fix `Definitions by`

* add test for react-native-swiper
This commit is contained in:
Downpooooour
2017-06-01 13:15:00 +08:00
committed by Mohamed Hegazy
parent f7ef6b01f6
commit a8dca3c8f5
3 changed files with 111 additions and 7 deletions

View File

@@ -1,14 +1,33 @@
// Type definitions for react-native-swiper 1.5
// Project: https://github.com/leecade/react-native-swiper#readme
// Definitions by: CaiHuan <https://github.com/CaiHuan>, HuHuanming <https://github.com/huhuanming>
// Definitions by: CaiHuan <https://github.com/CaiHuan>
// HuHuanming <https://github.com/huhuanming>
// mhcgrq <https://github.com/mhcgrq>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
import * as React from 'react';
import {
ViewStyle
ViewStyle,
NativeSyntheticEvent,
NativeScrollEvent,
} from 'react-native';
export interface SwiperState {
autoplayEnd: boolean;
dir: 'x' | 'y';
height: number;
width: number;
index: number;
isScrolling: boolean;
loopJump: boolean;
offset: {
x: number;
y: number;
};
total: number;
}
export interface SwiperProperties extends React.Props<Swiper> {
horizontal?: boolean;
@@ -24,6 +43,8 @@ export interface SwiperProperties extends React.Props<Swiper> {
scrollsToTop?: boolean;
scrollEnabled?: boolean;
removeClippedSubviews?: boolean;
automaticallyAdjustContentInsets?: boolean;
@@ -54,6 +75,10 @@ export interface SwiperProperties extends React.Props<Swiper> {
activeDotStyle?: ViewStyle;
activeDot?: JSX.Element;
dot?: JSX.Element;
dotColor?: string;
activeDotColor?: string;
@@ -63,7 +88,50 @@ export interface SwiperProperties extends React.Props<Swiper> {
width?: number;
paginationStyle?: ViewStyle;
buttonWrapperStyle?: ViewStyle;
nextButton?: JSX.Element;
prevButton?: JSX.Element;
onScrollBeginDrag?(
event: NativeSyntheticEvent<NativeScrollEvent>,
state: SwiperState,
context: Swiper
): void;
onMomentumScrollEnd?(
event: NativeSyntheticEvent<NativeScrollEvent>,
state: SwiperState,
context: Swiper
): void;
onTouchStartCapture?(
event: NativeSyntheticEvent<NativeScrollEvent>,
state: SwiperState,
context: Swiper
): void;
onTouchStart?(
event: NativeSyntheticEvent<NativeScrollEvent>,
state: SwiperState,
context: Swiper
): void;
onTouchEnd?(
event: NativeSyntheticEvent<NativeScrollEvent>,
state: SwiperState,
context: Swiper
): void;
onResponderRelease?(
event: NativeSyntheticEvent<NativeScrollEvent>,
state: SwiperState,
context: Swiper
): void;
}
export default class Swiper extends React.Component<SwiperProperties, {}> {
export default class Swiper extends React.Component<SwiperProperties, SwiperState> {
scrollBy(index: number, animated: boolean): void;
}

View File

@@ -3,18 +3,54 @@ import {
StyleSheet,
Text,
View,
ViewStyle
ViewStyle,
NativeSyntheticEvent,
NativeScrollEvent
} from 'react-native';
import Swiper from 'react-native-swiper';
import Swiper, { SwiperState } from 'react-native-swiper';
class SwiperTest extends React.Component<{}, {}> {
constructor(props: {}) {
super(props);
}
callback = (
event: NativeSyntheticEvent<NativeScrollEvent>,
state: SwiperState,
context: Swiper
) => {
console.log(this.callback.name, event, state, context);
}
render(): React.ReactElement<any> {
return (
<Swiper
horizontal
pagingEnabled
showsHorizontalScrollIndicator
showsVerticalScrollIndicator
bounces
scrollsToTop
scrollEnabled
removeClippedSubviews
automaticallyAdjustContentInsets
showsPagination
showsButtons
loadMinimal
loadMinimalSize={1}
loop
autoplay
autoplayTimeout={300}
autoplayDirection
renderPagination={() => (<View />)}
height={100}
width={200}
nextButton={<View><Text>NEXT</Text></View>}
prevButton={<View><Text>PREV</Text></View>}
onScrollBeginDrag={this.callback}
onMomentumScrollEnd={this.callback}
onTouchStartCapture={this.callback}
onTouchStart={this.callback}
onTouchEnd={this.callback}
onResponderRelease={this.callback}
style={styles.wrapper}>
<View
style={styles.slide1}>

View File

@@ -490,7 +490,7 @@ interface NavigationContainerState {
export interface NavigationContainer extends React.ComponentClass<
NavigationContainerProps
> {
router: any
router: NavigationRouter
}
export type StackNavigatorConfig =