diff --git a/RNVectorIcons.xcodeproj/project.pbxproj b/RNVectorIcons.xcodeproj/project.pbxproj new file mode 100644 index 0000000..f1129bb --- /dev/null +++ b/RNVectorIcons.xcodeproj/project.pbxproj @@ -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 = ""; }; + 5DBEB16C1B18CF1500B34395 /* RNVectorIconsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNVectorIconsManager.m; sourceTree = ""; }; +/* 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 = ""; + }; + 5DBEB1511B18CEA900B34395 /* Products */ = { + isa = PBXGroup; + children = ( + 5DBEB1501B18CEA900B34395 /* libRNVectorIcons.a */, + ); + name = Products; + sourceTree = ""; + }; + 5DBEB16A1B18CF1500B34395 /* RNVectorIconsManager */ = { + isa = PBXGroup; + children = ( + 5DBEB16B1B18CF1500B34395 /* RNVectorIconsManager.h */, + 5DBEB16C1B18CF1500B34395 /* RNVectorIconsManager.m */, + ); + path = RNVectorIconsManager; + sourceTree = ""; + }; +/* 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 */; +} diff --git a/RNVectorIcons.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/RNVectorIcons.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ec91947 --- /dev/null +++ b/RNVectorIcons.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/RNVectorIcons.xcodeproj/project.xcworkspace/xcshareddata/RNVectorIcons.xccheckout b/RNVectorIcons.xcodeproj/project.xcworkspace/xcshareddata/RNVectorIcons.xccheckout new file mode 100644 index 0000000..b099528 --- /dev/null +++ b/RNVectorIcons.xcodeproj/project.xcworkspace/xcshareddata/RNVectorIcons.xccheckout @@ -0,0 +1,41 @@ + + + + + IDESourceControlProjectFavoriteDictionaryKey + + IDESourceControlProjectIdentifier + 74A596B3-C045-4AF3-B00F-76B0B71BDDBF + IDESourceControlProjectName + RNVectorIcons + IDESourceControlProjectOriginsDictionary + + A1A2C29701292F28F728A71971FE2C46E2332102 + https://github.com/oblador/react-native-vector-icons.git + + IDESourceControlProjectPath + RNVectorIcons.xcodeproj + IDESourceControlProjectRelativeInstallPathDictionary + + A1A2C29701292F28F728A71971FE2C46E2332102 + ../.. + + IDESourceControlProjectURL + https://github.com/oblador/react-native-vector-icons.git + IDESourceControlProjectVersion + 111 + IDESourceControlProjectWCCIdentifier + A1A2C29701292F28F728A71971FE2C46E2332102 + IDESourceControlProjectWCConfigurations + + + IDESourceControlRepositoryExtensionIdentifierKey + public.vcs.git + IDESourceControlWCCIdentifierKey + A1A2C29701292F28F728A71971FE2C46E2332102 + IDESourceControlWCCName + react-native-vector-icons + + + + diff --git a/RNVectorIcons.xcodeproj/project.xcworkspace/xcuserdata/joel.xcuserdatad/UserInterfaceState.xcuserstate b/RNVectorIcons.xcodeproj/project.xcworkspace/xcuserdata/joel.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..d562ef2 Binary files /dev/null and b/RNVectorIcons.xcodeproj/project.xcworkspace/xcuserdata/joel.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/RNVectorIcons.xcodeproj/xcuserdata/joel.xcuserdatad/xcschemes/RNVectorIcons.xcscheme b/RNVectorIcons.xcodeproj/xcuserdata/joel.xcuserdatad/xcschemes/RNVectorIcons.xcscheme new file mode 100644 index 0000000..916d2e8 --- /dev/null +++ b/RNVectorIcons.xcodeproj/xcuserdata/joel.xcuserdatad/xcschemes/RNVectorIcons.xcscheme @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RNVectorIcons.xcodeproj/xcuserdata/joel.xcuserdatad/xcschemes/xcschememanagement.plist b/RNVectorIcons.xcodeproj/xcuserdata/joel.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..6f25640 --- /dev/null +++ b/RNVectorIcons.xcodeproj/xcuserdata/joel.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,27 @@ + + + + + SchemeUserState + + RNVectorIcons.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 5DBEB14F1B18CEA900B34395 + + primary + + + 5DBEB15A1B18CEA900B34395 + + primary + + + + + diff --git a/RNVectorIconsManager/RNVectorIconsManager.h b/RNVectorIconsManager/RNVectorIconsManager.h new file mode 100644 index 0000000..6231c1c --- /dev/null +++ b/RNVectorIconsManager/RNVectorIconsManager.h @@ -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 + +@end diff --git a/RNVectorIconsManager/RNVectorIconsManager.m b/RNVectorIconsManager/RNVectorIconsManager.m new file mode 100644 index 0000000..295ac7e --- /dev/null +++ b/RNVectorIconsManager/RNVectorIconsManager.m @@ -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 diff --git a/lib/create-icon-set.js b/lib/create-icon-set.js index 651662a..7989a92 100644 --- a/lib/create-icon-set.js +++ b/lib/create-icon-set.js @@ -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;