2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2015-03-23 20:35:08 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
|
|
|
* @providesModule ImageStylePropTypes
|
2015-03-26 17:06:50 +00:00
|
|
|
* @flow
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var ImageResizeMode = require('ImageResizeMode');
|
|
|
|
var LayoutPropTypes = require('LayoutPropTypes');
|
2016-07-05 13:34:00 +00:00
|
|
|
var ReactPropTypes = require('react/lib/ReactPropTypes');
|
2015-12-23 03:29:01 +00:00
|
|
|
var ColorPropType = require('ColorPropType');
|
Improved shadow performance
Summary:
public
React Native currently exposes the iOS layer shadow properties more-or-less directly, however there are a number of problems with this:
1) Performance when using these properties is poor by default. That's because iOS calculates the shadow by getting the exact pixel mask of the view, including any tranlucent content, and all of its subviews, which is very CPU and GPU-intensive.
2) The iOS shadow properties do not match the syntax or semantics of the CSS box-shadow standard, and are unlikely to be possible to implement on Android.
3) We don't expose the `layer.shadowPath` property, which is crucial to getting good performance out of layer shadows.
This diff solves problem number 1) by implementing a default `shadowPath` that matches the view border for views with an opaque background. This improves the performance of shadows by optimizing for the common usage case. I've also reinstated background color propagation for views which have shadow props - this should help ensure that this best-case scenario occurs more often.
For views with an explicit transparent background, the shadow will continue to work as it did before ( `shadowPath` will be left unset, and the shadow will be derived exactly from the pixels of the view and its subviews). This is the worst-case path for performance, however, so you should avoid it unless absolutely necessary. **Support for this may be disabled by default in future, or dropped altogether.**
For translucent images, it is suggested that you bake the shadow into the image itself, or use another mechanism to pre-generate the shadow. For text shadows, you should use the textShadow properties, which work cross-platform and have much better performance.
Problem number 2) will be solved in a future diff, possibly by renaming the iOS shadowXXX properties to boxShadowXXX, and changing the syntax and semantics to match the CSS standards.
Problem number 3) is now mostly moot, since we generate the shadowPath automatically. In future, we may provide an iOS-specific prop to set the path explicitly if there's a demand for more precise control of the shadow.
Reviewed By: weicool
Differential Revision: D2827581
fb-gh-sync-id: 853aa018e1d61d5f88304c6fc1b78f9d7e739804
2016-01-14 22:03:31 +00:00
|
|
|
var ShadowPropTypesIOS = require('ShadowPropTypesIOS');
|
2015-05-06 21:28:05 +00:00
|
|
|
var TransformPropTypes = require('TransformPropTypes');
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-03-20 23:41:31 +00:00
|
|
|
var ImageStylePropTypes = {
|
|
|
|
...LayoutPropTypes,
|
Improved shadow performance
Summary:
public
React Native currently exposes the iOS layer shadow properties more-or-less directly, however there are a number of problems with this:
1) Performance when using these properties is poor by default. That's because iOS calculates the shadow by getting the exact pixel mask of the view, including any tranlucent content, and all of its subviews, which is very CPU and GPU-intensive.
2) The iOS shadow properties do not match the syntax or semantics of the CSS box-shadow standard, and are unlikely to be possible to implement on Android.
3) We don't expose the `layer.shadowPath` property, which is crucial to getting good performance out of layer shadows.
This diff solves problem number 1) by implementing a default `shadowPath` that matches the view border for views with an opaque background. This improves the performance of shadows by optimizing for the common usage case. I've also reinstated background color propagation for views which have shadow props - this should help ensure that this best-case scenario occurs more often.
For views with an explicit transparent background, the shadow will continue to work as it did before ( `shadowPath` will be left unset, and the shadow will be derived exactly from the pixels of the view and its subviews). This is the worst-case path for performance, however, so you should avoid it unless absolutely necessary. **Support for this may be disabled by default in future, or dropped altogether.**
For translucent images, it is suggested that you bake the shadow into the image itself, or use another mechanism to pre-generate the shadow. For text shadows, you should use the textShadow properties, which work cross-platform and have much better performance.
Problem number 2) will be solved in a future diff, possibly by renaming the iOS shadowXXX properties to boxShadowXXX, and changing the syntax and semantics to match the CSS standards.
Problem number 3) is now mostly moot, since we generate the shadowPath automatically. In future, we may provide an iOS-specific prop to set the path explicitly if there's a demand for more precise control of the shadow.
Reviewed By: weicool
Differential Revision: D2827581
fb-gh-sync-id: 853aa018e1d61d5f88304c6fc1b78f9d7e739804
2016-01-14 22:03:31 +00:00
|
|
|
...ShadowPropTypesIOS,
|
2015-05-06 21:28:05 +00:00
|
|
|
...TransformPropTypes,
|
2015-03-20 23:41:31 +00:00
|
|
|
resizeMode: ReactPropTypes.oneOf(Object.keys(ImageResizeMode)),
|
2015-12-15 02:56:32 +00:00
|
|
|
backfaceVisibility: ReactPropTypes.oneOf(['visible', 'hidden']),
|
2015-12-23 03:29:01 +00:00
|
|
|
backgroundColor: ColorPropType,
|
|
|
|
borderColor: ColorPropType,
|
2015-03-20 23:41:31 +00:00
|
|
|
borderWidth: ReactPropTypes.number,
|
|
|
|
borderRadius: ReactPropTypes.number,
|
2015-07-27 17:49:43 +00:00
|
|
|
overflow: ReactPropTypes.oneOf(['visible', 'hidden']),
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2016-04-06 16:20:39 +00:00
|
|
|
/**
|
2016-01-24 21:59:36 +00:00
|
|
|
* Changes the color of all the non-transparent pixels to the tintColor.
|
|
|
|
*/
|
2015-12-23 03:29:01 +00:00
|
|
|
tintColor: ColorPropType,
|
2015-03-20 23:41:31 +00:00
|
|
|
opacity: ReactPropTypes.number,
|
2016-01-24 21:59:36 +00:00
|
|
|
/**
|
|
|
|
* When the image has rounded corners, specifying an overlayColor will
|
|
|
|
* cause the remaining space in the corners to be filled with a solid color.
|
|
|
|
* This is useful in cases which are not supported by the Android
|
|
|
|
* implementation of rounded corners:
|
|
|
|
* - Certain resize modes, such as 'contain'
|
|
|
|
* - Animated GIFs
|
2016-04-06 16:20:39 +00:00
|
|
|
*
|
2016-01-24 21:59:36 +00:00
|
|
|
* A typical way to use this prop is with images displayed on a solid
|
|
|
|
* background and setting the `overlayColor` to the same color
|
|
|
|
* as the background.
|
|
|
|
*
|
|
|
|
* For details of how this works under the hood, see
|
|
|
|
* http://frescolib.org/docs/rounded-corners-and-circles.html
|
|
|
|
*
|
|
|
|
* @platform android
|
|
|
|
*/
|
|
|
|
overlayColor: ReactPropTypes.string,
|
2016-04-13 14:41:36 +00:00
|
|
|
|
|
|
|
// Android-Specific styles
|
|
|
|
borderTopLeftRadius: ReactPropTypes.number,
|
|
|
|
borderTopRightRadius: ReactPropTypes.number,
|
|
|
|
borderBottomLeftRadius: ReactPropTypes.number,
|
|
|
|
borderBottomRightRadius: ReactPropTypes.number,
|
2015-03-20 23:41:31 +00:00
|
|
|
};
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
module.exports = ImageStylePropTypes;
|