Merge pull request #29125 from Esemesek/master

[react-native ]Changed event handler types
This commit is contained in:
Eloy Durán 2018-09-22 19:15:46 +02:00 committed by GitHub
commit adf4e18eef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 9 deletions

View File

@ -13,6 +13,7 @@
// Tanguy Krotoff <https://github.com/tkrotoff>
// Alexander T. <https://github.com/a-tarasyuk>
// Martin van Dam <https://github.com/mvdam>
// Kacper Wiszczuk <https://github.com/esemesek>
// 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<any>) => void;
onOrientationChange?: (event: NativeSyntheticEvent<any>) => 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<NativeScrollEvent>) => void;
onScroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
/**
* Fires if a user initiates a scroll gesture.
*/
onScrollBeginDrag?: (event?: NativeSyntheticEvent<NativeScrollEvent>) => void;
onScrollBeginDrag?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
/**
* Fires when a user has finished scrolling.
*/
onScrollEndDrag?: (event?: NativeSyntheticEvent<NativeScrollEvent>) => void;
onScrollEndDrag?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
/**
* Fires when scroll view has finished moving
*/
onMomentumScrollEnd?: (event?: NativeSyntheticEvent<NativeScrollEvent>) => void;
onMomentumScrollEnd?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
/**
* Fires when scroll view has begun moving
*/
onMomentumScrollBegin?: (event?: NativeSyntheticEvent<NativeScrollEvent>) => void;
onMomentumScrollBegin?: (event: NativeSyntheticEvent<NativeScrollEvent>) => 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<T> {
listener?: (event?: NativeSyntheticEvent<T>) => void;
listener?: (event: NativeSyntheticEvent<T>) => void;
useNativeDriver?: boolean;
}

View File

@ -63,6 +63,7 @@ import {
InputAccessoryView,
StatusBar,
NativeSyntheticEvent,
NativeScrollEvent,
GestureResponderEvent,
TextInputScrollEventData,
TextInputSelectionChangeEventData,
@ -388,7 +389,14 @@ export class CapsLockComponent extends React.Component<TextProps> {
}
}
class ScrollerListComponentTest extends React.Component<{}, { dataSource: ListViewDataSource }> {
class ScrollerListComponentTest extends React.Component<
{},
{ dataSource: ListViewDataSource }
> {
eventHandler = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
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 <ScrollView horizontal={true} nestedScrollEnabled={true} contentOffset={{x: 0, y: 0}} {...props} style={[scrollViewStyle1.scrollView, scrollViewStyle2]} />;
return (
<ScrollView
horizontal={true}
nestedScrollEnabled={true}
contentOffset={{ x: 0, y: 0 }}
{...props}
style={[
scrollViewStyle1.scrollView,
scrollViewStyle2
]}
/>
);
}}
renderRow={({ type, data }, _, row) => {
return <Text>Filler</Text>;
}}
onScroll={this.eventHandler}
onScrollBeginDrag={this.eventHandler}
onScrollEndDrag={this.eventHandler}
onMomentumScrollBegin={this.eventHandler}
onMomentumScrollEnd={this.eventHandler}
/>
);
}