From f4e1c1e8f7f0b41f830b72d41da44db307be37a4 Mon Sep 17 00:00:00 2001 From: Wojciech Lewicki Date: Thu, 26 Oct 2023 14:25:27 +0200 Subject: [PATCH] fix: proper usage of turbomodule (#1550) * fix: proper usage of turbomodule * fix: wrong value passed * Bring podspec in line with https://reactnative.dev/docs/the-new-architecture/backward-compatibility-fabric-components * revert the RNVectorIconsManager changes * Update RNVectorIcons.podspec --------- Co-authored-by: John Ferlito Co-authored-by: Joel Arvidsson --- RNVectorIcons.podspec | 42 +++++++------------ ...IconsManager.m => RNVectorIconsManager.mm} | 32 +++++++------- 2 files changed, 31 insertions(+), 43 deletions(-) rename RNVectorIconsManager/{RNVectorIconsManager.m => RNVectorIconsManager.mm} (89%) diff --git a/RNVectorIcons.podspec b/RNVectorIcons.podspec index 92652fd30..5877f53ef 100644 --- a/RNVectorIcons.podspec +++ b/RNVectorIcons.podspec @@ -1,36 +1,22 @@ 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" + # React Native Core dependency + if defined? install_modules_dependencies + install_modules_dependencies(s) end - end diff --git a/RNVectorIconsManager/RNVectorIconsManager.m b/RNVectorIconsManager/RNVectorIconsManager.mm similarity index 89% rename from RNVectorIconsManager/RNVectorIconsManager.m rename to RNVectorIconsManager/RNVectorIconsManager.mm index 02a5f4929..ff2c56582 100644 --- a/RNVectorIconsManager/RNVectorIconsManager.m +++ b/RNVectorIconsManager/RNVectorIconsManager.mm @@ -17,6 +17,7 @@ #import "RNVectorIconsSpec.h" #endif + NSString *const RNVIErrorDomain = @"org.oblador.react-native-vector-icons"; @implementation RNVectorIconsManager @@ -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"}]; @@ -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 @@ -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 @@ -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]; @@ -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); @@ -173,7 +175,7 @@ - (NSString *)createGlyphImagePathForFont:(NSString *)fontName - (std::shared_ptr)getTurboModule: (const facebook::react::ObjCTurboModule::InitParams &)params { - return std::make_shared(params); + return std::make_shared(params); } #endif