Skip to content

Commit a5af841

Browse files
sherginfacebook-github-bot
authored andcommittedJan 15, 2018
Prettier for View, Image and co.
Summary: Trivial beauty. Reviewed By: sahrens Differential Revision: D6715955 fbshipit-source-id: 3632750591f53d4673a2ce76309a0cc62946524d
1 parent bf9cabb commit a5af841

12 files changed

+134
-74
lines changed
 

‎Libraries/Components/View/View.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*
99
* @providesModule View
1010
* @flow
11+
* @format
1112
*/
1213
'use strict';
1314

@@ -52,17 +53,18 @@ const View = createReactClass({
5253
*/
5354
viewConfig: {
5455
uiViewClassName: 'RCTView',
55-
validAttributes: ReactNativeViewAttributes.RCTView
56+
validAttributes: ReactNativeViewAttributes.RCTView,
5657
},
5758

5859
contextTypes: {
5960
isInAParentText: PropTypes.bool,
6061
},
6162

62-
render: function() {
63+
render() {
6364
invariant(
6465
!(this.context.isInAParentText && Platform.OS === 'android'),
65-
'Nesting of <View> within <Text> is not supported on Android.');
66+
'Nesting of <View> within <Text> is not supported on Android.',
67+
);
6668

6769
// WARNING: This method will not be used in production mode as in that mode we
6870
// replace wrapper component View with generated native wrapper RCTView. Avoid
@@ -76,17 +78,18 @@ const RCTView = requireNativeComponent('RCTView', View, {
7678
nativeOnly: {
7779
nativeBackgroundAndroid: true,
7880
nativeForegroundAndroid: true,
79-
}
81+
},
8082
});
8183

8284
if (__DEV__) {
8385
const UIManager = require('UIManager');
84-
const viewConfig = UIManager.viewConfigs && UIManager.viewConfigs.RCTView || {};
86+
const viewConfig =
87+
(UIManager.viewConfigs && UIManager.viewConfigs.RCTView) || {};
8588
for (const prop in viewConfig.nativeProps) {
8689
const viewAny: any = View; // Appease flow
8790
if (!viewAny.propTypes[prop] && !ReactNativeStyleAttributes[prop]) {
8891
throw new Error(
89-
'View is missing propType for native prop `' + prop + '`'
92+
'View is missing propType for native prop `' + prop + '`',
9093
);
9194
}
9295
}
@@ -98,4 +101,4 @@ if (__DEV__) {
98101
}
99102

100103
// No one should depend on the DEV-mode createClass View wrapper.
101-
module.exports = ((ViewToExport : any) : typeof RCTView);
104+
module.exports = ((ViewToExport: any): typeof RCTView);

‎Libraries/Image/AssetRegistry.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
*
99
* @providesModule AssetRegistry
1010
* @flow
11+
* @format
1112
*/
1213
'use strict';
1314

14-
1515
export type PackagerAsset = {
1616
+__packager_asset: boolean,
1717
+fileSystemLocation: string,
@@ -24,7 +24,6 @@ export type PackagerAsset = {
2424
+type: string,
2525
};
2626

27-
2827
var assets: Array<PackagerAsset> = [];
2928

3029
function registerAsset(asset: PackagerAsset): number {
@@ -37,4 +36,4 @@ function getAssetByID(assetId: number): PackagerAsset {
3736
return assets[assetId - 1];
3837
}
3938

40-
module.exports = { registerAsset, getAssetByID };
39+
module.exports = {registerAsset, getAssetByID};

‎Libraries/Image/AssetSourceResolver.js

+22-19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*
99
* @providesModule AssetSourceResolver
1010
* @flow
11+
* @format
1112
*/
1213
'use strict';
1314

@@ -19,7 +20,7 @@ export type ResolvedAssetSource = {
1920
scale: number,
2021
};
2122

22-
import type { PackagerAsset } from 'AssetRegistry';
23+
import type {PackagerAsset} from 'AssetRegistry';
2324

2425
const PixelRatio = require('PixelRatio');
2526
const Platform = require('Platform');
@@ -43,22 +44,18 @@ function getScaledAssetPath(asset): string {
4344
function getAssetPathInDrawableFolder(asset): string {
4445
var scale = AssetSourceResolver.pickScale(asset.scales, PixelRatio.get());
4546
var drawbleFolder = assetPathUtils.getAndroidResourceFolderName(asset, scale);
46-
var fileName = assetPathUtils.getAndroidResourceIdentifier(asset);
47+
var fileName = assetPathUtils.getAndroidResourceIdentifier(asset);
4748
return drawbleFolder + '/' + fileName + '.' + asset.type;
4849
}
4950

5051
class AssetSourceResolver {
51-
5252
serverUrl: ?string;
5353
// where the jsbundle is being run from
5454
jsbundleUrl: ?string;
5555
// the asset to resolve
5656
asset: PackagerAsset;
5757

58-
constructor(serverUrl: ?string,
59-
jsbundleUrl: ?string,
60-
asset: PackagerAsset
61-
) {
58+
constructor(serverUrl: ?string, jsbundleUrl: ?string, asset: PackagerAsset) {
6259
this.serverUrl = serverUrl;
6360
this.jsbundleUrl = jsbundleUrl;
6461
this.asset = asset;
@@ -78,9 +75,9 @@ class AssetSourceResolver {
7875
}
7976

8077
if (Platform.OS === 'android') {
81-
return this.isLoadedFromFileSystem() ?
82-
this.drawableFolderInBundle() :
83-
this.resourceIdentifierWithoutScale();
78+
return this.isLoadedFromFileSystem()
79+
? this.drawableFolderInBundle()
80+
: this.resourceIdentifierWithoutScale();
8481
} else {
8582
return this.scaledAssetURLNearBundle();
8683
}
@@ -93,8 +90,12 @@ class AssetSourceResolver {
9390
assetServerURL(): ResolvedAssetSource {
9491
invariant(!!this.serverUrl, 'need server to load from');
9592
return this.fromSource(
96-
this.serverUrl + getScaledAssetPath(this.asset) +
97-
'?platform=' + Platform.OS + '&hash=' + this.asset.hash
93+
this.serverUrl +
94+
getScaledAssetPath(this.asset) +
95+
'?platform=' +
96+
Platform.OS +
97+
'&hash=' +
98+
this.asset.hash,
9899
);
99100
}
100101

@@ -122,8 +123,13 @@ class AssetSourceResolver {
122123
* E.g. 'assets_awesomemodule_icon'
123124
*/
124125
resourceIdentifierWithoutScale(): ResolvedAssetSource {
125-
invariant(Platform.OS === 'android', 'resource identifiers work on Android');
126-
return this.fromSource(assetPathUtils.getAndroidResourceIdentifier(this.asset));
126+
invariant(
127+
Platform.OS === 'android',
128+
'resource identifiers work on Android',
129+
);
130+
return this.fromSource(
131+
assetPathUtils.getAndroidResourceIdentifier(this.asset),
132+
);
127133
}
128134

129135
/**
@@ -133,9 +139,7 @@ class AssetSourceResolver {
133139
*/
134140
drawableFolderInBundle(): ResolvedAssetSource {
135141
const path = this.jsbundleUrl || 'file://';
136-
return this.fromSource(
137-
path + getAssetPathInDrawableFolder(this.asset)
138-
);
142+
return this.fromSource(path + getAssetPathInDrawableFolder(this.asset));
139143
}
140144

141145
fromSource(source: string): ResolvedAssetSource {
@@ -161,7 +165,6 @@ class AssetSourceResolver {
161165
// in which case we default to 1
162166
return scales[scales.length - 1] || 1;
163167
}
164-
165168
}
166169

167-
module.exports = AssetSourceResolver;
170+
module.exports = AssetSourceResolver;

‎Libraries/Image/Image.android.js

+46-22
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*
99
* @providesModule Image
1010
* @flow
11+
* @format
1112
*/
1213
'use strict';
1314

@@ -32,9 +33,7 @@ var merge = require('merge');
3233
var requireNativeComponent = require('requireNativeComponent');
3334
var resolveAssetSource = require('resolveAssetSource');
3435

35-
var {
36-
ImageLoader,
37-
} = NativeModules;
36+
var {ImageLoader} = NativeModules;
3837

3938
let _requestId = 1;
4039
function generateRequestId() {
@@ -75,14 +74,16 @@ var ImageViewAttributes = merge(ReactNativeViewAttributes.UIView, {
7574
});
7675

7776
var ViewStyleKeys = new Set(Object.keys(ViewStylePropTypes));
78-
var ImageSpecificStyleKeys = new Set(Object.keys(ImageStylePropTypes).filter(x => !ViewStyleKeys.has(x)));
77+
var ImageSpecificStyleKeys = new Set(
78+
Object.keys(ImageStylePropTypes).filter(x => !ViewStyleKeys.has(x)),
79+
);
7980

8081
var Image = createReactClass({
8182
displayName: 'Image',
8283
propTypes: {
8384
...ViewPropTypes,
8485
style: StyleSheetPropType(ImageStylePropTypes),
85-
/**
86+
/**
8687
* `uri` is a string representing the resource identifier for the image, which
8788
* could be an http address, a local file path, or a static image
8889
* resource (which should be wrapped in the `require('./path/to/image.png')` function).
@@ -108,11 +109,12 @@ var Image = createReactClass({
108109
width: PropTypes.number,
109110
height: PropTypes.number,
110111
headers: PropTypes.objectOf(PropTypes.string),
111-
}))
112+
}),
113+
),
112114
]),
113115
/**
114-
* blurRadius: the blur radius of the blur filter added to the image
115-
*/
116+
* blurRadius: the blur radius of the blur filter added to the image
117+
*/
116118
blurRadius: PropTypes.number,
117119
/**
118120
* similarly to `source`, this property represents the resource used to render
@@ -202,9 +204,12 @@ var Image = createReactClass({
202204
.then(function(sizes) {
203205
success(sizes.width, sizes.height);
204206
})
205-
.catch(failure || function() {
206-
console.warn('Failed to get size for image: ' + url);
207-
});
207+
.catch(
208+
failure ||
209+
function() {
210+
console.warn('Failed to get size for image: ' + url);
211+
},
212+
);
208213
},
209214

210215
/**
@@ -231,7 +236,9 @@ var Image = createReactClass({
231236
* @return a mapping from url to cache status, such as "disk" or "memory". If a requested URL is
232237
* not in the mapping, it means it's not in the cache.
233238
*/
234-
async queryCache(urls: Array<string>): Promise<Map<string, 'memory' | 'disk'>> {
239+
async queryCache(
240+
urls: Array<string>,
241+
): Promise<Map<string, 'memory' | 'disk'>> {
235242
return await ImageLoader.queryCache(urls);
236243
},
237244

@@ -255,12 +262,14 @@ var Image = createReactClass({
255262
},
256263

257264
contextTypes: {
258-
isInAParentText: PropTypes.bool
265+
isInAParentText: PropTypes.bool,
259266
},
260267

261268
render: function() {
262269
const source = resolveAssetSource(this.props.source);
263-
const loadingIndicatorSource = resolveAssetSource(this.props.loadingIndicatorSource);
270+
const loadingIndicatorSource = resolveAssetSource(
271+
this.props.loadingIndicatorSource,
272+
);
264273

265274
// As opposed to the ios version, here we render `null` when there is no source, source.uri
266275
// or source array.
@@ -270,11 +279,15 @@ var Image = createReactClass({
270279
}
271280

272281
if (this.props.src) {
273-
console.warn('The <Image> component requires a `source` property rather than `src`.');
282+
console.warn(
283+
'The <Image> component requires a `source` property rather than `src`.',
284+
);
274285
}
275286

276287
if (this.props.children) {
277-
throw new Error('The <Image> component cannot contain children. If you want to render content on top of the image, consider using the <ImageBackground> component or absolute positioning.');
288+
throw new Error(
289+
'The <Image> component cannot contain children. If you want to render content on top of the image, consider using the <ImageBackground> component or absolute positioning.',
290+
);
278291
}
279292

280293
if (source && (source.uri || Array.isArray(source))) {
@@ -292,20 +305,27 @@ var Image = createReactClass({
292305
const {onLoadStart, onLoad, onLoadEnd, onError} = this.props;
293306
const nativeProps = merge(this.props, {
294307
style,
295-
shouldNotifyLoadEvents: !!(onLoadStart || onLoad || onLoadEnd || onError),
308+
shouldNotifyLoadEvents: !!(
309+
onLoadStart ||
310+
onLoad ||
311+
onLoadEnd ||
312+
onError
313+
),
296314
src: sources,
297315
headers: source.headers,
298-
loadingIndicatorSrc: loadingIndicatorSource ? loadingIndicatorSource.uri : null,
316+
loadingIndicatorSrc: loadingIndicatorSource
317+
? loadingIndicatorSource.uri
318+
: null,
299319
});
300320

301321
if (this.context.isInAParentText) {
302-
return <RCTTextInlineImage {...nativeProps}/>;
322+
return <RCTTextInlineImage {...nativeProps} />;
303323
} else {
304-
return <RKImage {...nativeProps}/>;
324+
return <RKImage {...nativeProps} />;
305325
}
306326
}
307327
return null;
308-
}
328+
},
309329
});
310330

311331
var styles = StyleSheet.create({
@@ -323,6 +343,10 @@ var cfg = {
323343
},
324344
};
325345
var RKImage = requireNativeComponent('RCTImageView', Image, cfg);
326-
var RCTTextInlineImage = requireNativeComponent('RCTTextInlineImage', Image, cfg);
346+
var RCTTextInlineImage = requireNativeComponent(
347+
'RCTTextInlineImage',
348+
Image,
349+
cfg,
350+
);
327351

328352
module.exports = Image;

0 commit comments

Comments
 (0)
Please sign in to comment.