Skip to content

Commit a4413a3

Browse files
committed
fix: flow error
1 parent 4666359 commit a4413a3

File tree

9 files changed

+43
-20
lines changed

9 files changed

+43
-20
lines changed

.flowconfig

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[version]
2+
^0.237.2
3+
14
[ignore]
25
; We fork some components by platform
36
.*/*[.]android.js
@@ -20,21 +23,24 @@ node_modules/warning/.*
2023
; Ignore test files in resolve
2124
.*/node_modules/resolve/test/.*
2225

26+
; Ignore fbjs flow weak mode
27+
.*/node_modules/fbjs/lib/.*
28+
2329
[untyped]
2430
.*/node_modules/@react-native-community/cli/.*/.*
31+
.*/node_modules/fbjs/.*
2532

2633
[include]
2734

2835
[libs]
2936
node_modules/react-native/interface.js
3037
node_modules/react-native/flow/
38+
flow-typed/
3139

3240
[options]
3341
server.max_workers=4
3442
emoji=true
3543

36-
esproposal.optional_chaining=enable
37-
esproposal.nullish_coalescing=enable
3844

3945
module.file_ext=.js
4046
module.file_ext=.json
@@ -49,9 +55,12 @@ suppress_type=$FlowIssue
4955
suppress_type=$FlowFixMe
5056
suppress_type=$FlowFixMeProps
5157
suppress_type=$FlowFixMeState
58+
suppress_type=$FlowFixMeEmpty
59+
60+
; Errors from built-in Flow library definitions
61+
exact_by_default=false
62+
5263

53-
well_formed_exports=true
54-
experimental.abstract_locations=true
5564

5665
sharedmemory.heap_size=4000000000
5766

@@ -64,8 +73,6 @@ nonstrict-import=warn
6473
deprecated-type=warn
6574
unsafe-getters-setters=warn
6675
unnecessary-invariant=warn
67-
signature-verification-failure=warn
68-
deprecated-utility=error
6976

7077
[strict]
7178
deprecated-type

flow-typed/globals.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @flow
2+
// Global type definitions to suppress Flow library errors
3+
4+
// Declare global types that are causing issues in Flow's built-in libraries
5+
declare class Headers {}
6+
declare class Request {}
7+
declare class Response {}

js/SegmentedControl.ios.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ type Props = $ReadOnly<{|
4343
*/
4444

4545
class SegmentedControlIOS extends React.Component<Props> {
46-
static defaultProps = {
46+
static defaultProps: {|
47+
values: $ReadOnlyArray<string | number>,
48+
enabled: boolean,
49+
|} = {
4750
values: [],
4851
enabled: true,
4952
};
@@ -54,7 +57,7 @@ class SegmentedControlIOS extends React.Component<Props> {
5457
this.props.onValueChange(event.nativeEvent.value);
5558
};
5659

57-
render() {
60+
render(): React.Node {
5861
const {forwardedRef, fontStyle, activeFontStyle, values, ...props} =
5962
this.props;
6063
return (

js/SegmentedControl.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const SegmentedControl = ({
4444
const colorScheme = appearance || colorSchemeHook;
4545
const [segmentWidth, setSegmentWidth] = React.useState(0);
4646
const animation = React.useRef(new Animated.Value(0)).current;
47-
const ref = React.useRef();
47+
const ref = React.useRef<?React.ElementRef<typeof View>>(null);
4848

4949
const handleChange = (index: number) => {
5050
// mocks iOS's nativeEvent
@@ -75,15 +75,17 @@ const SegmentedControl = ({
7575
Animated.timing(animation, {
7676
toValue: isRTL * (selectedIndex || 0),
7777
duration: 300,
78-
easing: Easing.out(Easing.quad),
78+
easing: Easing.out(Easing.quad.bind(Easing)),
7979
useNativeDriver: true,
8080
}).start();
8181
}
8282
}, [animation, segmentWidth, selectedIndex]);
8383

8484
React.useEffect(() => {
8585
if (ref.current) {
86-
ref.current.measure((_x, _y, width) => updateSegmentWidth(width));
86+
ref.current.measure((_x: number, _y: number, width: number) =>
87+
updateSegmentWidth(width),
88+
);
8789
}
8890
}, [values, updateSegmentWidth]);
8991

js/SegmentedControlTab.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ type Props = $ReadOnly<{|
3232
testID?: string,
3333
|}>;
3434

35-
function isBase64(str) {
35+
function isBase64(str: mixed): boolean {
3636
const regex =
3737
/^data:image\/(?:gif|png|jpeg|bmp|webp)(?:;charset=utf-8)?;base64,(?:[A-Za-z0-9]|[+/])+={0,2}/;
38-
return str && regex.test(str);
38+
return typeof str === 'string' && regex.test(str);
3939
}
4040

4141
export const SegmentedControlTab = ({

js/SegmentsSeparators.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const SegmentsSeparators = ({
1818
selectedIndex,
1919
}: Props): React.Node => {
2020
const colorScheme = useColorScheme();
21-
const hide = (val) => {
21+
const hide = (val: number) => {
2222
return selectedIndex === val || selectedIndex === val + 1;
2323
};
2424

js/types.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,8 @@ export type SegmentedControlProps = $ReadOnly<{|
116116
* Style properties for the slider component (Animated.View)
117117
*/
118118
sliderStyle?: ViewStyle,
119+
/**
120+
* Accessibility hint separator text
121+
*/
122+
accessibilityHintSeperator?: string,
119123
|}>;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"eslint-plugin-ft-flow": "^3.0.11",
4141
"eslint-plugin-prettier": "^5.0.0",
4242
"expo": "^46.0.16",
43-
"flow-bin": "^0.142.0",
43+
"flow-bin": "^0.237.2",
4444
"husky": "^8.0.1",
4545
"jest": "^29.2.1",
4646
"metro-react-native-babel-preset": "0.77.0",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)