mirror of
https://github.com/status-im/react-native.git
synced 2025-01-13 19:15:05 +00:00
Managed assets support for RCTConvert
Reviewed By: @nicklockwood Differential Revision: D2443130
This commit is contained in:
parent
e15035f30b
commit
f07dd70051
@ -79,7 +79,8 @@ var TabBarExample = React.createClass({
|
|||||||
{this._renderContent('#783E33', 'Red Tab', this.state.notifCount)}
|
{this._renderContent('#783E33', 'Red Tab', this.state.notifCount)}
|
||||||
</TabBarIOS.Item>
|
</TabBarIOS.Item>
|
||||||
<TabBarIOS.Item
|
<TabBarIOS.Item
|
||||||
systemIcon="more"
|
icon={require('./flux.png')}
|
||||||
|
title="More"
|
||||||
selected={this.state.selectedTab === 'greenTab'}
|
selected={this.state.selectedTab === 'greenTab'}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
BIN
Examples/UIExplorer/flux@3x.png
Normal file
BIN
Examples/UIExplorer/flux@3x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
@ -15,6 +15,7 @@ var React = require('React');
|
|||||||
var StaticContainer = require('StaticContainer.react');
|
var StaticContainer = require('StaticContainer.react');
|
||||||
var StyleSheet = require('StyleSheet');
|
var StyleSheet = require('StyleSheet');
|
||||||
var View = require('View');
|
var View = require('View');
|
||||||
|
var resolveAssetSource = require('resolveAssetSource');
|
||||||
|
|
||||||
var requireNativeComponent = require('requireNativeComponent');
|
var requireNativeComponent = require('requireNativeComponent');
|
||||||
|
|
||||||
@ -114,7 +115,8 @@ var TabBarItemIOS = React.createClass({
|
|||||||
return (
|
return (
|
||||||
<RCTTabBarItem
|
<RCTTabBarItem
|
||||||
{...this.props}
|
{...this.props}
|
||||||
icon={this.props.systemIcon || this.props.icon}
|
icon={this.props.systemIcon || resolveAssetSource(this.props.icon)}
|
||||||
|
selectedIcon={resolveAssetSource(this.props.selectedIcon)}
|
||||||
badge={badge}
|
badge={badge}
|
||||||
style={[styles.tab, this.props.style]}>
|
style={[styles.tab, this.props.style]}>
|
||||||
{tabContents}
|
{tabContents}
|
||||||
|
@ -77,10 +77,12 @@ describe('resolveAssetSource', () => {
|
|||||||
name: 'logo',
|
name: 'logo',
|
||||||
type: 'png',
|
type: 'png',
|
||||||
}, {
|
}, {
|
||||||
|
__packager_asset: true,
|
||||||
isStatic: false,
|
isStatic: false,
|
||||||
width: 100,
|
width: 100,
|
||||||
height: 200,
|
height: 200,
|
||||||
uri: 'http://10.0.0.1:8081/assets/module/a/logo.png?platform=ios&hash=5b6f00f',
|
uri: 'http://10.0.0.1:8081/assets/module/a/logo.png?platform=ios&hash=5b6f00f',
|
||||||
|
scale: 1,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -96,10 +98,12 @@ describe('resolveAssetSource', () => {
|
|||||||
name: 'logo',
|
name: 'logo',
|
||||||
type: 'png',
|
type: 'png',
|
||||||
}, {
|
}, {
|
||||||
|
__packager_asset: true,
|
||||||
isStatic: false,
|
isStatic: false,
|
||||||
width: 100,
|
width: 100,
|
||||||
height: 200,
|
height: 200,
|
||||||
uri: 'http://10.0.0.1:8081/assets/module/a/logo@2x.png?platform=ios&hash=5b6f00f',
|
uri: 'http://10.0.0.1:8081/assets/module/a/logo@2x.png?platform=ios&hash=5b6f00f',
|
||||||
|
scale: 2,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -125,6 +129,7 @@ describe('resolveAssetSource', () => {
|
|||||||
name: 'logo',
|
name: 'logo',
|
||||||
type: 'png',
|
type: 'png',
|
||||||
}, {
|
}, {
|
||||||
|
__packager_asset: true,
|
||||||
isStatic: true,
|
isStatic: true,
|
||||||
width: 100,
|
width: 100,
|
||||||
height: 200,
|
height: 200,
|
||||||
@ -153,6 +158,7 @@ describe('resolveAssetSource', () => {
|
|||||||
name: '!@Logo#1_€', // Invalid chars shouldn't get passed to native
|
name: '!@Logo#1_€', // Invalid chars shouldn't get passed to native
|
||||||
type: 'png',
|
type: 'png',
|
||||||
}, {
|
}, {
|
||||||
|
__packager_asset: true,
|
||||||
isStatic: true,
|
isStatic: true,
|
||||||
width: 100,
|
width: 100,
|
||||||
height: 200,
|
height: 200,
|
||||||
|
@ -121,13 +121,16 @@ function assetToImageSource(asset) {
|
|||||||
var devServerURL = getDevServerURL();
|
var devServerURL = getDevServerURL();
|
||||||
if (devServerURL) {
|
if (devServerURL) {
|
||||||
return {
|
return {
|
||||||
|
__packager_asset: true,
|
||||||
width: asset.width,
|
width: asset.width,
|
||||||
height: asset.height,
|
height: asset.height,
|
||||||
uri: getPathOnDevserver(devServerURL, asset),
|
uri: getPathOnDevserver(devServerURL, asset),
|
||||||
isStatic: false,
|
isStatic: false,
|
||||||
|
scale: pickScale(asset.scales, PixelRatio.get()),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
|
__packager_asset: true,
|
||||||
width: asset.width,
|
width: asset.width,
|
||||||
height: asset.height,
|
height: asset.height,
|
||||||
uri: getPathInArchive(asset),
|
uri: getPathInArchive(asset),
|
||||||
|
@ -413,11 +413,13 @@ RCT_CGSTRUCT_CONVERTER(CGAffineTransform, (@[
|
|||||||
UIImage *image;
|
UIImage *image;
|
||||||
NSString *path;
|
NSString *path;
|
||||||
CGFloat scale = 0.0;
|
CGFloat scale = 0.0;
|
||||||
|
BOOL isPackagerAsset = NO;
|
||||||
if ([json isKindOfClass:[NSString class]]) {
|
if ([json isKindOfClass:[NSString class]]) {
|
||||||
path = json;
|
path = json;
|
||||||
} else if ([json isKindOfClass:[NSDictionary class]]) {
|
} else if ([json isKindOfClass:[NSDictionary class]]) {
|
||||||
path = [self NSString:json[@"uri"]];
|
path = [self NSString:json[@"uri"]];
|
||||||
scale = [self CGFloat:json[@"scale"]];
|
scale = [self CGFloat:json[@"scale"]];
|
||||||
|
isPackagerAsset = [self BOOL:json[@"__packager_asset"]];
|
||||||
} else {
|
} else {
|
||||||
RCTLogConvertError(json, @"an image");
|
RCTLogConvertError(json, @"an image");
|
||||||
}
|
}
|
||||||
@ -459,6 +461,8 @@ RCT_CGSTRUCT_CONVERTER(CGAffineTransform, (@[
|
|||||||
|
|
||||||
} else if ([scheme isEqualToString:@"data"]) {
|
} else if ([scheme isEqualToString:@"data"]) {
|
||||||
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:URL]];
|
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:URL]];
|
||||||
|
} else if ([scheme isEqualToString:@"http"] && isPackagerAsset) {
|
||||||
|
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:URL]];
|
||||||
} else {
|
} else {
|
||||||
RCTLogConvertError(json, @"an image. Only local files or data URIs are supported");
|
RCTLogConvertError(json, @"an image. Only local files or data URIs are supported");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user