Skip to content

Commit

Permalink
fix: update flow version (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
Naturalclar authored Nov 28, 2023
1 parent 16d693e commit 5719c0e
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 30 deletions.
5 changes: 1 addition & 4 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ suppress_type=$FlowFixMeState

server.max_workers=2

experimental.abstract_locations=true

[lints]
sketchy-null-number=warn
sketchy-null-mixed=warn
Expand All @@ -71,7 +69,6 @@ nonstrict-import=warn
deprecated-type=warn
unsafe-getters-setters=warn
unnecessary-invariant=warn
signature-verification-failure=warn

[strict]
deprecated-type
Expand All @@ -83,4 +80,4 @@ untyped-import
untyped-type-import

[version]
^0.170.0
^0.222.0
1 change: 1 addition & 0 deletions js/AndroidDropdownPickerNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTyp
import type {HostComponent} from 'react-native/Libraries/Renderer/shims/ReactNativeTypes';
import type {
BubblingEventHandler,
Double,
Int32,
} from 'react-native/Libraries/Types/CodegenTypes';

Expand Down
2 changes: 1 addition & 1 deletion js/Picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type PickerItemProps = $ReadOnly<{|
* Individual selectable item in a Picker.
*/
class PickerItem extends React.Component<PickerItemProps> {
render() {
render(): React.Node {
// The items are not rendered directly
throw null;
}
Expand Down
4 changes: 2 additions & 2 deletions js/Picker.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type PickerProps = {
prompt?: string,
};

const Select = forwardRef((props: any, forwardedRef) =>
const Select = forwardRef((props: $FlowFixMe, forwardedRef: $FlowFixMe) =>
unstable_createElement('select', {
...props,
ref: forwardedRef,
Expand All @@ -39,7 +39,7 @@ const Select = forwardRef((props: any, forwardedRef) =>

const Picker: React$AbstractComponent<PickerProps, empty> = forwardRef<
PickerProps,
*,
$FlowFixMe,
>((props, forwardedRef) => {
const {
enabled,
Expand Down
42 changes: 26 additions & 16 deletions js/PickerIOS.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Label = Stringish | number;

type Props = $ReadOnly<{|
...ViewProps,
// $FlowFixMe
children: ChildrenArray<Element<typeof PickerIOSItem>>,
itemStyle?: ?TextStyleProp,
numberOfLines: ?number,
Expand Down Expand Up @@ -92,6 +93,7 @@ function useMergeRefs<T>(...refs: $ReadOnlyArray<?Ref<T>>): CallbackRef<T> {
);
}

// $FlowFixMe
const PickerIOSItem: RNCPickerIOSItemType = (props: ItemProps): null => {
return null;
};
Expand All @@ -117,6 +119,7 @@ const PickerIOSWithForwardedRef: React.AbstractComponent<
typeof RNCPickerNativeComponent,
> | null>(null);

// $FlowFixMe
const ref = useMergeRefs(nativePickerRef, forwardedRef);

const [nativeSelectedIndex, setNativeSelectedIndex] = React.useState({
Expand All @@ -127,20 +130,22 @@ const PickerIOSWithForwardedRef: React.AbstractComponent<
// eslint-disable-next-line no-shadow
let selectedIndex = 0;
// eslint-disable-next-line no-shadow
const items = React.Children.toArray(children).map((child, index) => {
if (child === null) {
return null;
}
if (String(child.props.value) === String(selectedValue)) {
selectedIndex = index;
}
return {
value: String(child.props.value),
label: String(child.props.label),
textColor: processColor(child.props.color),
testID: child.props.testID,
};
});
const items = React.Children.toArray<$FlowFixMe>(children).map(
(child, index) => {
if (child === null) {
return null;
}
if (String(child.props.value) === String(selectedValue)) {
selectedIndex = index;
}
return {
value: String(child.props.value),
label: String(child.props.label),
textColor: processColor(child.props.color),
testID: child.props.testID,
};
},
);
return [items, selectedIndex];
}, [children, selectedValue]);

Expand All @@ -151,7 +156,10 @@ const PickerIOSWithForwardedRef: React.AbstractComponent<

React.useLayoutEffect(() => {
let jsValue = 0;
React.Children.toArray(children).forEach(function (child, index) {
React.Children.toArray<$FlowFixMe>(children).forEach(function (
child: $FlowFixMe,
index: number,
) {
if (String(child.props.value) === String(selectedValue)) {
jsValue = index;
}
Expand All @@ -177,7 +185,7 @@ const PickerIOSWithForwardedRef: React.AbstractComponent<
}, [selectedValue, nativeSelectedIndex, children]);

const _onChange = React.useCallback(
(event) => {
(event: $FlowFixMe) => {
onChange?.(event);
onValueChange?.(event.nativeEvent.newValue, event.nativeEvent.newIndex);
setNativeSelectedIndex({value: event.nativeEvent.newIndex});
Expand All @@ -192,6 +200,7 @@ const PickerIOSWithForwardedRef: React.AbstractComponent<
themeVariant={themeVariant}
testID={testID}
style={[styles.pickerIOS, itemStyle]}
// $FlowFixMe
items={items}
onChange={_onChange}
numberOfLines={parsedNumberOfLines}
Expand All @@ -211,6 +220,7 @@ const styles = StyleSheet.create({
},
});

// $FlowFixMe
PickerIOSWithForwardedRef.Item = PickerIOSItem;

export default PickerIOSWithForwardedRef;
9 changes: 7 additions & 2 deletions js/PickerMacOS.macos.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Label = Stringish | number;

type Props = $ReadOnly<{|
...ViewProps,
// $FlowFixMe
children: ChildrenArray<Element<typeof PickerMacOSItem>>,
itemStyle?: ?TextStyleProp,
onChange?: ?(event: PickerMacOSChangeEvent) => mixed,
Expand Down Expand Up @@ -89,7 +90,10 @@ class PickerMacOS extends React.Component<Props, State> {
static getDerivedStateFromProps(props: Props): State {
let selectedIndex = 0;
const items = [];
React.Children.toArray(props.children).forEach(function (child, index) {
React.Children.toArray<$FlowFixMe>(props.children).forEach(function (
child: $FlowFixMe,
index: number,
) {
if (child.props.value === props.selectedValue) {
selectedIndex = index;
}
Expand All @@ -112,6 +116,7 @@ class PickerMacOS extends React.Component<Props, State> {
}}
testID={this.props.testID}
style={[styles.pickerMacOS, this.props.itemStyle]}
// $FlowFixMe
items={this.state.items}
selectedIndex={this.state.selectedIndex}
onChange={this._onChange}
Expand All @@ -120,7 +125,7 @@ class PickerMacOS extends React.Component<Props, State> {
);
}

_onChange = (event) => {
_onChange = (event: $FlowFixMe) => {
if (this.props.onChange) {
this.props.onChange(event);
}
Expand Down
1 change: 1 addition & 0 deletions js/RNCPickerNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
BubblingEventHandler,
Int32,
} from 'react-native/Libraries/Types/CodegenTypes';
import type {ProcessedColorValue} from 'react-native/Libraries/StyleSheet/processColor';

import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"eslint": "^7.32.0",
"eslint-plugin-prettier": "^3.0.1",
"expo": "^41.0.1",
"flow-bin": "0.170.0",
"flow-bin": "0.222.0",
"husky": "^2.2.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.67.0",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8287,10 +8287,10 @@ flatted@^3.1.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.1.1.tgz#c4b489e80096d9df1dfc97c79871aea7c617c469"
integrity sha512-zAoAQiudy+r5SvnSw3KJy5os/oRJYHzrzja/tBDqrZtNhUw8bt6y8OBzMWcjWr+8liV8Eb6yOhw8WZ7VFZ5ZzA==

flow-bin@0.170.0:
version "0.170.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.170.0.tgz#1da264de9868cc20a338f801bedc370e3e06f5cc"
integrity sha512-h4qy4f5loKdeLhj7TRM6XQWhmPpnfjDcOg6GPDuJnLAQuB60LJIHZ8QL3hxMf0oA++NkiYx62Vr8oHu+UZ2bGQ==
flow-bin@0.222.0:
version "0.222.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.222.0.tgz#b4ca588c77fbd79db1edf38615cd04d114c1e933"
integrity sha512-U2047+pOX1EutHGykcjtamAlP8UIHrxbkexB5zPVQ8PH+WcVmD4PtRE6J8Jc3S6odyo0AqVnQsI4rE/2x2fGmQ==

flow-parser@0.*:
version "0.154.0"
Expand Down

0 comments on commit 5719c0e

Please sign in to comment.