mirror of
https://github.com/status-im/react-native.git
synced 2025-02-23 22:58:19 +00:00
Summary: There were approximately 350 unused suppressions in xplat/js when checking with .flowconfig.android The flow team is partially responsible for this, since our release process hasn't changed since we added the flowconfig. In the diff beneath this one, I added the functionality necessary for us to not add any more unused suppressions. To test it, I made this diff. The steps were: 1. Start iOS server 2. Start android server 3. remove unused ios suppressions 4. remove unused android suppressions 5. add ios suppressions with site=react_native_ios_fb 6. add android suppressions with site=react_native_android_fb 7. remove unused ios suppressions. The ones that are unused are ones where an android comment was inserted as well, since the ios comment no longer is next to the error 8. add suppressions using ios flowconfig with site=react_native_fb 9. remove unused android suppressions. The unused ones are ones that were moved up when the cross-platform suppressions were inserted. I'm going to make this into a script to make sure we don't contribute anymore unused suppressions from our side. The controller you requested could not be found. nolint Reviewed By: TheSavior Differential Revision: D10053893 fbshipit-source-id: 7bee212062f8b2153c6ba906a30cf40df2224019
169 lines
5.4 KiB
JavaScript
169 lines
5.4 KiB
JavaScript
/**
|
|
* 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 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';
|
|
|
|
import type {SyntheticEvent} from 'CoreEventTypes';
|
|
import type {TextStyleProp} from 'StyleSheet';
|
|
|
|
type PickerAndroidChangeEvent = SyntheticEvent<
|
|
$ReadOnly<{|
|
|
position: number,
|
|
|}>,
|
|
>;
|
|
|
|
type PickerAndroidProps = $ReadOnly<{|
|
|
children?: React.Node,
|
|
style?: ?TextStyleProp,
|
|
selectedValue?: any,
|
|
enabled?: ?boolean,
|
|
mode?: ?('dialog' | 'dropdown'),
|
|
onValueChange?: ?(newValue: any, newIndex: number) => mixed,
|
|
prompt?: ?string,
|
|
testID?: string,
|
|
|}>;
|
|
|
|
/**
|
|
* Not exposed as a public API - use <Picker> instead.
|
|
*/
|
|
class PickerAndroid extends React.Component<PickerAndroidProps, *> {
|
|
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
|
|
* when making Flow check .android.js files. */
|
|
constructor(props, context) {
|
|
super(props, context);
|
|
const state = this._stateFromProps(props);
|
|
|
|
this.state = {
|
|
...state,
|
|
initialSelectedIndex: state.selectedIndex,
|
|
};
|
|
}
|
|
|
|
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
|
|
* when making Flow check .android.js files. */
|
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
this.setState(this._stateFromProps(nextProps));
|
|
}
|
|
|
|
// Translate prop and children into stuff that the native picker understands.
|
|
_stateFromProps = props => {
|
|
let selectedIndex = 0;
|
|
const items = React.Children.map(props.children, (child, index) => {
|
|
if (child.props.value === props.selectedValue) {
|
|
selectedIndex = index;
|
|
}
|
|
const childProps = {
|
|
value: child.props.value,
|
|
label: child.props.label,
|
|
};
|
|
if (child.props.color) {
|
|
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was
|
|
* found when making Flow check .android.js files. */
|
|
childProps.color = processColor(child.props.color);
|
|
}
|
|
return childProps;
|
|
});
|
|
return {selectedIndex, items};
|
|
};
|
|
|
|
render() {
|
|
const Picker =
|
|
this.props.mode === MODE_DROPDOWN ? DropdownPicker : DialogPicker;
|
|
|
|
const nativeProps = {
|
|
enabled: this.props.enabled,
|
|
items: this.state.items,
|
|
mode: this.props.mode,
|
|
onSelect: this._onChange,
|
|
prompt: this.props.prompt,
|
|
selected: this.state.initialSelectedIndex,
|
|
testID: this.props.testID,
|
|
style: [styles.pickerAndroid, this.props.style],
|
|
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
|
|
* when making Flow check .android.js files. */
|
|
accessibilityLabel: this.props.accessibilityLabel,
|
|
};
|
|
|
|
return <Picker ref={REF_PICKER} {...nativeProps} />;
|
|
}
|
|
|
|
_onChange = (event: PickerAndroidChangeEvent) => {
|
|
if (this.props.onValueChange) {
|
|
const position = event.nativeEvent.position;
|
|
if (position >= 0) {
|
|
const children = React.Children.toArray(this.props.children);
|
|
const value = children[position].props.value;
|
|
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was
|
|
* found when making Flow check .android.js files. */
|
|
this.props.onValueChange(value, position);
|
|
} else {
|
|
this.props.onValueChange(null, position);
|
|
}
|
|
}
|
|
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
|
|
* when making Flow check .android.js files. */
|
|
this._lastNativePosition = event.nativeEvent.position;
|
|
this.forceUpdate();
|
|
};
|
|
|
|
componentDidMount() {
|
|
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
|
|
* when making Flow check .android.js files. */
|
|
this._lastNativePosition = this.state.initialSelectedIndex;
|
|
}
|
|
|
|
componentDidUpdate() {
|
|
// The picker is a controlled component. This means we expect the
|
|
// on*Change handlers to be in charge of updating our
|
|
// `selectedValue` prop. That way they can also
|
|
// disallow/undo/mutate the selection of certain values. In other
|
|
// words, the embedder of this component should be the source of
|
|
// truth, not the native component.
|
|
if (
|
|
this.refs[REF_PICKER] &&
|
|
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
|
|
* when making Flow check .android.js files. */
|
|
this.state.selectedIndex !== this._lastNativePosition
|
|
) {
|
|
this.refs[REF_PICKER].setNativeProps({
|
|
selected: this.state.selectedIndex,
|
|
});
|
|
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
|
|
* when making Flow check .android.js files. */
|
|
this._lastNativePosition = this.state.selectedIndex;
|
|
}
|
|
}
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
pickerAndroid: {
|
|
// The picker will conform to whatever width is given, but we do
|
|
// have to set the component's height explicitly on the
|
|
// surrounding view to ensure it gets rendered.
|
|
// TODO would be better to export a native constant for this,
|
|
// like in iOS the RCTDatePickerManager.m
|
|
height: 50,
|
|
},
|
|
});
|
|
|
|
module.exports = PickerAndroid;
|