Annotate `useCallback` in xplat (11/n)

Summary:
Add explicit annotations to useCallback as required for Flow's Local Type Inference project. This codemod prepares the codebase to match Flow's new typechecking algorithm. The new algorithm will make Flow more reliable and predictable.

Codemod command: `flow codemod annotate-use-callback`

drop-conflicts
bypass-lint

Changelog: [Internal]

Reviewed By: evanyeung

Differential Revision: D40079418

fbshipit-source-id: 59750a5d07b2ac1f440927794a7523682f048a5e
This commit is contained in:
Sam Zhou 2022-10-04 18:51:59 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 108c876206
Коммит b56d709e6e
7 изменённых файлов: 24 добавлений и 9 удалений

Просмотреть файл

@ -60,7 +60,7 @@ export default function useAnimatedProps<TProps: {...}, TInstance>(
// But there is no way to transparently compose three separate callback refs,
// so we just combine them all into one for now.
const refEffect = useCallback(
instance => {
(instance: TInstance) => {
// NOTE: This may be called more often than necessary (e.g. when `props`
// changes), but `setNativeView` already optimizes for that.
node.setNativeView(instance);

Просмотреть файл

@ -31,7 +31,7 @@ export default function useRefEffect<TInstance>(
): CallbackRef<TInstance | null> {
const cleanupRef = useRef<(() => void) | void>(undefined);
return useCallback(
instance => {
(instance: null | TInstance) => {
if (cleanupRef.current) {
cleanupRef.current();
cleanupRef.current = undefined;

Просмотреть файл

@ -111,7 +111,7 @@ const RNTesterApp = (): React.Node => {
);
const handleModuleExampleCardPress = React.useCallback(
exampleName => {
(exampleName: string) => {
dispatch({
type: RNTesterActionsType.EXAMPLE_CARD_PRESS,
data: {key: exampleName},
@ -131,7 +131,7 @@ const RNTesterApp = (): React.Node => {
);
const handleNavBarPress = React.useCallback(
args => {
(args: {screen: string}) => {
dispatch({
type: RNTesterActionsType.NAVBAR_PRESS,
data: {screen: args.screen},

Просмотреть файл

@ -68,7 +68,7 @@ function FilterModalButton(props: FilterModalProps) {
setModalVisible(false);
}, []);
const onPendingTextChange = useCallback(newText => {
const onPendingTextChange = useCallback((newText: string) => {
setPendingFilterText(newText);
}, []);

Просмотреть файл

@ -106,7 +106,7 @@ function constructAsyncTestHook(
});
}, [description]);
const stepHandler = useCallback(testCase => {
const stepHandler = useCallback((testCase: PlatformTestCase) => {
const stepAssertions = runTestCase(testCase);
assertionsRef.current.push(...stepAssertions);
}, []);

Просмотреть файл

@ -16,6 +16,7 @@ import {FlatList, StyleSheet, Text, View} from 'react-native';
import RNTesterPage from '../../components/RNTesterPage';
import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
import type {ViewToken} from '../../../../../Libraries/Lists/ViewabilityHelper';
type OuterItem = 'head' | 'vertical' | 'horizontal' | 'filler';
@ -78,7 +79,13 @@ function NestedListExample(): React.Node {
const [inner, dispatchInner] = useReducer(reducer, initialItemsState);
const onViewableItemsChanged = useCallback(
({changed}) => {
({
changed,
}: {
changed: Array<ViewToken>,
viewableItems: Array<ViewToken>,
...
}) => {
for (const token of changed) {
dispatchOuter({
type: token.isViewable ? 'add-viewable' : 'remove-viewable',
@ -162,7 +169,13 @@ function OuterItemRenderer({
}, [dispatchOuter, index]);
const onViewableItemsChanged = useCallback(
({changed}) => {
({
changed,
}: {
changed: Array<ViewToken>,
viewableItems: Array<ViewToken>,
...
}) => {
for (const token of changed) {
dispatchInner({
type: token.isViewable ? 'add-viewable' : 'remove-viewable',

Просмотреть файл

@ -9,7 +9,9 @@
*/
'use strict';
import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
import type {ViewToken} from '../../../../../Libraries/Lists/ViewabilityHelper';
import BaseFlatListExample from './BaseFlatListExample';
import {StyleSheet, View, FlatList} from 'react-native';
import * as React from 'react';
@ -32,7 +34,7 @@ export function FlatList_onViewableItemsChanged(props: {
const {viewabilityConfig, offScreen, horizontal, useScrollRefScroll} = props;
const [output, setOutput] = React.useState('');
const onViewableItemsChanged = React.useCallback(
info =>
(info: {changed: Array<ViewToken>, viewableItems: Array<ViewToken>, ...}) =>
setOutput(
info.viewableItems
.filter(viewToken => viewToken.index != null && viewToken.isViewable)