Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 41 additions & 22 deletions packages/react-native/Libraries/Core/Timers/JSTimers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @deprecated
*/
Expand All @@ -29,13 +29,15 @@ export type JSTimerType =
| 'queueReactNativeMicrotask'
| 'requestIdleCallback';

type TimerFunc = (...args: Array<unknown>) => unknown;

// These timing constants should be kept in sync with the ones in native ios and
// android `RCTTiming` module.
const FRAME_DURATION = 1000 / 60;
const IDLE_CALLBACK_FRAME_DEADLINE = 1;

// Parallel arrays
const callbacks: Array<?Function> = [];
const callbacks: Array<?TimerFunc> = [];
const types: Array<?JSTimerType> = [];
const timerIDs: Array<?number> = [];
const freeIdxs: Array<number> = [];
Expand All @@ -57,7 +59,7 @@ function _getFreeIndex(): number {
return freeIdx;
}

function _allocateCallback(func: Function, type: JSTimerType): number {
function _allocateCallback(func: TimerFunc, type: JSTimerType): number {
const id = GUID++;
const freeIndex = _getFreeIndex();
timerIDs[freeIndex] = id;
Expand Down Expand Up @@ -210,9 +212,9 @@ const JSTimers = {
* @param {number} duration Number of milliseconds.
*/
setTimeout: function (
func: Function,
func: TimerFunc,
duration: number,
...args: any
...args: Array<unknown>
): number {
const id = _allocateCallback(
() => func.apply(undefined, args),
Expand All @@ -227,9 +229,9 @@ const JSTimers = {
* @param {number} duration Number of milliseconds.
*/
setInterval: function (
func: Function,
func: TimerFunc,
duration: number,
...args: any
...args: Array<unknown>
): number {
const id = _allocateCallback(
() => func.apply(undefined, args),
Expand All @@ -247,7 +249,10 @@ const JSTimers = {
* @param {function} func Callback to be invoked before the end of the
* current JavaScript execution loop.
*/
queueReactNativeMicrotask: function (func: Function, ...args: any): number {
queueReactNativeMicrotask: function (
func: TimerFunc,
...args: Array<unknown>
): number {
const id = _allocateCallback(
() => func.apply(undefined, args),
'queueReactNativeMicrotask',
Expand All @@ -259,7 +264,7 @@ const JSTimers = {
/**
* @param {function} func Callback to be invoked every frame.
*/
requestAnimationFrame: function (func: Function): any | number {
requestAnimationFrame: function (func: TimerFunc): number {
const id = _allocateCallback(func, 'requestAnimationFrame');
createTimer(id, 1, Date.now(), /* recurring */ false);
return id;
Expand All @@ -271,17 +276,17 @@ const JSTimers = {
* @param {?object} options
*/
requestIdleCallback: function (
func: Function,
options: ?Object,
): any | number {
func: TimerFunc,
options: ?{timeout?: number, ...},
): number {
if (requestIdleCallbacks.length === 0) {
setSendIdleEvents(true);
}

const timeout = options && options.timeout;
const id: number = _allocateCallback(
timeout != null
? (deadline: any) => {
? (deadline: unknown) => {
const timeoutId: number = requestIdleCallbackTimeouts[id];
if (timeoutId) {
JSTimers.clearTimeout(timeoutId);
Expand Down Expand Up @@ -353,7 +358,7 @@ const JSTimers = {
* This is called from the native side. We are passed an array of timerIDs,
* and
*/
callTimers: function (timersToCall: Array<number>): any | void {
callTimers: function (timersToCall: Array<number>): void {
invariant(
timersToCall.length !== 0,
'Cannot call `callTimers` with an empty list of IDs.',
Expand Down Expand Up @@ -458,20 +463,34 @@ function setSendIdleEvents(sendIdleEvents: boolean): void {
}

let ExportedJSTimers: {
callIdleCallbacks: (frameTime: number) => any | void,
callIdleCallbacks: (frameTime: number) => void,
callReactNativeMicrotasks: () => void,
callTimers: (timersToCall: Array<number>) => any | void,
callTimers: (timersToCall: Array<number>) => void,
cancelAnimationFrame: (timerID: number) => void,
cancelIdleCallback: (timerID: number) => void,
clearReactNativeMicrotask: (timerID: number) => void,
clearInterval: (timerID: number) => void,
clearTimeout: (timerID: number) => void,
emitTimeDriftWarning: (warningMessage: string) => any | void,
requestAnimationFrame: (func: any) => any | number,
requestIdleCallback: (func: any, options: ?any) => any | number,
queueReactNativeMicrotask: (func: any, ...args: any) => number,
setInterval: (func: any, duration: number, ...args: any) => number,
setTimeout: (func: any, duration: number, ...args: any) => number,
emitTimeDriftWarning: (warningMessage: string) => void,
requestAnimationFrame: (func: TimerFunc) => number,
requestIdleCallback: (
func: TimerFunc,
options: ?{timeout?: number, ...},
) => number,
queueReactNativeMicrotask: (
func: TimerFunc,
...args: Array<unknown>
) => number,
setInterval: (
func: TimerFunc,
duration: number,
...args: Array<unknown>
) => number,
setTimeout: (
func: TimerFunc,
duration: number,
...args: Array<unknown>
) => number,
};

if (!NativeTiming) {
Expand Down
16 changes: 10 additions & 6 deletions packages/react-native/Libraries/Core/setUpReactDevTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
*/

'use strict';

import type {Domain} from '../../src/private/devsupport/rndevtools/setUpFuseboxReactDevToolsDispatcher';
import type {
Domain,
JSONValue,
} from '../../src/private/devsupport/rndevtools/setUpFuseboxReactDevToolsDispatcher';
import type {Spec as NativeReactDevToolsRuntimeSettingsModuleSpec} from '../../src/private/devsupport/rndevtools/specs/NativeReactDevToolsRuntimeSettingsModule';

if (__DEV__) {
Expand All @@ -35,6 +38,7 @@ if (__DEV__) {
const {
initialize,
connectWithCustomMessagingProtocol,
// $FlowFixMe[untyped-import]
} = require('react-devtools-core');

const reactDevToolsSettingsManager = require('../../src/private/devsupport/rndevtools/ReactDevToolsSettingsManager');
Expand Down Expand Up @@ -73,7 +77,7 @@ if (__DEV__) {
require('../Components/View/ReactNativeStyleAttributes').default;
const resolveRNStyle = require('../StyleSheet/flattenStyle').default;

function handleReactDevToolsSettingsUpdate(settings: Object) {
function handleReactDevToolsSettingsUpdate(settings: {[string]: unknown}) {
reactDevToolsSettingsManager.setGlobalHookSettings(
JSON.stringify(settings),
);
Expand All @@ -97,13 +101,13 @@ if (__DEV__) {
maybeReactDevToolsRuntimeSettingsModuleModule,
);
disconnect = connectWithCustomMessagingProtocol({
onSubscribe: listener => {
onSubscribe: (listener: (message: JSONValue) => void) => {
domain.onMessage.addEventListener(listener);
},
onUnsubscribe: listener => {
onUnsubscribe: (listener: (message: JSONValue) => void) => {
domain.onMessage.removeEventListener(listener);
},
onMessage: (event, payload) => {
onMessage: (event: string, payload: JSONValue) => {
domain.sendMessage({event, payload});
},
nativeStyleEditorValidAttributes: Object.keys(ReactNativeStyleAttributes),
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native/Libraries/Core/setUpReactRefresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
*/

Expand All @@ -18,6 +18,7 @@ if (__DEV__) {
}

// This needs to run before the renderer initializes.
// $FlowFixMe[untyped-import]
const ReactRefreshRuntime = require('react-refresh/runtime');
ReactRefreshRuntime.injectIntoGlobalHook(global);

Expand Down
27 changes: 17 additions & 10 deletions packages/react-native/Libraries/Lists/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
*/

Expand Down Expand Up @@ -78,10 +78,10 @@ type OptionalFlatListProps<ItemT> = {
* any of your `renderItem`, Header, Footer, etc. functions depend on anything outside of the
* `data` prop, stick it here and treat it immutably.
*/
extraData?: any,
extraData?: unknown,
/**
* `getItemLayout` is an optional optimizations that let us skip measurement of dynamic content if
* you know the height of items a priori. `getItemLayout` is the most efficient, and is easy to
* you know the height of items a priori.
* use if you have fixed height items, for example:
*
* getItemLayout={(data, index) => (
Expand Down Expand Up @@ -172,9 +172,10 @@ function numColumnsOrDefault(numColumns: ?number) {
return numColumns ?? 1;
}

function isArrayLike(data: unknown): boolean {
// $FlowExpectedError[incompatible-use]
return typeof Object(data).length === 'number';
function isArrayLike<ItemT>(
data: ?Readonly<$ArrayLike<ItemT>>,
): implies data is Readonly<$ArrayLike<ItemT>> {
return data != null && typeof data.length === 'number';
}

type FlatListBaseProps<ItemT> = {
Expand Down Expand Up @@ -305,6 +306,7 @@ export type FlatListProps<ItemT> = Readonly<{
*
* Also inherits [ScrollView Props](docs/scrollview.html#props), unless it is nested in another FlatList of same orientation.
*/
// flowlint-next-line unclear-type:off
class FlatList<ItemT = any> extends React.PureComponent<FlatListProps<ItemT>> {
/**
* Scrolls to the end of the content. May be janky without `getItemLayout` prop.
Expand Down Expand Up @@ -404,7 +406,7 @@ class FlatList<ItemT = any> extends React.PureComponent<FlatListProps<ItemT>> {
}
}

getScrollableNode(): any {
getScrollableNode(): ?number {
if (this._listRef) {
return this._listRef.getScrollableNode();
}
Expand Down Expand Up @@ -499,7 +501,10 @@ class FlatList<ItemT = any> extends React.PureComponent<FlatListProps<ItemT>> {
'FlatList does not support custom data formats.',
);
if (numColumns > 1) {
invariant(!horizontal, 'numColumns does not support horizontal.');
invariant(
!Boolean(horizontal),
'numColumns does not support horizontal.',
);
} else {
invariant(
!columnWrapperStyle,
Expand Down Expand Up @@ -611,11 +616,13 @@ class FlatList<ItemT = any> extends React.PureComponent<FlatListProps<ItemT>> {
}

_renderer = (
ListItemComponent: ?(React.ComponentType<any> | React.MixedElement),
ListItemComponent: ?(
React.ComponentType<ListRenderItemInfo<ItemT>> | React.MixedElement
),
renderItem: ?ListRenderItem<ItemT>,
columnWrapperStyle: ?ViewStyleProp,
numColumns: ?number,
extraData: ?any,
extraData: ?unknown,
// $FlowFixMe[missing-local-annot]
) => {
const cols = numColumnsOrDefault(numColumns);
Expand Down
10 changes: 6 additions & 4 deletions packages/react-native/Libraries/Lists/SectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
*/

Expand All @@ -26,6 +26,7 @@ import * as React from 'react';
const VirtualizedSectionList = VirtualizedLists.VirtualizedSectionList;

type DefaultSectionT = {
// flowlint-next-line unclear-type:off
[key: string]: any,
};

Expand Down Expand Up @@ -74,7 +75,7 @@ type OptionalSectionListProps<ItemT, SectionT = DefaultSectionT> = {
* any of your `renderItem`, Header, Footer, etc. functions depend on anything outside of the
* `data` prop, stick it here and treat it immutably.
*/
extraData?: any,
extraData?: unknown,
/**
* How many items to render in the initial batch. This should be enough to fill the screen but not
* much more. Note these items will never be unmounted as part of the windowed rendering in order
Expand Down Expand Up @@ -172,6 +173,7 @@ export type SectionListProps<ItemT, SectionT = DefaultSectionT> = {
* @see https://reactnative.dev/docs/sectionlist
*/
export default class SectionList<
// flowlint-next-line unclear-type:off
ItemT = any,
SectionT = DefaultSectionT,
> extends React.PureComponent<SectionListProps<ItemT, SectionT>> {
Expand Down Expand Up @@ -226,14 +228,14 @@ export default class SectionList<
/**
* Provides a handle to the underlying scroll node.
*/
getScrollableNode(): any {
getScrollableNode(): ?number {
const listRef = this._wrapperListRef && this._wrapperListRef.getListRef();
if (listRef) {
return listRef.getScrollableNode();
}
}

setNativeProps(props: Object) {
setNativeProps(props: {[string]: unknown, ...}) {
const listRef = this._wrapperListRef && this._wrapperListRef.getListRef();
if (listRef) {
listRef.setNativeProps(props);
Expand Down
Loading
Loading