Skip to content
Open
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
8 changes: 5 additions & 3 deletions packages/react-native/Libraries/Animated/AnimatedExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
* 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
*/

// flowlint unsafe-getters-setters:off

import typeof AnimatedFlatList from './components/AnimatedFlatList';
import typeof AnimatedImage from './components/AnimatedImage';
import typeof AnimatedScrollView from './components/AnimatedScrollView';
Expand All @@ -27,7 +29,7 @@ export default {
/**
* FlatList and SectionList infer generic Type defined under their `data` and `section` props.
*/
get FlatList(): AnimatedFlatList<any> {
get FlatList(): AnimatedFlatList<> {
return require('./components/AnimatedFlatList').default;
},
/**
Expand All @@ -47,7 +49,7 @@ export default {
/**
* FlatList and SectionList infer generic Type defined under their `data` and `section` props.
*/
get SectionList(): AnimatedSectionList<any, any> {
get SectionList(): AnimatedSectionList<> {
return require('./components/AnimatedSectionList').default;
},
/**
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 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 Down Expand Up @@ -64,10 +64,10 @@ type PassThroughProps = Readonly<{
passthroughAnimatedPropExplicitValues?: ViewProps | null,
}>;

type LooseOmit<O extends interface {}, K extends keyof $FlowFixMe> = Pick<
O,
Exclude<keyof O, K>,
>;
type LooseOmit<
O extends interface {},
K extends string | number | symbol,
> = Pick<O, Exclude<keyof O, K>>;

export type AnimatedProps<Props extends {...}> = LooseOmit<
{
Expand All @@ -94,7 +94,7 @@ export type AnimatedComponentType<
> = component(ref?: React.RefSetter<Instance>, ...AnimatedProps<Props>);

export default function createAnimatedComponent<
TInstance extends React.ComponentType<any>,
TInstance extends Exclude<React.ElementType, string>,
>(
Component: TInstance,
): AnimatedComponentType<
Expand Down Expand Up @@ -157,9 +157,11 @@ export function unstable_createAnimatedComponentWithAllowlist<
);
};

AnimatedComponent.displayName = `Animated(${
Component.displayName || 'Anonymous'
})`;
const componentName =
Component.displayName != null && Component.displayName !== ''
? Component.displayName
: 'Anonymous';
AnimatedComponent.displayName = `Animated(${componentName})`;

return AnimatedComponent;
}
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 @@ -63,7 +63,11 @@ export default class AnimatedAddition extends AnimatedWithChildren {
super.__detach();
}

__getNativeConfig(): any {
__getNativeConfig(): {
type: string,
input: [number, number],
debugID: ?string,
} {
return {
type: 'addition',
input: [this._a.__getNativeTag(), this._b.__getNativeTag()],
Expand Down
22 changes: 16 additions & 6 deletions packages/react-native/Libraries/Animated/nodes/AnimatedColor.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 @@ -90,19 +90,21 @@ function processColor(
return null;
}

function isRgbaValue(value: any): boolean {
function isRgbaValue(value: unknown): boolean {
return (
value &&
value != null &&
typeof value === 'object' &&
typeof value.r === 'number' &&
typeof value.g === 'number' &&
typeof value.b === 'number' &&
typeof value.a === 'number'
);
}

function isRgbaAnimatedValue(value: any): boolean {
function isRgbaAnimatedValue(value: unknown): boolean {
return (
value &&
value != null &&
typeof value === 'object' &&
value.r instanceof AnimatedValue &&
value.g instanceof AnimatedValue &&
value.b instanceof AnimatedValue &&
Expand Down Expand Up @@ -325,7 +327,15 @@ export default class AnimatedColor extends AnimatedWithChildren {
super.__makeNative(platformConfig);
}

__getNativeConfig(): {...} {
__getNativeConfig(): {
type: string,
r: number,
g: number,
b: number,
a: number,
nativeColor: ?NativeColorValue,
debugID: ?string,
} {
return {
type: 'color',
r: this.r.__getNativeTag(),
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 Down Expand Up @@ -70,7 +70,13 @@ export default class AnimatedDiffClamp extends AnimatedWithChildren {
super.__detach();
}

__getNativeConfig(): any {
__getNativeConfig(): {
type: string,
input: number,
min: number,
max: number,
debugID: ?string,
} {
return {
type: 'diffclamp',
input: this._a.__getNativeTag(),
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 Down Expand Up @@ -79,7 +79,11 @@ export default class AnimatedDivision extends AnimatedWithChildren {
super.__detach();
}

__getNativeConfig(): any {
__getNativeConfig(): {
type: string,
input: [number, number],
debugID: ?string,
} {
return {
type: 'division',
input: [this._a.__getNativeTag(), this._b.__getNativeTag()],
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 Down Expand Up @@ -57,7 +57,12 @@ export default class AnimatedModulo extends AnimatedWithChildren {
super.__detach();
}

__getNativeConfig(): any {
__getNativeConfig(): {
type: string,
input: number,
modulus: number,
debugID: ?string,
} {
return {
type: 'modulus',
input: this._a.__getNativeTag(),
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 Down Expand Up @@ -62,7 +62,11 @@ export default class AnimatedMultiplication extends AnimatedWithChildren {
super.__detach();
}

__getNativeConfig(): any {
__getNativeConfig(): {
type: string,
input: [number, number],
debugID: ?string,
} {
return {
type: 'multiplication',
input: [this._a.__getNativeTag(), this._b.__getNativeTag()],
Expand Down
Loading
Loading