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
committed by Facebook GitHub Bot
parent 108c876206
commit b56d709e6e
7 changed files with 24 additions and 9 deletions
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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;
+2 -2
View File
@@ -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)