Skip to content

Commit 888a253

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Update Alert types to use .js.flow as the common interface file (#49116)
Summary: Pull Request resolved: #49116 Changelog: [Internal] Differential Revision: D69044714
1 parent bc4dee9 commit 888a253

File tree

6 files changed

+73
-89
lines changed

6 files changed

+73
-89
lines changed

packages/react-native/Libraries/Alert/Alert.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
*/
1010

1111
import type {DialogOptions} from '../NativeModules/specs/NativeDialogManagerAndroid';
12-
import type {AlertOptions, AlertType, Buttons} from './Alert.flow';
12+
import type {AlertOptions, AlertType, Buttons} from './AlertTypes.flow';
1313

1414
import Platform from '../Utilities/Platform';
1515
import RCTAlertManager from './RCTAlertManager';
1616

17-
export type * from './Alert.flow';
18-
1917
class Alert {
2018
static alert(
2119
title: ?string,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
import type {AlertOptions, AlertType, Buttons} from './AlertTypes.flow';
12+
13+
export type * from './AlertTypes.flow';
14+
15+
/**
16+
* Launches an alert dialog with the specified title and message.
17+
*
18+
* See https://reactnative.dev/docs/alert
19+
*/
20+
declare class Alert {
21+
static alert(
22+
title: ?string,
23+
message?: ?string,
24+
buttons?: Buttons,
25+
options?: AlertOptions,
26+
): void;
27+
28+
static prompt(
29+
title: ?string,
30+
message?: ?string,
31+
callbackOrButtons?: ?(((text: string) => void) | Buttons),
32+
type?: ?AlertType,
33+
defaultValue?: string,
34+
keyboardType?: string,
35+
options?: AlertOptions,
36+
): void;
37+
}
38+
39+
export default Alert;

packages/react-native/Libraries/Alert/Alert.flow.js renamed to packages/react-native/Libraries/Alert/AlertTypes.flow.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,3 @@ export type AlertOptions = {
3434
onDismiss?: ?() => void,
3535
...
3636
};
37-
38-
/**
39-
* Launches an alert dialog with the specified title and message.
40-
*
41-
* See https://reactnative.dev/docs/alert
42-
*/
43-
declare class Alert {
44-
static alert(
45-
title: ?string,
46-
message?: ?string,
47-
buttons?: Buttons,
48-
options?: AlertOptions,
49-
): void;
50-
51-
static prompt(
52-
title: ?string,
53-
message?: ?string,
54-
callbackOrButtons?: ?(((text: string) => void) | Buttons),
55-
type?: ?AlertType,
56-
defaultValue?: string,
57-
keyboardType?: string,
58-
options?: AlertOptions,
59-
): void;
60-
}
61-
62-
export default Alert;

packages/react-native/Libraries/Alert/RCTAlertManager.flow.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,8 @@ declare export default typeof NativeActionSheetManager;
5353
"
5454
`;
5555

56-
exports[`public API should not change unintentionally Libraries/Alert/Alert.flow.js 1`] = `
57-
"export type AlertType =
58-
| \\"default\\"
59-
| \\"plain-text\\"
60-
| \\"secure-text\\"
61-
| \\"login-password\\";
62-
export type AlertButtonStyle = \\"default\\" | \\"cancel\\" | \\"destructive\\";
63-
export type AlertButton = {
64-
text?: string,
65-
onPress?: ?((value?: string) => any) | ?Function,
66-
isPreferred?: boolean,
67-
style?: AlertButtonStyle,
68-
...
69-
};
70-
export type Buttons = Array<AlertButton>;
71-
export type AlertOptions = {
72-
cancelable?: ?boolean,
73-
userInterfaceStyle?: \\"unspecified\\" | \\"light\\" | \\"dark\\",
74-
onDismiss?: ?() => void,
75-
...
76-
};
77-
declare class Alert {
56+
exports[`public API should not change unintentionally Libraries/Alert/Alert.js 1`] = `
57+
"declare class Alert {
7858
static alert(
7959
title: ?string,
8060
message?: ?string,
@@ -95,8 +75,8 @@ declare export default typeof Alert;
9575
"
9676
`;
9777

98-
exports[`public API should not change unintentionally Libraries/Alert/Alert.js 1`] = `
99-
"export type * from \\"./Alert.flow\\";
78+
exports[`public API should not change unintentionally Libraries/Alert/Alert.js.flow 1`] = `
79+
"export type * from \\"./AlertTypes.flow\\";
10080
declare class Alert {
10181
static alert(
10282
title: ?string,
@@ -118,20 +98,33 @@ declare export default typeof Alert;
11898
"
11999
`;
120100

121-
exports[`public API should not change unintentionally Libraries/Alert/NativeAlertManager.js 1`] = `
122-
"export * from \\"../../src/private/specs_DEPRECATED/modules/NativeAlertManager\\";
123-
declare export default typeof NativeAlertManager;
101+
exports[`public API should not change unintentionally Libraries/Alert/AlertTypes.flow.js 1`] = `
102+
"export type AlertType =
103+
| \\"default\\"
104+
| \\"plain-text\\"
105+
| \\"secure-text\\"
106+
| \\"login-password\\";
107+
export type AlertButtonStyle = \\"default\\" | \\"cancel\\" | \\"destructive\\";
108+
export type AlertButton = {
109+
text?: string,
110+
onPress?: ?((value?: string) => any) | ?Function,
111+
isPreferred?: boolean,
112+
style?: AlertButtonStyle,
113+
...
114+
};
115+
export type Buttons = Array<AlertButton>;
116+
export type AlertOptions = {
117+
cancelable?: ?boolean,
118+
userInterfaceStyle?: \\"unspecified\\" | \\"light\\" | \\"dark\\",
119+
onDismiss?: ?() => void,
120+
...
121+
};
124122
"
125123
`;
126124

127-
exports[`public API should not change unintentionally Libraries/Alert/RCTAlertManager.flow.js 1`] = `
128-
"declare const RCTAlertManager: {
129-
alertWithArgs(
130-
args: Args,
131-
callback: (id: number, value: string) => void
132-
): void,
133-
};
134-
declare export default typeof RCTAlertManager;
125+
exports[`public API should not change unintentionally Libraries/Alert/NativeAlertManager.js 1`] = `
126+
"export * from \\"../../src/private/specs_DEPRECATED/modules/NativeAlertManager\\";
127+
declare export default typeof NativeAlertManager;
135128
"
136129
`;
137130

scripts/build/build-types.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ const path = require('path');
2121
const {parseArgs} = require('util');
2222

2323
const TYPES_DIR = 'types_generated';
24-
const IGNORE_PATTERN = '**/__{tests,mocks,fixtures}__/**';
24+
const IGNORE_PATTERN = '**/__{tests,mocks,fixtures,flowtests}__/**';
2525

2626
const SOURCE_PATTERNS = [
2727
// Start with Animated only
28-
'react-native/Libraries/Alert/**/*.js',
28+
'react-native/Libraries/Alert/**/*.{js,flow}',
2929
'react-native/Libraries/ActionSheetIOS/**/*.js',
3030
'react-native/Libraries/TurboModule/RCTExport.js',
3131
'react-native/Libraries/Types/RootTagTypes.js',
@@ -115,7 +115,7 @@ function getBuildPath(file /*: string */) /*: string */ {
115115
packageDir,
116116
file
117117
.replace(packageDir, TYPES_DIR)
118-
.replace(/\.flow\.js$/, '.js')
118+
.replace(/\.js\.flow$/, '.js')
119119
.replace(/\.js$/, '.d.ts'),
120120
);
121121
}
@@ -126,15 +126,15 @@ function ignoreShadowedFiles(files /*: Array<string> */) /*: Array<string> */ {
126126

127127
// Find all flow definition files that shadow other files
128128
for (const file of files) {
129-
if (/\.flow\.js$/.test(file)) {
129+
if (/\.js\.flow$/.test(file)) {
130130
shadowedPrefixes[file.substring(0, file.length - 8)] = true;
131131
}
132132
}
133133

134134
// Filter out all files shadowed by flow definition files
135135
for (const file of files) {
136136
const prefix = file.split('.')[0];
137-
if (/\.flow\.js$/.test(file) || !shadowedPrefixes[prefix]) {
137+
if (/\.js\.flow$/.test(file) || !shadowedPrefixes[prefix]) {
138138
result.push(file);
139139
}
140140
}

0 commit comments

Comments
 (0)