Skip to content

Commit 76948ad

Browse files
elicwhitefacebook-github-bot
authored andcommitted
Typing View style as ViewStyleProp
Summary: Locking down view style so that invalid styles can't be passed into View. Reviewed By: yungsters Differential Revision: D9309097 fbshipit-source-id: 69e7e3c5626609cfd47c167027a55470c42228c8
1 parent 22cf5dc commit 76948ad

File tree

15 files changed

+70
-57
lines changed

15 files changed

+70
-57
lines changed

IntegrationTests/LayoutEventsTest.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,24 @@ const ReactNative = require('react-native');
1616
const {Image, LayoutAnimation, StyleSheet, Text, View} = ReactNative;
1717
const {TestModule} = ReactNative.NativeModules;
1818

19+
import type {ViewStyleProp} from 'StyleSheet';
20+
1921
const deepDiffer = require('deepDiffer');
2022

2123
function debug(...args) {
2224
// console.log.apply(null, arguments);
2325
}
2426

2527
import type {Layout, LayoutEvent} from 'CoreEventTypes';
26-
type Style = {
27-
margin?: number,
28-
padding?: number,
29-
borderColor?: string,
30-
borderWidth?: number,
31-
backgroundColor?: string,
32-
width?: number,
33-
};
3428

3529
type State = {
3630
didAnimation: boolean,
3731
extraText?: string,
3832
imageLayout?: Layout,
3933
textLayout?: Layout,
4034
viewLayout?: Layout,
41-
viewStyle?: Style,
42-
containerStyle?: Style,
35+
viewStyle?: ViewStyleProp,
36+
containerStyle?: ViewStyleProp,
4337
};
4438

