mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Remove 6 $FlowFixMe[sketchy-null-*] suppressions (Button, URL, ScrollView, RNTester) (#59211)
Summary: Pull Request resolved: https://github.com/react/react-native/pull/59211 Replaces six `$FlowFixMe[sketchy-null-string|bool|number]` suppressions with explicit checks that keep the exact runtime behavior, including for `''`, `0` and `NaN`. - `Button`: `ariaLabel || accessibilityLabel` became `ariaLabel != null && ariaLabel !== '' ? ariaLabel : accessibilityLabel`, so an empty `aria-label` still falls back to `accessibilityLabel`. - `URL`: in the constructor, `!base` became `base == null || base === ''`. A `URL` instance is always truthy, so this matches the old check. - `ScrollView` (2): `keyboardShouldPersistTaps` is typed `?('always' | 'never' | 'handled')`, whose values are never falsy. So `!keyboardShouldPersistTaps` is the same as `keyboardShouldPersistTaps == null`. - RNTester `PressableExample`: `setForce(event.nativeEvent?.force || 1)` became `touchForce != null && Boolean(touchForce) ? touchForce : 1`, reading the value into a local const. `Boolean()` keeps the `0`/`NaN` fallback exactly as `||` did, and `!= null` lets Flow refine the value to `number`. - RNTester `useJsStalls`: `!state.stallIntervalId` became `!Boolean(state.stallIntervalId)`. The interval ID is an opaque `IntervalID` in the OSS Flow libdefs, so it can't be compared with `0`; `Boolean()` keeps the exact semantics. No new suppressions, casts, comments, or tests. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D126162944 fbshipit-source-id: d0402e37351005d364a45c90d3bb086953179242
This commit is contained in:
1 parent
2fd8fd664c
commit
a64b21b1a0
5 files changed
+13
-12
No files matched your search
+1
-2
@@ -81,8 +81,7 @@ export class URL {
|
||||
// $FlowFixMe[missing-local-annot]
|
||||
constructor(url: string, base?: string | URL) {
|
||||
let baseUrl = null;
|
||||
// $FlowFixMe[sketchy-null-string]
|
||||
if (!base || validateBaseUrl(url)) {
|
||||
if (base == null || base === '' || validateBaseUrl(url)) {
|
||||
this._url = url;
|
||||
if (this._url.includes('#')) {
|
||||
const split = this._url.split('#');
|
||||
|
||||
+1
-2
@@ -271,8 +271,7 @@ const Button: component(
|
||||
accessibilityActions={accessibilityActions}
|
||||
onAccessibilityAction={onAccessibilityAction}
|
||||
accessibilityLabel={
|
||||
// $FlowFixMe[sketchy-null-string]
|
||||
ariaLabel || accessibilityLabel
|
||||
ariaLabel != null && ariaLabel !== '' ? ariaLabel : accessibilityLabel
|
||||
}
|
||||
accessibilityHint={accessibilityHint}
|
||||
accessibilityLanguage={accessibilityLanguage}
|
||||
|
||||
@@ -1586,8 +1586,8 @@ class ScrollView extends React.Component<ScrollViewProps, ScrollViewState> {
|
||||
// then the second tap goes to the actual interior view)
|
||||
const {keyboardShouldPersistTaps} = this.props;
|
||||
const keyboardNeverPersistTaps =
|
||||
// $FlowFixMe[sketchy-null-bool]
|
||||
!keyboardShouldPersistTaps || keyboardShouldPersistTaps === 'never';
|
||||
keyboardShouldPersistTaps == null ||
|
||||
keyboardShouldPersistTaps === 'never';
|
||||
|
||||
if (typeof e.target === 'number') {
|
||||
if (__DEV__) {
|
||||
@@ -1669,8 +1669,8 @@ class ScrollView extends React.Component<ScrollViewProps, ScrollViewState> {
|
||||
|
||||
const {keyboardShouldPersistTaps} = this.props;
|
||||
const keyboardNeverPersistsTaps =
|
||||
// $FlowFixMe[sketchy-null-bool]
|
||||
!keyboardShouldPersistTaps || keyboardShouldPersistTaps === 'never';
|
||||
keyboardShouldPersistTaps == null ||
|
||||
keyboardShouldPersistTaps === 'never';
|
||||
|
||||
// Dismiss the keyboard now if we didn't become responder in capture phase
|
||||
// to eat presses, but still want to dismiss on interaction.
|
||||
|
||||
@@ -191,8 +191,12 @@ function ForceTouchExample() {
|
||||
style={styles.wrapper}
|
||||
testID="pressable_3dtouch_button"
|
||||
onStartShouldSetResponder={() => true}
|
||||
// $FlowFixMe[sketchy-null-number]
|
||||
onResponderMove={event => setForce(event.nativeEvent?.force || 1)}
|
||||
onResponderMove={event => {
|
||||
const touchForce = event.nativeEvent?.force;
|
||||
setForce(
|
||||
touchForce != null && Boolean(touchForce) ? touchForce : 1,
|
||||
);
|
||||
}}
|
||||
onResponderRelease={event => setForce(0)}>
|
||||
<Text style={styles.button}>Press Me</Text>
|
||||
</View>
|
||||
|
||||
@@ -67,8 +67,7 @@ const useJsStalls = (): ({
|
||||
onStall: ({busyTime}) =>
|
||||
setStallsState(state => {
|
||||
// If previous interval was cleared
|
||||
// $FlowFixMe[sketchy-null-number]
|
||||
if (!state.stallIntervalId) {
|
||||
if (!Boolean(state.stallIntervalId)) {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user