Skip to content

Commit fd5f8ba

Browse files
committed
chore(Libraries): Updating overridden JavaScript libraries
Copied latest JavaScript from React Native.
1 parent 59bb64e commit fd5f8ba

17 files changed

+602
-560
lines changed

Libraries/Utilities/Alert.windows.js renamed to Libraries/Alert/Alert.windows.js

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,23 @@
1111
*/
1212
'use strict';
1313

14-
var AlertIOS = require('AlertIOS');
15-
var Platform = require('Platform');
16-
var DialogModuleAndroid = require('NativeModules').DialogManagerAndroid;
17-
var DialogModuleWindows = require('NativeModules').DialogManagerWindows;
14+
const AlertIOS = require('AlertIOS');
15+
const NativeModules = require('NativeModules');
16+
const Platform = require('Platform');
1817

1918
import type { AlertType, AlertButtonStyle } from 'AlertIOS';
2019

2120
type Buttons = Array<{
22-
text?: string;
23-
onPress?: ?Function;
24-
style?: AlertButtonStyle;
21+
text?: string,
22+
onPress?: ?Function,
23+
style?: AlertButtonStyle,
2524
}>;
2625

26+
type Options = {
27+
cancelable?: ?boolean,
28+
onDismiss?: ?Function,
29+
};
30+
2731
/**
2832
* Launches an alert dialog with the specified title and message.
2933
*
@@ -49,6 +53,15 @@ type Buttons = Array<{
4953
* - Two buttons mean 'negative', 'positive' (such as 'Cancel', 'OK')
5054
* - Three buttons mean 'neutral', 'negative', 'positive' (such as 'Later', 'Cancel', 'OK')
5155
*
56+
* By default alerts on Android can be dismissed by tapping outside of the alert
57+
* box. This event can be handled by providing an optional `options` parameter,
58+
* with an `onDismiss` callback property `{ onDismiss: () => {} }`.
59+
*
60+
* Alternatively, the dismissing behavior can be disabled altogether by providing
61+
* an optional `options` parameter with the `cancelable` property set to `false`
62+
* i.e. `{ cancelable: false }`
63+
*
64+
* Example usage:
5265
* ```
5366
* // Works on both iOS and Android
5467
* Alert.alert(
@@ -58,7 +71,8 @@ type Buttons = Array<{
5871
* {text: 'Ask me later', onPress: () => console.log('Ask me later pressed')},
5972
* {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
6073
* {text: 'OK', onPress: () => console.log('OK Pressed')},
61-
* ]
74+
* ],
75+
* { cancelable: false }
6276
* )
6377
* ```
6478
* ## Windows
@@ -86,17 +100,18 @@ class Alert {
86100
title: ?string,
87101
message?: ?string,
88102
buttons?: Buttons,
103+
options?: Options,
89104
type?: AlertType,
90105
): void {
91106
if (Platform.OS === 'ios') {
92107
if (typeof type !== 'undefined') {
93-
console.warn('Alert.alert() with a 4th "type" parameter is deprecated and will be removed. Use AlertIOS.prompt() instead.');
108+
console.warn('Alert.alert() with a 5th "type" parameter is deprecated and will be removed. Use AlertIOS.prompt() instead.');
94109
AlertIOS.alert(title, message, buttons, type);
95110
return;
96111
}
97112
AlertIOS.alert(title, message, buttons);
98113
} else if (Platform.OS === 'android') {
99-
AlertAndroid.alert(title, message, buttons);
114+
AlertAndroid.alert(title, message, buttons, options);
100115
} else if (Platform.OS === 'windows') {
101116
AlertWindows.alert(title, message, buttons);
102117
}
@@ -112,39 +127,45 @@ class AlertAndroid {
112127
title: ?string,
113128
message?: ?string,
114129
buttons?: Buttons,
130+
options?: Options,
115131
): void {
116132
var config = {
117133
title: title || '',
118134
message: message || '',
119135
};
136+
137+
if (options) {
138+
config = {...config, cancelable: options.cancelable};
139+
}
120140
// At most three buttons (neutral, negative, positive). Ignore rest.
121141
// The text 'OK' should be probably localized. iOS Alert does that in native.
122142
var validButtons: Buttons = buttons ? buttons.slice(0, 3) : [{text: 'OK'}];
123143
var buttonPositive = validButtons.pop();
124144
var buttonNegative = validButtons.pop();
125145
var buttonNeutral = validButtons.pop();
126146
if (buttonNeutral) {
127-
config = {...config, buttonNeutral: buttonNeutral.text || '' }
147+
config = {...config, buttonNeutral: buttonNeutral.text || '' };
128148
}
129149
if (buttonNegative) {
130-
config = {...config, buttonNegative: buttonNegative.text || '' }
150+
config = {...config, buttonNegative: buttonNegative.text || '' };
131151
}
132152
if (buttonPositive) {
133-
config = {...config, buttonPositive: buttonPositive.text || '' }
153+
config = {...config, buttonPositive: buttonPositive.text || '' };
134154
}
135-
DialogModuleAndroid.showAlert(
155+
NativeModules.DialogManagerAndroid.showAlert(
136156
config,
137-
(errorMessage) => console.warn(message),
157+
(errorMessage) => console.warn(errorMessage),
138158
(action, buttonKey) => {
139-
if (action !== DialogModuleAndroid.buttonClicked) {
140-
return;
141-
}
142-
if (buttonKey === DialogModuleAndroid.buttonNeutral) {
143-
buttonNeutral.onPress && buttonNeutral.onPress();
144-
} else if (buttonKey === DialogModuleAndroid.buttonNegative) {
145-
buttonNegative.onPress && buttonNegative.onPress();
146-
} else if (buttonKey === DialogModuleAndroid.buttonPositive) {
147-
buttonPositive.onPress && buttonPositive.onPress();
159+
if (action === NativeModules.DialogManagerAndroid.buttonClicked) {
160+
if (buttonKey === NativeModules.DialogManagerAndroid.buttonNeutral) {
161+
buttonNeutral.onPress && buttonNeutral.onPress();
162+
} else if (buttonKey === NativeModules.DialogManagerAndroid.buttonNegative) {
163+
buttonNegative.onPress && buttonNegative.onPress();
164+
} else if (buttonKey === NativeModules.DialogManagerAndroid.buttonPositive) {
165+
buttonPositive.onPress && buttonPositive.onPress();
166+
}
167+
} else if (action === NativeModules.DialogManagerAndroid.dismissed) {
168+
options && options.onDismiss && options.onDismiss();
148169
}
149170
}
150171
);
@@ -176,16 +197,16 @@ class AlertWindows {
176197
if (buttonPositive) {
177198
config = {...config, buttonPositive: buttonPositive.text || '' }
178199
}
179-
DialogModuleWindows.showAlert(
200+
NativeModules.DialogManagerWindows.showAlert(
180201
config,
181202
(errorMessage) => console.warn(message),
182203
(action, buttonKey) => {
183-
if (action !== DialogModuleWindows.buttonClicked) {
204+
if (action !== NativeModules.DialogManagerWindows.buttonClicked) {
184205
return;
185206
}
186-
if (buttonKey === DialogModuleWindows.buttonNegative) {
207+
if (buttonKey === NativeModules.DialogManagerWindows.buttonNegative) {
187208
buttonNegative.onPress && buttonNegative.onPress();
188-
} else if (buttonKey === DialogModuleWindows.buttonPositive) {
209+
} else if (buttonKey === NativeModules.DialogManagerWindows.buttonPositive) {
189210
buttonPositive.onPress && buttonPositive.onPress();
190211
}
191212
}

Libraries/Components/ActivityIndicator/ActivityIndicator.windows.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,32 @@ const ColorPropType = require('ColorPropType');
1515
const NativeMethodsMixin = require('NativeMethodsMixin');
1616
const Platform = require('Platform');
1717
const React = require('React');
18+
const PropTypes = require('prop-types');
1819
const StyleSheet = require('StyleSheet');
1920
const View = require('View');
21+
const ViewPropTypes = require('ViewPropTypes');
2022

2123
const requireNativeComponent = require('requireNativeComponent');
2224

23-
const PropTypes = React.PropTypes;
24-
2525
const GRAY = '#999999';
2626

27+
type IndicatorSize = number | 'small' | 'large';
28+
29+
type DefaultProps = {
30+
animating: boolean,
31+
color: any,
32+
hidesWhenStopped: boolean,
33+
size: IndicatorSize,
34+
}
35+
2736
/**
2837
* Displays a circular loading indicator.
2938
*/
3039
const ActivityIndicator = React.createClass({
3140
mixins: [NativeMethodsMixin],
3241

3342
propTypes: {
34-
...View.propTypes,
43+
...ViewPropTypes,
3544
/**
3645
* Whether to show the indicator (true, the default) or hide it (false).
3746
*/
@@ -41,12 +50,12 @@ const ActivityIndicator = React.createClass({
4150
*/
4251
color: ColorPropType,
4352
/**
44-
* Size of the indicator. Small has a height of 20, large has a height of 36.
45-
* Other sizes can be obtained using a scale transform.
53+
* Size of the indicator (default is 'small').
54+
* Passing a number to the size prop is only supported on Android.
4655
*/
47-
size: PropTypes.oneOf([
48-
'small',
49-
'large',
56+
size: PropTypes.oneOfType([
57+
PropTypes.oneOf([ 'small', 'large' ]),
58+
PropTypes.number,
5059
]),
5160
/**
5261
* Whether the indicator should hide when not animating (true by default).
@@ -56,7 +65,7 @@ const ActivityIndicator = React.createClass({
5665
hidesWhenStopped: PropTypes.bool,
5766
},
5867

59-
getDefaultProps() {
68+
getDefaultProps(): DefaultProps {
6069
return {
6170
animating: true,
6271
color: Platform.OS !== 'android' ? GRAY : undefined,
@@ -68,14 +77,19 @@ const ActivityIndicator = React.createClass({
6877
render() {
6978
const {onLayout, style, ...props} = this.props;
7079
let sizeStyle;
80+
7181
switch (props.size) {
7282
case 'small':
7383
sizeStyle = styles.sizeSmall;
7484
break;
7585
case 'large':
7686
sizeStyle = styles.sizeLarge;
7787
break;
88+
default:
89+
sizeStyle = {height: props.size, width: props.size};
90+
break;
7891
}
92+
7993
return (
8094
<View
8195
onLayout={onLayout}
@@ -127,7 +141,7 @@ if (Platform.OS === 'ios') {
127141
var RCTActivityIndicator = requireNativeComponent(
128142
'WindowsProgressRing',
129143
ActivityIndicator
130-
)
144+
);
131145
}
132146

133147
module.exports = ActivityIndicator;

Libraries/Components/ActivityIndicator/ActivityIndicatorIOS.windows.js

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

0 commit comments

Comments
 (0)