4539
const LayoutEventsTest = createReactClass({

Libraries/Components/ScrollView/ScrollView.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ export type Props = $ReadOnly<{|
483483
* See [RefreshControl](docs/refreshcontrol.html).
484484
*/
485485
refreshControl?: ?React.Element<any>,
486-
style?: ?ViewStyleProp,
487486
children?: React.Node,
488487
|}>;
489488

Libraries/Components/TextInput/TextInput.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const requireNativeComponent = require('requireNativeComponent');
3333
const warning = require('fbjs/lib/warning');
3434

3535
import type {ColorValue} from 'StyleSheetTypes';
36-
import type {TextStyleProp} from 'StyleSheet';
36+
import type {TextStyleProp, ViewStyleProp} from 'StyleSheet';
3737
import type {ViewProps} from 'ViewPropTypes';
3838

3939
let AndroidTextInput;
@@ -169,7 +169,7 @@ type AndroidProps = $ReadOnly<{|
169169
|}>;
170170

171171
type Props = $ReadOnly<{|
172-
...ViewProps,
172+
...$Diff<ViewProps, $ReadOnly<{|style: ?ViewStyleProp|}>>,
173173
...IOSProps,
174174
...AndroidProps,
175175
autoCapitalize?: ?AutoCapitalize,

Libraries/Components/View/ViewPropTypes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import type {
3333
import type {EdgeInsetsProp} from 'EdgeInsetsPropType';
3434
import type {TVViewProps} from 'TVViewPropTypes';
3535
import type {Layout, LayoutEvent} from 'CoreEventTypes';
36+
import type {ViewStyleProp} from 'StyleSheet';
3637

3738
const stylePropType = StyleSheetPropType(ViewStylePropTypes);
3839

@@ -103,7 +104,7 @@ export type ViewProps = $ReadOnly<{|
103104
nativeID?: string,
104105
hitSlop?: ?EdgeInsetsProp,
105106
pointerEvents?: null | 'box-none' | 'none' | 'box-only' | 'auto',
106-
style?: stylePropType,
107+
style?: ?ViewStyleProp,
107108
removeClippedSubviews?: boolean,
108109
renderToHardwareTextureAndroid?: boolean,
109110
shouldRasterizeIOS?: boolean,

Libraries/Experimental/IncrementalPresenter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const View = require('View');
1818
const ViewPropTypes = require('ViewPropTypes');
1919

2020
import type {Context} from 'Incremental';
21+
import type {ViewStyleProp} from 'StyleSheet';
2122

2223
/**
2324
* WARNING: EXPERIMENTAL. Breaking changes will probably happen a lot and will
@@ -36,7 +37,7 @@ type Props = {
3637
disabled?: boolean,
3738
onDone?: () => void,
3839
onLayout?: (event: Object) => void,
39-
style?: mixed,
40+
style?: ViewStyleProp,
4041
children?: any,
4142
};
4243
class IncrementalPresenter extends React.Component<Props> {

Libraries/Image/Image.ios.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const ImageViewManager = NativeModules.ImageViewManager;
2323

2424
const RCTImageView = requireNativeComponent('RCTImageView');
2525

26+
import type {ImageStyleProp} from 'StyleSheet';
2627
import type {ImageProps as ImagePropsType} from 'ImageProps';
2728

2829
function getSize(
@@ -71,12 +72,14 @@ let Image = (
7172
};
7273

7374
let sources;
74-
let style;
75+
let style: ImageStyleProp;
7576
if (Array.isArray(source)) {
77+
// $FlowFixMe flattenStyle is not strong enough
7678
style = flattenStyle([styles.base, props.style]) || {};
7779
sources = source;
7880
} else {
7981
const {width, height, uri} = source;
82+
// $FlowFixMe flattenStyle is not strong enough
8083
style = flattenStyle([{width, height}, styles.base, props.style]) || {};
8184
sources = [source];
8285

Libraries/Image/ImageEditor.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ type ImageCropData = {
1616
* The top-left corner of the cropped image, specified in the original
1717
* image's coordinate space.
1818
*/
19-
offset: {
19+
offset: {|
2020
x: number,
2121
y: number,
22-
},
22+
|},
2323
/**
2424
* The size (dimensions) of the cropped image, specified in the original
2525
* image's coordinate space.
2626
*/
27-
size: {
27+
size: {|
2828
width: number,
2929
height: number,
30-
},
30+
|},
3131
/**
3232
* (Optional) size to scale the cropped image to.
3333
*/
34-
displaySize?: ?{
34+
displaySize?: ?{|
3535
width: number,
3636
height: number,
37-
},
37+
|},
3838
/**
3939
* (Optional) the resizing mode to use when scaling the image. If the
4040
* `displaySize` param is not specified, this has no effect.

Libraries/Image/ImageProps.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type {ViewProps} from 'ViewPropTypes';
2121
import type {ImageSource} from 'ImageSource';
2222
import type {EdgeInsetsProp} from 'EdgeInsetsPropType';
2323
import type {SyntheticEvent} from 'CoreEventTypes';
24-
import type {ImageStyleProp} from 'StyleSheet';
24+
import type {ViewStyleProp, ImageStyleProp} from 'StyleSheet';
2525

2626
type OnLoadEvent = SyntheticEvent<
2727
$ReadOnly<{|
@@ -51,7 +51,7 @@ type AndroidImageProps = $ReadOnly<{|
5151
|}>;
5252

5353
export type ImageProps = {|
54-
...ViewProps,
54+
...$Diff<ViewProps, $ReadOnly<{|style: ?ViewStyleProp|}>>,
5555
...IOSImageProps,
5656
...AndroidImageProps,
5757
blurRadius?: number,

Libraries/Lists/FlatList.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const StyleSheet = require('StyleSheet');
1818

1919
const invariant = require('fbjs/lib/invariant');
2020

21-
import type {DangerouslyImpreciseStyleProp, ViewStyleProp} from 'StyleSheet';
21+
import type {ViewStyleProp} from 'StyleSheet';
2222
import type {
2323
ViewabilityConfig,
2424
ViewToken,
@@ -104,7 +104,7 @@ type OptionalProps<ItemT> = {
104104
/**
105105
* Optional custom style for multi-item rows generated when numColumns > 1.
106106
*/
107-
columnWrapperStyle?: DangerouslyImpreciseStyleProp,
107+
columnWrapperStyle?: ViewStyleProp,
108108
/**
109109
* A marker property for telling the list to re-render (since it implements `PureComponent`). If
110110
* any of your `renderItem`, Header, Footer, etc. functions depend on anything outside of the

Libraries/Lists/VirtualizedList.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const warning = require('fbjs/lib/warning');
3131

3232
const {computeWindowedRenderLimits} = require('VirtualizeUtils');
3333

34-
import type {DangerouslyImpreciseStyleProp, ViewStyleProp} from 'StyleSheet';
34+
import type {ViewStyleProp} from 'StyleSheet';
3535
import type {
3636
ViewabilityConfig,
3737
ViewToken,
@@ -661,7 +661,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
661661
stickyIndicesFromProps: Set<number>,
662662
first: number,
663663
last: number,
664-
inversionStyle: ?DangerouslyImpreciseStyleProp,
664+
inversionStyle: ViewStyleProp,
665665
) {
666666
const {
667667
CellRendererComponent,
@@ -1619,7 +1619,7 @@ class CellRenderer extends React.Component<
16191619
fillRateHelper: FillRateHelper,
16201620
horizontal: ?boolean,
16211621
index: number,
1622-
inversionStyle: ?DangerouslyImpreciseStyleProp,
1622+
inversionStyle: ViewStyleProp,
16231623
item: Item,
16241624
onLayout: (event: Object) => void, // This is extracted by ScrollViewStickyHeader
16251625
onUnmount: (cellKey: string) => void,

0 commit comments

Comments
 (0)