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
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 @@ -49,6 +49,7 @@ export type ShareActionSheetIOSOptions = Readonly<{
export type ShareActionSheetError = Readonly<{
domain: string,
code: string,
// $FlowFixMe[unclear-type]
userInfo?: ?Object,
message: string,
}>;
Expand Down Expand Up @@ -155,7 +156,9 @@ const ActionSheetIOS = {
*/
showShareActionSheetWithOptions(
options: ShareActionSheetIOSOptions,
// $FlowFixMe[unclear-type]
failureCallback: Function | ((error: ShareActionSheetError) => void),
// $FlowFixMe[unclear-type]
successCallback: Function | ((success: boolean, method: ?string) => void),
) {
invariant(
Expand Down
40 changes: 20 additions & 20 deletions packages/react-native/Libraries/Alert/Alert.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 @@ export type AlertButtonStyle = 'default' | 'cancel' | 'destructive';

export type AlertButton = {
text?: string,
// $FlowFixMe[unclear-type]
onPress?: ?((value?: string) => any) | ?Function,
isPreferred?: boolean,
style?: AlertButtonStyle,
Expand Down Expand Up @@ -121,7 +122,7 @@ class Alert {
cancelable: false,
};

if (options && options.cancelable) {
if (options != null && options.cancelable === true) {
config.cancelable = options.cancelable;
}
// At most three buttons (neutral, negative, positive). Ignore rest.
Expand All @@ -141,25 +142,20 @@ class Alert {
config.buttonNegative = buttonNegative.text || '';
}
if (buttonPositive) {
config.buttonPositive = buttonPositive.text || defaultPositiveText;
config.buttonPositive =
buttonPositive.text != null && buttonPositive.text !== ''
? buttonPositive.text
: defaultPositiveText;
}

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by
* Flow's LTI update could not be added via codemod */
const onAction = (action, buttonKey) => {
const onAction = (action: string, buttonKey?: number) => {
if (action === constants.buttonClicked) {
if (buttonKey === constants.buttonNeutral) {
// $FlowFixMe[incompatible-type]
// $FlowFixMe[incompatible-use]
buttonNeutral.onPress && buttonNeutral.onPress();
buttonNeutral?.onPress?.();
} else if (buttonKey === constants.buttonNegative) {
// $FlowFixMe[incompatible-type]
// $FlowFixMe[incompatible-use]
buttonNegative.onPress && buttonNegative.onPress();
buttonNegative?.onPress?.();
} else if (buttonKey === constants.buttonPositive) {
// $FlowFixMe[incompatible-type]
// $FlowFixMe[incompatible-use]
buttonPositive.onPress && buttonPositive.onPress();
buttonPositive?.onPress?.();
}
} else if (action === constants.dismissed) {
options && options.onDismiss && options.onDismiss();
Expand All @@ -186,7 +182,7 @@ class Alert {
options?: AlertOptions,
): void {
if (Platform.OS === 'ios') {
let callbacks: Array<?any> = [];
let callbacks: Array<?(value: string) => unknown> = [];
const buttons = [];
let cancelButtonKey;
let destructiveButtonKey;
Expand All @@ -195,16 +191,20 @@ class Alert {
callbacks = [callbackOrButtons];
} else if (Array.isArray(callbackOrButtons)) {
callbackOrButtons.forEach((btn, index) => {
callbacks[index] = btn.onPress;
callbacks[index] =
btn.onPress == null ? null : value => btn.onPress?.(value);
if (btn.style === 'cancel') {
cancelButtonKey = String(index);
} else if (btn.style === 'destructive') {
destructiveButtonKey = String(index);
}
if (btn.isPreferred) {
if (btn.isPreferred === true) {
preferredButtonKey = String(index);
}
if (btn.text || index < (callbackOrButtons || []).length - 1) {
if (
(btn.text != null && btn.text !== '') ||
index < callbackOrButtons.length - 1
) {
const btnDef: {[number]: string} = {};
btnDef[index] = btn.text || '';
buttons.push(btnDef);
Expand All @@ -215,7 +215,7 @@ class Alert {
alertWithArgs(
{
title: title || '',
message: message || undefined,
message: message != null && message !== '' ? message : undefined,
buttons,
type: type || undefined,
defaultValue,
Expand Down
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 @@ -20,6 +20,7 @@ import invariant from 'invariant';
*/
/* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
* Flow's LTI update could not be added via codemod */
// $FlowFixMe[unclear-type]
const oneArgumentPooler = function (copyFieldsFrom: any) {
const Klass = this; // eslint-disable-line consistent-this
if (Klass.instancePool.length) {
Expand All @@ -33,6 +34,7 @@ const oneArgumentPooler = function (copyFieldsFrom: any) {

/* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
* Flow's LTI update could not be added via codemod */
// $FlowFixMe[unclear-type]
const twoArgumentPooler = function (a1: any, a2: any) {
const Klass = this; // eslint-disable-line consistent-this
if (Klass.instancePool.length) {
Expand All @@ -46,6 +48,7 @@ const twoArgumentPooler = function (a1: any, a2: any) {

/* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
* Flow's LTI update could not be added via codemod */
// $FlowFixMe[unclear-type]
const threeArgumentPooler = function (a1: any, a2: any, a3: any) {
const Klass = this; // eslint-disable-line consistent-this
if (Klass.instancePool.length) {
Expand All @@ -59,6 +62,7 @@ const threeArgumentPooler = function (a1: any, a2: any, a3: any) {

/* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
* Flow's LTI update could not be added via codemod */
// $FlowFixMe[unclear-type]
const fourArgumentPooler = function (a1: any, a2: any, a3: any, a4: any) {
const Klass = this; // eslint-disable-line consistent-this
if (Klass.instancePool.length) {
Expand Down Expand Up @@ -89,6 +93,7 @@ const standardReleaser = function (instance) {
const DEFAULT_POOL_SIZE = 10;
const DEFAULT_POOLER = oneArgumentPooler;

// $FlowFixMe[unclear-type]
type Pooler = any;

/**
Expand All @@ -112,6 +117,7 @@ const addPoolingTo = function <T>(
} {
// Casting as any so that flow ignores the actual implementation and trusts
// it to match the type we declared
// $FlowFixMe[unclear-type]
const NewKlass: any = CopyConstructor;
NewKlass.instancePool = [];
NewKlass.getPooled = pooler || DEFAULT_POOLER;
Expand Down
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
Loading
Loading