AndroidDropdownPicker and AndroidDialogPicker (#22999)

Summary:
Changelog:
----------

[Android] [Changed] - As mentioned in #22990, I have moved native components required by PickerAndroid.android.js into separate files and added Flow Typing.
Pull Request resolved: https://github.com/facebook/react-native/pull/22999

Differential Revision: D13697130

Pulled By: TheSavior

fbshipit-source-id: 42da73d82cca45fefa066871eed5a637811643c8
This commit is contained in:
jesse
2019-01-16 13:00:36 -08:00
committed by Facebook Github Bot
parent 35823ec416
commit 462cb10949
3 changed files with 99 additions and 5 deletions

View File

@@ -0,0 +1,47 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'use strict';
const requireNativeComponent = require('requireNativeComponent');
import type {SyntheticEvent} from 'CoreEventTypes';
import type {TextStyleProp} from 'StyleSheet';
import type {NativeComponent} from 'ReactNative';
type PickerAndroidChangeEvent = SyntheticEvent<
$ReadOnly<{|
position: number,
|}>,
>;
type Item = $ReadOnly<{|
label: string,
value: ?(number | string),
color?: ?number,
|}>;
type NativeProps = $ReadOnly<{|
enabled?: ?boolean,
items: $ReadOnlyArray<Item>,
mode?: ?('dialog' | 'dropdown'),
onSelect?: (event: PickerAndroidChangeEvent) => void,
selected: number,
prompt?: ?string,
testID?: string,
style?: ?TextStyleProp,
accessibilityLabel?: ?string,
|}>;
type DialogPickerNativeType = Class<NativeComponent<NativeProps>>;
module.exports = ((requireNativeComponent(
'AndroidDialogPicker',
): any): DialogPickerNativeType);

View File

@@ -0,0 +1,47 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'use strict';
const requireNativeComponent = require('requireNativeComponent');
import type {SyntheticEvent} from 'CoreEventTypes';
import type {TextStyleProp} from 'StyleSheet';
import type {NativeComponent} from 'ReactNative';
type PickerAndroidChangeEvent = SyntheticEvent<
$ReadOnly<{|
position: number,
|}>,
>;
type Item = $ReadOnly<{|
label: string,
value: ?(number | string),
color?: ?number,
|}>;
type NativeProps = $ReadOnly<{|
enabled?: ?boolean,
items: $ReadOnlyArray<Item>,
mode?: ?('dialog' | 'dropdown'),
onSelect?: (event: PickerAndroidChangeEvent) => void,
selected: number,
prompt?: ?string,
testID?: string,
style?: ?TextStyleProp,
accessibilityLabel?: ?string,
|}>;
type DropdownPickerNativeType = Class<NativeComponent<NativeProps>>;
module.exports = ((requireNativeComponent(
'AndroidDropdownPicker',
): any): DropdownPickerNativeType);

View File

@@ -10,14 +10,12 @@
'use strict';
const AndroidDropdownPickerNativeComponent = require('AndroidDropdownPickerNativeComponent');
const AndroidDialogPickerNativeComponent = require('AndroidDialogPickerNativeComponent');
const React = require('React');
const StyleSheet = require('StyleSheet');
const processColor = require('processColor');
const requireNativeComponent = require('requireNativeComponent');
const DropdownPicker = requireNativeComponent('AndroidDropdownPicker');
const DialogPicker = requireNativeComponent('AndroidDialogPicker');
const REF_PICKER = 'picker';
const MODE_DROPDOWN = 'dropdown';
@@ -103,7 +101,9 @@ class PickerAndroid extends React.Component<
render() {
const Picker =
this.props.mode === MODE_DROPDOWN ? DropdownPicker : DialogPicker;
this.props.mode === MODE_DROPDOWN
? AndroidDropdownPickerNativeComponent
: AndroidDialogPickerNativeComponent;
const nativeProps = {
enabled: this.props.enabled,