Skip to content

Commit

Permalink
fix: proper usage of turbomodule (#1550)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Joel Arvidsson <[email protected]>
  • Loading branch information
3 people authored Oct 26, 2023
1 parent f2d1b73 commit f4e1c1e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 43 deletions.
42 changes: 14 additions & 28 deletions RNVectorIcons.podspec
Original file line number Diff line number Diff line change
@@ -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" => "[email protected]" }
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
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

0 comments on commit f4e1c1e

Please sign in to comment.