Skip to content

Commit

Permalink
Add explicit React useState annotations in xplat/js
Browse files Browse the repository at this point in the history
Reviewed By: SamChou19815

Differential Revision: D39756144

fbshipit-source-id: d34c86b62e82e771723714fb7896058b7f27670f
  • Loading branch information
pieterv authored and facebook-github-bot committed Sep 23, 2022
1 parent c557f25 commit ff14ff3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
15 changes: 9 additions & 6 deletions Libraries/Inspector/DevtoolsOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
* @flow
*/

import ElementBox from './ElementBox';
import * as React from 'react';
import type {PressEvent} from '../Types/CoreEventTypes';
import type {HostRef} from './getInspectorDataForViewAtPoint';

import View from '../Components/View/View';
import StyleSheet from '../StyleSheet/StyleSheet';
import Dimensions from '../Utilities/Dimensions';
const getInspectorDataForViewAtPoint = require('./getInspectorDataForViewAtPoint');
const {findNodeHandle} = require('../ReactNative/RendererProxy');
import ElementBox from './ElementBox';
import * as React from 'react';

import type {HostRef} from './getInspectorDataForViewAtPoint';
const {findNodeHandle} = require('../ReactNative/RendererProxy');
const getInspectorDataForViewAtPoint = require('./getInspectorDataForViewAtPoint');

const {useEffect, useState, useCallback, useRef} = React;

Expand All @@ -28,7 +29,9 @@ export default function DevtoolsOverlay({
}: {
inspectedView: ?HostRef,
}): React.Node {
const [inspected, setInspected] = useState(null);
const [inspected, setInspected] = useState<null | {
frame: {height: any, left: any, top: any, width: any},
}>(null);
const [isInspecting, setIsInspecting] = useState(false);
const devToolsAgentRef = useRef(null);

Expand Down
8 changes: 4 additions & 4 deletions packages/rn-tester/js/examples/Pressable/PressableExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

import * as React from 'react';
import {
Alert,
Animated,
Image,
Platform,
Pressable,
StyleSheet,
Text,
Platform,
View,
Alert,
} from 'react-native';
import ReactNativeFeatureFlags from 'react-native/Libraries/ReactNative/ReactNativeFeatureFlags';

Expand Down Expand Up @@ -101,7 +101,7 @@ function PressableAriaLabel() {
);
}
function PressableFeedbackEvents() {
const [eventLog, setEventLog] = useState([]);
const [eventLog, setEventLog] = useState<Array<string>>([]);

function appendEvent(eventName: string) {
const limit = 6;
Expand Down Expand Up @@ -137,7 +137,7 @@ function PressableFeedbackEvents() {
}

function PressableDelayEvents() {
const [eventLog, setEventLog] = useState([]);
const [eventLog, setEventLog] = useState<Array<string>>([]);

function appendEvent(eventName: string) {
const limit = 6;
Expand Down
38 changes: 24 additions & 14 deletions packages/rn-tester/js/examples/ScrollView/ScrollViewExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,24 @@
* @format
*/

import * as React from 'react';
import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';

import ScrollViewPressableStickyHeaderExample from './ScrollViewPressableStickyHeaderExample';
import nullthrows from 'nullthrows';
import * as React from 'react';
import {useCallback, useState} from 'react';
import {
Platform,
RefreshControl,
ScrollView,
StyleSheet,
Text,
TextInput,
TouchableOpacity,
View,
TextInput,
RefreshControl,
} from 'react-native';

import nullthrows from 'nullthrows';

import {useState, useCallback} from 'react';
import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';
import ScrollViewPressableStickyHeaderExample from './ScrollViewPressableStickyHeaderExample';

class EnableDisableList extends React.Component<{}, {scrollEnabled: boolean}> {
state: {scrollEnabled: boolean} = {
scrollEnabled: true,
Expand Down Expand Up @@ -570,7 +568,7 @@ const SnapToOptions = () => {
const snapToAlignmentModes = ['start', 'center', 'end'];
const [snapToEnd, setSnapToEnd] = useState(true);
const [snapToInterval, setSnapToInterval] = useState(0);
const [snapToOffsets, setSnapToOffsets] = useState([]);
const [snapToOffsets, setSnapToOffsets] = useState<Array<number>>([]);
const [snapToStart, setSnapToStart] = useState(true);

return (
Expand Down Expand Up @@ -655,7 +653,12 @@ const ScrollToOptions = () => {
};

const ScrollIndicatorExample = () => {
const [scrollIndicatorInsets, setScrollIndicatorInsets] = useState(null);
const [scrollIndicatorInsets, setScrollIndicatorInsets] = useState<null | {
bottom: number,
left: number,
right: number,
top: number,
}>(null);
const [showsHorizontalScrollIndic, setShowsHorizontalScrollIndic] =
useState(true);
const [showsVerticalScrollIndic, setShowsVerticalScrollIndic] =
Expand Down Expand Up @@ -1101,8 +1104,15 @@ const DecelerationRateExample = () => {

const ContentExample = () => {
const [canCancelContentTouches, setCanCancelContentTouches] = useState(false);
const [contentInset, setContentInset] = useState(null);
const [contentContainerStyle, setContentContainerStyle] = useState(null);
const [contentInset, setContentInset] = useState<null | {
bottom: number,
left: number,
right: number,
top: number,
}>(null);
const [contentContainerStyle, setContentContainerStyle] = useState<null | {
backgroundColor: string,
}>(null);
const [contentInsetAdjustmentBehavior, setContentInsetAdjustmentBehavior] =
useState('never');
return (
Expand Down

0 comments on commit ff14ff3

Please sign in to comment.