Added RCTImageSource

Summary:
public

The +[RCTConvert UIImage:] function, while convenient, is inherently limited by being synchronous, which means that it cannot be used to load remote images, and may not be efficient for local images either. It's also unable to access the bridge, which means that it cannot take advantage of the modular image-loading pipeline.

This diff introduces a new RCTImageSource class which can be used to pass image source objects over the bridge and defer loading until later.

I've also added automatic application of the `resolveAssetSource()` function based on prop type, and fixed up the image logic in NavigatorIOS and TabBarIOS.

Reviewed By: javache

Differential Revision: D2631541

fb-gh-sync-id: 6604635e8bb5394425102487f1ee7cd729321877
This commit is contained in:
Nick Lockwood
2015-12-08 03:29:08 -08:00
committed by facebook-github-bot-4
parent dcebe8cd37
commit b672294858
23 changed files with 434 additions and 276 deletions

View File

@@ -312,6 +312,12 @@ var NavigatorIOS = React.createClass({
this.navigationContext = new NavigationContext();
},
getDefaultProps: function(): Object {
return {
translucent: true,
};
},
getInitialState: function(): State {
return {
idStack: [getuid()],
@@ -591,37 +597,26 @@ var NavigatorIOS = React.createClass({
},
_routeToStackItem: function(route: Route, i: number) {
var Component = route.component;
var shouldUpdateChild = this.state.updatingAllIndicesAtOrBeyond != null &&
var {component, wrapperStyle, passProps, ...route} = route;
var {itemWrapperStyle, ...props} = this.props;
var shouldUpdateChild =
this.state.updatingAllIndicesAtOrBeyond &&
this.state.updatingAllIndicesAtOrBeyond >= i;
var Component = component;
return (
<StaticContainer key={'nav' + i} shouldUpdate={shouldUpdateChild}>
<RCTNavigatorItem
title={route.title}
{...route}
{...props}
style={[
styles.stackItem,
this.props.itemWrapperStyle,
route.wrapperStyle
]}
backButtonIcon={resolveAssetSource(route.backButtonIcon)}
backButtonTitle={route.backButtonTitle}
leftButtonIcon={resolveAssetSource(route.leftButtonIcon)}
leftButtonTitle={route.leftButtonTitle}
onNavLeftButtonTap={route.onLeftButtonPress}
rightButtonIcon={resolveAssetSource(route.rightButtonIcon)}
rightButtonTitle={route.rightButtonTitle}
onNavRightButtonTap={route.onRightButtonPress}
navigationBarHidden={this.props.navigationBarHidden}
shadowHidden={this.props.shadowHidden}
tintColor={this.props.tintColor}
barTintColor={this.props.barTintColor}
translucent={this.props.translucent !== false}
titleTextColor={this.props.titleTextColor}>
itemWrapperStyle,
wrapperStyle
]}>
<Component
navigator={this.navigator}
route={route}
{...route.passProps}
{...passProps}
/>
</RCTNavigatorItem>
</StaticContainer>

View File

@@ -16,7 +16,6 @@ var React = require('React');
var StaticContainer = require('StaticContainer.react');
var StyleSheet = require('StyleSheet');
var View = require('View');
var resolveAssetSource = require('resolveAssetSource');
var requireNativeComponent = require('requireNativeComponent');
@@ -52,10 +51,7 @@ var TabBarItemIOS = React.createClass({
/**
* A custom icon for the tab. It is ignored when a system icon is defined.
*/
icon: React.PropTypes.oneOfType([
React.PropTypes.string,
Image.propTypes.source,
]),
icon: Image.propTypes.source,
/**
* A custom icon when the tab is selected. It is ignored when a system
* icon is defined. If left empty, the icon will be tinted in blue.
@@ -101,29 +97,23 @@ var TabBarItemIOS = React.createClass({
},
render: function() {
var tabContents = null;
var {style, children, ...props} = this.props;
// if the tab has already been shown once, always continue to show it so we
// preserve state between tab transitions
if (this.state.hasBeenSelected) {
tabContents =
var tabContents =
<StaticContainer shouldUpdate={this.props.selected}>
{this.props.children}
{children}
</StaticContainer>;
} else {
tabContents = <View />;
var tabContents = <View />;
}
var badge = typeof this.props.badge === 'number' ?
'' + this.props.badge :
this.props.badge;
return (
<RCTTabBarItem
{...this.props}
icon={this.props.systemIcon || resolveAssetSource(this.props.icon)}
selectedIcon={resolveAssetSource(this.props.selectedIcon)}
badge={badge}
style={[styles.tab, this.props.style]}>
{...props}
style={[styles.tab, style]}>
{tabContents}
</RCTTabBarItem>
);