Skip to content

Commit a2844f2

Browse files
excedfacebook-github-bot
authored andcommitted
Flow strict Slider (facebook#22127)
Summary: Related to facebook#22100 Turn on Flow strict mode for Slider. Enhanced event type and props callbacks type defs for Slider. - All flow tests succeed. [GENERAL] [ENHANCEMENT] [Slider.js] - Flow strict mode Pull Request resolved: facebook#22127 Differential Revision: D12946817 Pulled By: TheSavior fbshipit-source-id: 631391f70c04fddf0bfa6fec92f5cb769a555547
1 parent 592cb71 commit a2844f2

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Libraries/Components/Slider/Slider.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*
77
* @format
8-
* @flow
8+
* @flow strict-local
99
*/
1010

1111
'use strict';
@@ -21,10 +21,19 @@ import type {ImageSource} from 'ImageSource';
2121
import type {ViewStyleProp} from 'StyleSheet';
2222
import type {ColorValue} from 'StyleSheetTypes';
2323
import type {ViewProps} from 'ViewPropTypes';
24+
import type {SyntheticEvent} from 'CoreEventTypes';
2425

2526
const RCTSlider = requireNativeComponent('RCTSlider');
2627

27-
type Event = Object;
28+
type Event = SyntheticEvent<
29+
$ReadOnly<{|
30+
value: number,
31+
/**
32+
* Android Only.
33+
*/
34+
fromUser?: boolean,
35+
|}>,
36+
>;
2837

2938
type IOSProps = $ReadOnly<{|
3039
/**
@@ -118,14 +127,14 @@ type Props = $ReadOnly<{|
118127
/**
119128
* Callback continuously called while the user is dragging the slider.
120129
*/
121-
onValueChange?: ?Function,
130+
onValueChange?: ?(value: number) => void,
122131

123132
/**
124133
* Callback that is called when the user releases the slider,
125134
* regardless if the value has changed. The current value is passed
126135
* as an argument to the callback handler.
127136
*/
128-
onSlidingComplete?: ?Function,
137+
onSlidingComplete?: ?(value: number) => void,
129138

130139
/**
131140
* Used to locate this view in UI automation tests.
@@ -209,7 +218,8 @@ const Slider = (
209218
if (Platform.OS === 'android') {
210219
// On Android there's a special flag telling us the user is
211220
// dragging the slider.
212-
userEvent = event.nativeEvent.fromUser;
221+
userEvent =
222+
event.nativeEvent.fromUser != null && event.nativeEvent.fromUser;
213223
}
214224
props.onValueChange &&
215225
userEvent &&

0 commit comments

Comments
 (0)