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
41 changes: 32 additions & 9 deletions packages/react-native/Libraries/Animated/AnimatedEvent.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 @@ -29,6 +29,7 @@ export type EventConfig<T> = {
};

export function attachNativeEventImpl(
// $FlowFixMe[unclear-type]
viewRef: any,
eventName: string,
argMapping: ReadonlyArray<?Mapping>,
Expand Down Expand Up @@ -56,13 +57,20 @@ export function attachNativeEventImpl(
}
};

const firstMapping = argMapping[0];
const nativeEventMapping =
firstMapping != null &&
!(firstMapping instanceof AnimatedValue) &&
!(firstMapping instanceof AnimatedValueXY)
? firstMapping.nativeEvent
: null;
invariant(
argMapping[0] && argMapping[0].nativeEvent,
nativeEventMapping != null,
'Native driven events only support animated values contained inside `nativeEvent`.',
);

// Assume that the event containing `nativeEvent` is always the first argument.
traverse(argMapping[0].nativeEvent, []);
traverse(nativeEventMapping, []);

const viewTag = findNodeHandle(viewRef);
if (viewTag != null) {
Expand Down Expand Up @@ -91,7 +99,9 @@ export function attachNativeEventImpl(
};
}

// $FlowFixMe[unclear-type]
function validateMapping(argMapping: ReadonlyArray<?Mapping>, args: any) {
// $FlowFixMe[unclear-type]
const validate = (recMapping: ?Mapping, recEvt: any, key: string) => {
if (recMapping instanceof AnimatedValue) {
invariant(
Expand Down Expand Up @@ -145,35 +155,42 @@ function validateMapping(argMapping: ReadonlyArray<?Mapping>, args: any) {

export class AnimatedEvent {
_argMapping: ReadonlyArray<?Mapping>;
// $FlowFixMe[unclear-type]
_listeners: Array<Function> = [];
_attachedEvent: ?{detach: () => void, ...};
__isNative: boolean;
__platformConfig: ?PlatformConfig;

// $FlowFixMe[unclear-type]
constructor(argMapping: ReadonlyArray<?Mapping>, config: EventConfig<any>) {
this._argMapping = argMapping;

if (config == null) {
let resolvedConfig = config;
if (resolvedConfig == null) {
console.warn('Animated.event now requires a second argument for options');
config = {useNativeDriver: false};
resolvedConfig = {useNativeDriver: false};
}

if (config.listener) {
this.__addListener(config.listener);
if (resolvedConfig.listener) {
this.__addListener(resolvedConfig.listener);
}
this._attachedEvent = null;
this.__isNative = NativeAnimatedHelper.shouldUseNativeDriver(config);
this.__platformConfig = config.platformConfig;
this.__isNative =
NativeAnimatedHelper.shouldUseNativeDriver(resolvedConfig);
this.__platformConfig = resolvedConfig.platformConfig;
}

// $FlowFixMe[unclear-type]
__addListener(callback: Function): void {
this._listeners.push(callback);
}

// $FlowFixMe[unclear-type]
__removeListener(callback: Function): void {
this._listeners = this._listeners.filter(listener => listener !== callback);
}

// $FlowFixMe[unclear-type]
__attach(viewRef: any, eventName: string): void {
invariant(
this.__isNative,
Expand All @@ -188,6 +205,7 @@ export class AnimatedEvent {
);
}

// $FlowFixMe[unclear-type]
__detach(viewTag: any, eventName: string): void {
invariant(
this.__isNative,
Expand All @@ -197,10 +215,12 @@ export class AnimatedEvent {
this._attachedEvent && this._attachedEvent.detach();
}

// $FlowFixMe[unclear-type]
__getHandler(): (...args: any) => void {
if (this.__isNative) {
if (__DEV__) {
let validatedMapping = false;
// $FlowFixMe[unclear-type]
return (...args: any) => {
if (!validatedMapping) {
validateMapping(this._argMapping, args);
Expand All @@ -214,6 +234,7 @@ export class AnimatedEvent {
}

let validatedMapping = false;
// $FlowFixMe[unclear-type]
return (...args: any) => {
if (__DEV__ && !validatedMapping) {
validateMapping(this._argMapping, args);
Expand All @@ -222,6 +243,7 @@ export class AnimatedEvent {

const traverse = (
recMapping: ?(Mapping | AnimatedValue),
// $FlowFixMe[unclear-type]
recEvt: any,
) => {
if (recMapping instanceof AnimatedValue) {
Expand Down Expand Up @@ -250,6 +272,7 @@ export class AnimatedEvent {
};
}

// $FlowFixMe[unclear-type]
_callListeners = (...args: any) => {
this._listeners.forEach(listener => listener(...args));
};
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
Loading
Loading