Skip to content

Commit 8cdc9e7

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Place TypeScript Declarations Alongside Source Files
Summary: React Native's TS definitions are currently mostly stored in one monolithic file. This change splits the definitions up to correspond to the source files they came from, and are placed next to the source files. I think this should help inform, and make it easy to update the TS declarations when touching the Flow file. I noticed as part of the change that the typings have not yet removed many APIs that were removed from RN. This is bad, since it means using the removed/non-functional API doesn't cause typechecker errors. Locating typings next to source should prevent that from being able to happen. The organization here means individual TS declarations can declare what will be in the RN entrypoint, which is a little confusing. Seems like a good potential next refactor, beyond the literal translation I did. Changelog: [General][Changed] - Place TS Declarations Alongside Source Files Reviewed By: lunaleaps, rshest Differential Revision: D39796598 fbshipit-source-id: b36366466fd1976bdd2d4c8f7a4104a33c457a07
1 parent 77e79d6 commit 8cdc9e7

File tree

85 files changed

+10329
-10857
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+10329
-10857
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
*/
9+
10+
import {ProcessedColorValue} from '../StyleSheet/processColor';
11+
import {ColorValue} from '../StyleSheet/StyleSheet';
12+
13+
/**
14+
* @see: https://reactnative.dev/docs/actionsheetios#content
15+
*/
16+
export interface ActionSheetIOSOptions {
17+
title?: string | undefined;
18+
options: string[];
19+
cancelButtonIndex?: number | undefined;
20+
destructiveButtonIndex?: number | number[] | undefined | null;
21+
message?: string | undefined;
22+
anchor?: number | undefined;
23+
tintColor?: ColorValue | ProcessedColorValue | undefined;
24+
cancelButtonTintColor?: ColorValue | ProcessedColorValue | undefined;
25+
userInterfaceStyle?: 'light' | 'dark' | undefined;
26+
disabledButtonIndices?: number[] | undefined;
27+
}
28+
29+
export interface ShareActionSheetIOSOptions {
30+
message?: string | undefined;
31+
url?: string | undefined;
32+
subject?: string | undefined;
33+
/** The activities to exclude from the ActionSheet.
34+
* For example: ['com.apple.UIKit.activity.PostToTwitter']
35+
*/
36+
excludedActivityTypes?: string[] | undefined;
37+
}
38+
39+
/**
40+
* @see https://reactnative.dev/docs/actionsheetios#content
41+
*/
42+
export interface ActionSheetIOSStatic {
43+
/**
44+
* Display an iOS action sheet. The `options` object must contain one or more
45+
* of:
46+
* - `options` (array of strings) - a list of button titles (required)
47+
* - `cancelButtonIndex` (int) - index of cancel button in `options`
48+
* - `destructiveButtonIndex` (int) - index of destructive button in `options`
49+
* - `title` (string) - a title to show above the action sheet
50+
* - `message` (string) - a message to show below the title
51+
*/
52+
showActionSheetWithOptions: (
53+
options: ActionSheetIOSOptions,
54+
callback: (buttonIndex: number) => void,
55+
) => void;
56+
57+
/**
58+
* Display the iOS share sheet. The `options` object should contain
59+
* one or both of `message` and `url` and can additionally have
60+
* a `subject` or `excludedActivityTypes`:
61+
*
62+
* - `url` (string) - a URL to share
63+
* - `message` (string) - a message to share
64+
* - `subject` (string) - a subject for the message
65+
* - `excludedActivityTypes` (array) - the activities to exclude from the ActionSheet
66+
*
67+
* NOTE: if `url` points to a local file, or is a base64-encoded
68+
* uri, the file it points to will be loaded and shared directly.
69+
* In this way, you can share images, videos, PDF files, etc.
70+
*/
71+
showShareActionSheetWithOptions: (
72+
options: ShareActionSheetIOSOptions,
73+
failureCallback: (error: Error) => void,
74+
successCallback: (success: boolean, method: string) => void,
75+
) => void;
76+
}
77+
78+
export const ActionSheetIOS: ActionSheetIOSStatic;
79+
export type ActionSheetIOS = ActionSheetIOSStatic;

Libraries/Alert/Alert.d.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
*/
9+
10+
/**
11+
* @see https://reactnative.dev/docs/alert#content
12+
*/
13+
export interface AlertButton {
14+
text?: string | undefined;
15+
onPress?: ((value?: string) => void) | undefined;
16+
isPreferred?: boolean;
17+
style?: 'default' | 'cancel' | 'destructive' | undefined;
18+
}
19+
20+
interface AlertOptions {
21+
/** @platform android */
22+
cancelable?: boolean | undefined;
23+
userInterfaceStyle?: 'unspecified' | 'light' | 'dark';
24+
/** @platform android */
25+
onDismiss?: (() => void) | undefined;
26+
}
27+
28+
/**
29+
* Launches an alert dialog with the specified title and message.
30+
*
31+
* Optionally provide a list of buttons. Tapping any button will fire the
32+
* respective onPress callback and dismiss the alert. By default, the only
33+
* button will be an 'OK' button.
34+
*
35+
* This is an API that works both on iOS and Android and can show static
36+
* alerts. To show an alert that prompts the user to enter some information,
37+
* see `AlertIOS`; entering text in an alert is common on iOS only.
38+
*
39+
* ## iOS
40+
*
41+
* On iOS you can specify any number of buttons. Each button can optionally
42+
* specify a style, which is one of 'default', 'cancel' or 'destructive'.
43+
*
44+
* ## Android
45+
*
46+
* On Android at most three buttons can be specified. Android has a concept
47+
* of a neutral, negative and a positive button:
48+
*
49+
* - If you specify one button, it will be the 'positive' one (such as 'OK')
50+
* - Two buttons mean 'negative', 'positive' (such as 'Cancel', 'OK')
51+
* - Three buttons mean 'neutral', 'negative', 'positive' (such as 'Later', 'Cancel', 'OK')
52+
*
53+
* ```
54+
* // Works on both iOS and Android
55+
* Alert.alert(
56+
* 'Alert Title',
57+
* 'My Alert Msg',
58+
* [
59+
* {text: 'Ask me later', onPress: () => console.log('Ask me later pressed')},
60+
* {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
61+
* {text: 'OK', onPress: () => console.log('OK Pressed')},
62+
* ]
63+
* )
64+
* ```
65+
*/
66+
export interface AlertStatic {
67+
alert: (
68+
title: string,
69+
message?: string,
70+
buttons?: AlertButton[],
71+
options?: AlertOptions,
72+
) => void;
73+
prompt: (
74+
title: string,
75+
message?: string,
76+
callbackOrButtons?: ((text: string) => void) | AlertButton[],
77+
type?: AlertType,
78+
defaultValue?: string,
79+
keyboardType?: string,
80+
) => void;
81+
}
82+
83+
export type AlertType =
84+
| 'default'
85+
| 'plain-text'
86+
| 'secure-text'
87+
| 'login-password';
88+
89+
export const Alert: AlertStatic;
90+
export type Alert = AlertStatic;

0 commit comments

Comments
 (0)