Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: proper usage of turbomodule #1550

Merged
merged 5 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 13 additions & 29 deletions RNVectorIcons.podspec
Original file line number Diff line number Diff line change
@@ -1,36 +1,20 @@
require 'json'
version = JSON.parse(File.read('package.json'))["version"]

folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
package = JSON.parse(File.read(File.join(__dir__, "package.json")))

Pod::Spec.new do |s|

s.name = "RNVectorIcons"
s.version = version
s.summary = "Customizable Icons for React Native with support for NavBar/TabBar, image source and full styling."
s.homepage = "https://github.com/oblador/react-native-vector-icons"
s.license = "MIT"
s.author = { "Joel Arvidsson" => "joel@oblador.se" }
s.platforms = { :ios => "9.0", :tvos => "9.0" }
s.source = { :git => "https://github.com/oblador/react-native-vector-icons.git", :tag => "v#{s.version}" }
s.source_files = 'RNVectorIconsManager/**/*.{h,m}'
s.version = package["version"]
s.summary = package["description"]
s.description = package["description"]
s.homepage = package["homepage"]
s.license = package["license"]
s.author = { package["author"]["name"] => package["author"]["email"] }
s.platforms = { :ios => "12.0", :tvos => "9.0" }
s.source = { :git => package["repository"]["url"], :tag => "v#{s.version}" }

s.source_files = 'RNVectorIconsManager/**/*.{h,m,mm,swift}'
s.resources = "Fonts/*.ttf"
s.preserve_paths = "**/*.js"
s.dependency 'React-Core'

# This guard prevent to install the dependencies when we run `pod install` in the old architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}

s.dependency "React-Codegen"
s.dependency "RCT-Folly"
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
end

# React Native Core dependency
install_modules_dependencies(s)
oblador marked this conversation as resolved.
Show resolved Hide resolved
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import "RNVectorIconsSpec.h"
#endif


NSString *const RNVIErrorDomain = @"org.oblador.react-native-vector-icons";

@implementation RNVectorIconsManager
Expand Down Expand Up @@ -79,18 +80,19 @@ - (BOOL)createAndSaveGlyphImage:(NSString *)glyph withFont:(UIFont *)font
- (NSString *)createGlyphImagePathForFont:(NSString *)fontName
withGlyph:(NSString *)glyph
withFontSize:(CGFloat)fontSize
withColor:(UIColor *)color
withColor:(double)color
withError:(NSError **)error
{
UIColor *parsedColor = [RCTConvert UIColor:@(color)];
UIFont *font = [UIFont fontWithName:fontName size:fontSize];
NSString *filePath = [self generateFilePath:glyph withFontName:fontName
withFontSize:fontSize
withColor:color
withColor:parsedColor
withExtraIdentifier:@""];

BOOL success = [self createAndSaveGlyphImage:glyph withFont:font
withFilePath:filePath
withColor:color];
withColor:parsedColor];

if (!success) {
*error = [NSError errorWithDomain:RNVIErrorDomain code:RNVIGenericError userInfo:@{NSLocalizedDescriptionKey: @"Failed to write rendered icon image"}];
Expand All @@ -101,11 +103,11 @@ - (NSString *)createGlyphImagePathForFont:(NSString *)fontName

RCT_EXPORT_METHOD(
getImageForFont:(NSString *)fontName
withGlyph:(NSString *)glyph
withFontSize:(CGFloat)fontSize
withColor:(UIColor *)color
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject
glyph:(NSString *)glyph
fontSize:(CGFloat)fontSize
color:(double)color
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject
) {
NSError *error = nil;
NSString *filePath = [self createGlyphImagePathForFont:fontName
Expand All @@ -122,9 +124,9 @@ - (NSString *)createGlyphImagePathForFont:(NSString *)fontName

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(
getImageForFontSync:(NSString *)fontName
withGlyph:(NSString *)glyph
withFontSize:(CGFloat)fontSize
withColor:(UIColor *)color
glyph:(NSString *)glyph
fontSize:(CGFloat)fontSize
color:(double)color
) {
NSError *error = nil;
return [self createGlyphImagePathForFont:fontName
Expand All @@ -137,8 +139,8 @@ - (NSString *)createGlyphImagePathForFont:(NSString *)fontName
RCT_EXPORT_METHOD(
loadFontWithFileName:(NSString *)fontFileName
extension:(NSString *)extension
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject
) {
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSURL *fontURL = [bundle URLForResource:fontFileName withExtension:extension];
Expand All @@ -155,7 +157,7 @@ - (NSString *)createGlyphImagePathForFont:(NSString *)fontName
resolve(nil);
} else {
NSString *errorMessage = [NSString stringWithFormat:@"Font '%@' failed to load", fontFileName];
        reject(@"font_load_failed", errorMessage, error);
reject(@"font_load_failed", errorMessage, error);
}
} else {
resolve(nil);
Expand All @@ -173,7 +175,7 @@ - (NSString *)createGlyphImagePathForFont:(NSString *)fontName
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared<facebook::react::RNVectorIconsSpecJSI>(params);
return std::make_shared<facebook::react::NativeRNVectorIconsSpecJSI>(params);
}
#endif

Expand Down