From 9e9bbefada450630f7a5c42fc4216fdd2f071bf4 Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Sat, 22 Sep 2018 12:49:14 +0200 Subject: [PATCH] Changed react-native event handler types --- types/react-native/index.d.ts | 15 ++++++++------- types/react-native/test/index.tsx | 28 ++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index f4471fe681..f6b5efe4a5 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -13,6 +13,7 @@ // Tanguy Krotoff // Alexander T. // Martin van Dam +// Kacper Wiszczuk // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -4810,7 +4811,7 @@ export interface ModalPropsIOS { * The `onOrientationChange` callback is called when the orientation changes while the modal is being displayed. * The orientation provided is only 'portrait' or 'landscape'. This callback is also called on initial render, regardless of the current orientation. */ - onOrientationChange?: (event?: NativeSyntheticEvent) => void; + onOrientationChange?: (event: NativeSyntheticEvent) => void; } export interface ModalPropsAndroid { @@ -6301,27 +6302,27 @@ export interface ScrollViewProps * Fires at most once per frame during scrolling. * The frequency of the events can be contolled using the scrollEventThrottle prop. */ - onScroll?: (event?: NativeSyntheticEvent) => void; + onScroll?: (event: NativeSyntheticEvent) => void; /** * Fires if a user initiates a scroll gesture. */ - onScrollBeginDrag?: (event?: NativeSyntheticEvent) => void; + onScrollBeginDrag?: (event: NativeSyntheticEvent) => void; /** * Fires when a user has finished scrolling. */ - onScrollEndDrag?: (event?: NativeSyntheticEvent) => void; + onScrollEndDrag?: (event: NativeSyntheticEvent) => void; /** * Fires when scroll view has finished moving */ - onMomentumScrollEnd?: (event?: NativeSyntheticEvent) => void; + onMomentumScrollEnd?: (event: NativeSyntheticEvent) => void; /** * Fires when scroll view has begun moving */ - onMomentumScrollBegin?: (event?: NativeSyntheticEvent) => void; + onMomentumScrollBegin?: (event: NativeSyntheticEvent) => void; /** * When true the scroll view stops on multiples of the scroll view's size @@ -8484,7 +8485,7 @@ export namespace Animated { type Mapping = { [key: string]: Mapping } | AnimatedValue; interface EventConfig { - listener?: (event?: NativeSyntheticEvent) => void; + listener?: (event: NativeSyntheticEvent) => void; useNativeDriver?: boolean; } diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index c9696e53d0..85d3285329 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -63,6 +63,7 @@ import { InputAccessoryView, StatusBar, NativeSyntheticEvent, + NativeScrollEvent, GestureResponderEvent, TextInputScrollEventData, TextInputSelectionChangeEventData, @@ -388,7 +389,14 @@ export class CapsLockComponent extends React.Component { } } -class ScrollerListComponentTest extends React.Component<{}, { dataSource: ListViewDataSource }> { +class ScrollerListComponentTest extends React.Component< + {}, + { dataSource: ListViewDataSource } +> { + eventHandler = (event: NativeSyntheticEvent) => { + console.log(event); + }; + render() { const scrollViewStyle1 = StyleSheet.create({ scrollView: { @@ -406,11 +414,27 @@ class ScrollerListComponentTest extends React.Component<{}, { dataSource: ListVi throw new Error("Expected scroll to be enabled."); } - return ; + return ( + + ); }} renderRow={({ type, data }, _, row) => { return Filler; }} + onScroll={this.eventHandler} + onScrollBeginDrag={this.eventHandler} + onScrollEndDrag={this.eventHandler} + onMomentumScrollBegin={this.eventHandler} + onMomentumScrollEnd={this.eventHandler} /> ); }