Skip to content

Commit 462cb10

Browse files
jessefacebook-github-bot
authored andcommitted
AndroidDropdownPicker and AndroidDialogPicker (facebook#22999)
Summary: Changelog: ---------- [Android] [Changed] - As mentioned in facebook#22990, I have moved native components required by PickerAndroid.android.js into separate files and added Flow Typing. Pull Request resolved: facebook#22999 Differential Revision: D13697130 Pulled By: TheSavior fbshipit-source-id: 42da73d82cca45fefa066871eed5a637811643c8
1 parent 35823ec commit 462cb10

File tree

3 files changed

+99
-5
lines changed

3 files changed

+99
-5
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
'use strict';
12+
13+
const requireNativeComponent = require('requireNativeComponent');
14+
15+
import type {SyntheticEvent} from 'CoreEventTypes';
16+
import type {TextStyleProp} from 'StyleSheet';
17+
import type {NativeComponent} from 'ReactNative';
18+
19+
type PickerAndroidChangeEvent = SyntheticEvent<
20+
$ReadOnly<{|
21+
position: number,
22+
|}>,
23+
>;
24+
25+
type Item = $ReadOnly<{|
26+
label: string,
27+
value: ?(number | string),
28+
color?: ?number,
29+
|}>;
30+
31+
type NativeProps = $ReadOnly<{|
32+
enabled?: ?boolean,
33+
items: $ReadOnlyArray<Item>,
34+
mode?: ?('dialog' | 'dropdown'),
35+
onSelect?: (event: PickerAndroidChangeEvent) => void,
36+
selected: number,
37+
prompt?: ?string,
38+
testID?: string,
39+
style?: ?TextStyleProp,
40+
accessibilityLabel?: ?string,
41+
|}>;
42+
43+
type DialogPickerNativeType = Class<NativeComponent<NativeProps>>;
44+
45+
module.exports = ((requireNativeComponent(
46+
'AndroidDialogPicker',
47+
): any): DialogPickerNativeType);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
'use strict';
12+
13+
const requireNativeComponent = require('requireNativeComponent');
14+
15+
import type {SyntheticEvent} from 'CoreEventTypes';
16+
import type {TextStyleProp} from 'StyleSheet';
17+
import type {NativeComponent} from 'ReactNative';
18+
19+
type PickerAndroidChangeEvent = SyntheticEvent<
20+
$ReadOnly<{|
21+
position: number,
22+
|}>,
23+
>;
24+
25+
type Item = $ReadOnly<{|
26+
label: string,
27+
value: ?(number | string),
28+
color?: ?number,
29+
|}>;
30+
31+
type NativeProps = $ReadOnly<{|
32+
enabled?: ?boolean,
33+
items: $ReadOnlyArray<Item>,
34+
mode?: ?('dialog' | 'dropdown'),
35+
onSelect?: (event: PickerAndroidChangeEvent) => void,
36+
selected: number,
37+
prompt?: ?string,
38+
testID?: string,
39+
style?: ?TextStyleProp,
40+
accessibilityLabel?: ?string,
41+
|}>;
42+
43+
type DropdownPickerNativeType = Class<NativeComponent<NativeProps>>;
44+
45+
module.exports = ((requireNativeComponent(
46+
'AndroidDropdownPicker',
47+
): any): DropdownPickerNativeType);

Libraries/Components/Picker/PickerAndroid.android.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010

1111
'use strict';
1212

13+
const AndroidDropdownPickerNativeComponent = require('AndroidDropdownPickerNativeComponent');
14+
const AndroidDialogPickerNativeComponent = require('AndroidDialogPickerNativeComponent');
1315
const React = require('React');
1416
const StyleSheet = require('StyleSheet');
1517

1618
const processColor = require('processColor');
17-
const requireNativeComponent = require('requireNativeComponent');
18-
19-
const DropdownPicker = requireNativeComponent('AndroidDropdownPicker');
20-
const DialogPicker = requireNativeComponent('AndroidDialogPicker');
2119

2220
const REF_PICKER = 'picker';
2321
const MODE_DROPDOWN = 'dropdown';
@@ -103,7 +101,9 @@ class PickerAndroid extends React.Component<
103101

104102
render() {
105103
const Picker =
106-
this.props.mode === MODE_DROPDOWN ? DropdownPicker : DialogPicker;
104+
this.props.mode === MODE_DROPDOWN
105+
? AndroidDropdownPickerNativeComponent
106+
: AndroidDialogPickerNativeComponent;
107107

108108
const nativeProps = {
109109
enabled: this.props.enabled,

0 commit comments

Comments
 (0)