WIP: Support for getting image sources and native TabBarIOS.Item.

This commit is contained in:
Joel Arvidsson
2015-05-29 20:15:25 +02:00
parent 1fde40da10
commit 77f2e38a38
9 changed files with 531 additions and 1 deletions

View File

@@ -0,0 +1,264 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
5DBEB17C1B18CFF400B34395 /* RNVectorIconsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DBEB16C1B18CF1500B34395 /* RNVectorIconsManager.m */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
5DBEB14E1B18CEA900B34395 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "include/$(PRODUCT_NAME)";
dstSubfolderSpec = 16;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
5DBEB1501B18CEA900B34395 /* libRNVectorIcons.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNVectorIcons.a; sourceTree = BUILT_PRODUCTS_DIR; };
5DBEB16B1B18CF1500B34395 /* RNVectorIconsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNVectorIconsManager.h; sourceTree = "<group>"; };
5DBEB16C1B18CF1500B34395 /* RNVectorIconsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNVectorIconsManager.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
5DBEB14D1B18CEA900B34395 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
5DBEB1471B18CEA900B34395 = {
isa = PBXGroup;
children = (
5DBEB16A1B18CF1500B34395 /* RNVectorIconsManager */,
5DBEB1511B18CEA900B34395 /* Products */,
);
sourceTree = "<group>";
};
5DBEB1511B18CEA900B34395 /* Products */ = {
isa = PBXGroup;
children = (
5DBEB1501B18CEA900B34395 /* libRNVectorIcons.a */,
);
name = Products;
sourceTree = "<group>";
};
5DBEB16A1B18CF1500B34395 /* RNVectorIconsManager */ = {
isa = PBXGroup;
children = (
5DBEB16B1B18CF1500B34395 /* RNVectorIconsManager.h */,
5DBEB16C1B18CF1500B34395 /* RNVectorIconsManager.m */,
);
path = RNVectorIconsManager;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
5DBEB14F1B18CEA900B34395 /* RNVectorIcons */ = {
isa = PBXNativeTarget;
buildConfigurationList = 5DBEB1641B18CEA900B34395 /* Build configuration list for PBXNativeTarget "RNVectorIcons" */;
buildPhases = (
5DBEB14C1B18CEA900B34395 /* Sources */,
5DBEB14D1B18CEA900B34395 /* Frameworks */,
5DBEB14E1B18CEA900B34395 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = RNVectorIcons;
productName = RNVectorIcons;
productReference = 5DBEB1501B18CEA900B34395 /* libRNVectorIcons.a */;
productType = "com.apple.product-type.library.static";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
5DBEB1481B18CEA900B34395 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0630;
ORGANIZATIONNAME = "Joel Arvidsson";
TargetAttributes = {
5DBEB14F1B18CEA900B34395 = {
CreatedOnToolsVersion = 6.3.2;
};
};
};
buildConfigurationList = 5DBEB14B1B18CEA900B34395 /* Build configuration list for PBXProject "RNVectorIcons" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = 5DBEB1471B18CEA900B34395;
productRefGroup = 5DBEB1511B18CEA900B34395 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
5DBEB14F1B18CEA900B34395 /* RNVectorIcons */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
5DBEB14C1B18CEA900B34395 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5DBEB17C1B18CFF400B34395 /* RNVectorIconsManager.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
5DBEB1621B18CEA900B34395 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
name = Debug;
};
5DBEB1631B18CEA900B34395 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
5DBEB1651B18CEA900B34395 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../React/**",
"$(SRCROOT)/../react-native/React/**",
"$(SRCROOT)/node_modules/react-native/React/**",
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
name = Debug;
};
5DBEB1661B18CEA900B34395 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../React/**",
"$(SRCROOT)/../react-native/React/**",
"$(SRCROOT)/node_modules/react-native/React/**",
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
5DBEB14B1B18CEA900B34395 /* Build configuration list for PBXProject "RNVectorIcons" */ = {
isa = XCConfigurationList;
buildConfigurations = (
5DBEB1621B18CEA900B34395 /* Debug */,
5DBEB1631B18CEA900B34395 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
5DBEB1641B18CEA900B34395 /* Build configuration list for PBXNativeTarget "RNVectorIcons" */ = {
isa = XCConfigurationList;
buildConfigurations = (
5DBEB1651B18CEA900B34395 /* Debug */,
5DBEB1661B18CEA900B34395 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 5DBEB1481B18CEA900B34395 /* Project object */;
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:RNVectorIcons.xcodeproj">
</FileRef>
</Workspace>

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>74A596B3-C045-4AF3-B00F-76B0B71BDDBF</string>
<key>IDESourceControlProjectName</key>
<string>RNVectorIcons</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>A1A2C29701292F28F728A71971FE2C46E2332102</key>
<string>https://github.com/oblador/react-native-vector-icons.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>RNVectorIcons.xcodeproj</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>A1A2C29701292F28F728A71971FE2C46E2332102</key>
<string>../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>https://github.com/oblador/react-native-vector-icons.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>111</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>A1A2C29701292F28F728A71971FE2C46E2332102</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>A1A2C29701292F28F728A71971FE2C46E2332102</string>
<key>IDESourceControlWCCName</key>
<string>react-native-vector-icons</string>
</dict>
</array>
</dict>
</plist>

View File

@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0630"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5DBEB14F1B18CEA900B34395"
BuildableName = "libRNVectorIcons.a"
BlueprintName = "RNVectorIcons"
ReferencedContainer = "container:RNVectorIcons.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5DBEB15A1B18CEA900B34395"
BuildableName = "RNVectorIconsTests.xctest"
BlueprintName = "RNVectorIconsTests"
ReferencedContainer = "container:RNVectorIcons.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5DBEB15A1B18CEA900B34395"
BuildableName = "RNVectorIconsTests.xctest"
BlueprintName = "RNVectorIconsTests"
ReferencedContainer = "container:RNVectorIcons.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5DBEB14F1B18CEA900B34395"
BuildableName = "libRNVectorIcons.a"
BlueprintName = "RNVectorIcons"
ReferencedContainer = "container:RNVectorIcons.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5DBEB14F1B18CEA900B34395"
BuildableName = "libRNVectorIcons.a"
BlueprintName = "RNVectorIcons"
ReferencedContainer = "container:RNVectorIcons.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5DBEB14F1B18CEA900B34395"
BuildableName = "libRNVectorIcons.a"
BlueprintName = "RNVectorIcons"
ReferencedContainer = "container:RNVectorIcons.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>RNVectorIcons.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>5DBEB14F1B18CEA900B34395</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>5DBEB15A1B18CEA900B34395</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,14 @@
//
// RNVectorIconsManager.h
// RNVectorIconsManager
//
// Created by Joel Arvidsson on 2015-05-29.
// Copyright (c) 2015 Joel Arvidsson. All rights reserved.
//
#import "RCTBridgeModule.h"
#import "RCTLog.h"
@interface RNVectorIconsManager : NSObject <RCTBridgeModule>
@end

View File

@@ -0,0 +1,42 @@
//
// RNVectorIconsManager.m
// RNVectorIconsManager
//
// Created by Joel Arvidsson on 2015-05-29.
// Copyright (c) 2015 Joel Arvidsson. All rights reserved.
//
#import "RNVectorIconsManager.h"
#import "RCTConvert.h"
#import "RCTBridge.h"
#import "RCTUtils.h"
@implementation RNVectorIconsManager
@synthesize bridge = _bridge;
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(getImageForFont:(NSString*)fontName withGlyph:(NSString*)glyph withFontSize:(CGFloat)fontSize callback:(RCTResponseSenderBlock)callback){
UIFont *font = [UIFont fontWithName:fontName size:fontSize];
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:glyph attributes:@{NSFontAttributeName: font}];
CGSize iconSize = [attributedString size];
CGSize imageSize = CGSizeMake(fontSize, fontSize);
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0);
//Center in case height doesn't equal fontSize
CGRect centeredRect = CGRectMake((imageSize.width - iconSize.width) / 2.0, (imageSize.height - iconSize.height) / 2.0, iconSize.width, iconSize.height);
[attributedString drawInRect:centeredRect];
UIImage *iconImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//Encode as base64 to be able to use it with React
NSData *imageData = UIImagePNGRepresentation(iconImage);
NSString *imageDataBase64encodedString = [imageData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
callback(@[[NSNull null], [NSString stringWithFormat:@"data:image/png;base64,%@", imageDataBase64encodedString]]);
}
@end

View File

@@ -10,6 +10,9 @@ var {
Text,
StyleSheet,
} = React;
var NativeModules = require('NativeModules');
var RNVectorIconsManager = NativeModules.RNVectorIconsManager;
var invariant = require('invariant');
var merge = require('merge');
var flattenStyle = require('flattenStyle');
var ViewStylePropTypes = require('ViewStylePropTypes');
@@ -30,7 +33,7 @@ function createIconSet(glyphMap, fontFamily) {
}
});
return React.createClass({
var Icon = React.createClass({
propTypes:{
name: React.PropTypes.oneOf(Object.keys(glyphMap)).isRequired,
size: React.PropTypes.number,
@@ -72,6 +75,28 @@ function createIconSet(glyphMap, fontFamily) {
);
}
});
Icon.getImageSource = function(name, size, callback) {
invariant(RNVectorIconsManager, 'RNVectorIconsManager not available, did you add the library to your project and link with libRNVectorIcons.a?');
var glyph = glyphMap[name] || '?';
if(typeof glyph === 'number') {
glyph = String.fromCharCode(glyph);
}
return new Promise((resolve, reject) => {
RNVectorIconsManager.getImageForFont(fontFamily, glyph, size || 12, function(err, image) {
callback && callback(err, image);
if (err) {
reject(err);
} else {
resolve(image);
}
});
});
};
return Icon;
};
module.exports = createIconSet;