Skip to content

Commit

Permalink
Migrate to new architecture (#1468)
Browse files Browse the repository at this point in the history
  • Loading branch information
oblador committed Oct 30, 2022
1 parent 91eefe3 commit 02e6cbc
Show file tree
Hide file tree
Showing 16 changed files with 324 additions and 219 deletions.
9 changes: 9 additions & 0 deletions Examples/IconExplorer/ios/.xcode.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
# To customize your local environment, you can create an `.xcode.env.local`
# file that is not versioned.

# Set up asdf-vm if present
if [[ -f "$HOME/.asdf/asdf.sh" ]]; then
# shellcheck source=/dev/null
. "$HOME/.asdf/asdf.sh"
elif [[ -x "$(command -v brew)" && -f "$(brew --prefix asdf)/asdf.sh" ]]; then
# shellcheck source=/dev/null
. "$(brew --prefix asdf)/asdf.sh"
fi

# NODE_BINARY variable contains the PATH to the node executable.
#
# Customize the NODE_BINARY variable here.
Expand Down
2 changes: 1 addition & 1 deletion Examples/IconExplorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"postinstall": "pwd && ./scripts/postinstall.sh",
"postinstall": "DESTINATION='node_modules/react-native-vector-icons' LIB_FILE=`cd ../.. && echo \\`pwd\\`/\\`npm pack\\`` && (rm -rf $DESTINATION || true) && mkdir $DESTINATION && tar -xvzf $LIB_FILE -C $DESTINATION --strip-components 1 && rm $LIB_FILE",
"test": "jest"
},
"dependencies": {
Expand Down
4 changes: 0 additions & 4 deletions Examples/IconExplorer/scripts/postinstall.sh

This file was deleted.

17 changes: 17 additions & 0 deletions RNVectorIcons.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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'

Pod::Spec.new do |s|

s.name = "RNVectorIcons"
Expand All @@ -16,4 +18,19 @@ Pod::Spec.new do |s|
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

end
8 changes: 0 additions & 8 deletions RNVectorIconsManager/RNVectorIconsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,8 @@
// Copyright (c) 2015 Joel Arvidsson. All rights reserved.
//

#if __has_include(<React/RCTBridgeModule.h>)
#import <React/RCTBridgeModule.h>
#else // Compatibility for RN version < 0.40
#import "RCTBridgeModule.h"
#endif
#if __has_include(<React/RCTLog.h>)
#import <React/RCTLog.h>
#else // Compatibility for RN version < 0.40
#import "RCTLog.h"
#endif

FOUNDATION_EXPORT NSString *const RNVIErrorDomain;

Expand Down
29 changes: 13 additions & 16 deletions RNVectorIconsManager/RNVectorIconsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,21 @@

#import "RNVectorIconsManager.h"
#import <CoreText/CoreText.h>
#if __has_include(<React/RCTConvert.h>)
#import <React/RCTConvert.h>
#else // Compatibility for RN version < 0.40
#import "RCTConvert.h"
#endif
#if __has_include(<React/RCTBridge.h>)
#import <React/RCTBridge.h>
#else // Compatibility for RN version < 0.40
#import "RCTBridge.h"
#endif
#if __has_include(<React/RCTUtils.h>)
#import <React/RCTUtils.h>
#else // Compatibility for RN version < 0.40
#import "RCTUtils.h"
#endif
#if __has_include(<React/RCTFont.h>)
#import <React/RCTFont.h>
#else // Compatibility for RN version < 0.40
#import "RCTFont.h"
// Thanks to this guard, we won't import this header when we build for the old architecture.
#ifdef RCT_NEW_ARCH_ENABLED
#import "RNVectorIconsSpec.h"
#endif

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

@implementation RNVectorIconsManager

@synthesize bridge = _bridge;
RCT_EXPORT_MODULE();
RCT_EXPORT_MODULE(RNVectorIcons);

- (NSString *)hexStringFromColor:(UIColor *)color
{
Expand Down Expand Up @@ -179,4 +167,13 @@ - (NSString *)createGlyphImagePathForFont:(NSString *)fontName
}
}

// Thanks to this guard, we won't compile this code when we build for the old architecture.
#ifdef RCT_NEW_ARCH_ENABLED
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared<facebook::react::RNVectorIconsSpecJSI>(params);
}
#endif

@end
60 changes: 32 additions & 28 deletions android/build.gradle
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
if (project == rootProject) {
ext.safeExtGet = {prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
repositories {
mavenCentral()
google()
google()
gradlePluginPortal()
}

dependencies {
classpath("com.android.tools.build:gradle:3.5.3")
classpath("com.android.tools.build:gradle:7.0.4")
}
}
}

apply plugin: 'com.android.library'

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
def isNewArchitectureEnabled() {
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

apply plugin: 'com.android.library'
if (isNewArchitectureEnabled()) {
apply plugin: 'com.facebook.react'
}

android {
compileSdkVersion safeExtGet('compileSdkVersion', 28)

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 28)
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
compileSdkVersion safeExtGet('compileSdkVersion', 31)

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 21)
targetSdkVersion safeExtGet('targetSdkVersion', 31)
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString())
}
sourceSets {
main {
if (isNewArchitectureEnabled()) {
java.srcDirs += ['src/newarch']
} else {
java.srcDirs += ['src/oldarch']
}
}
}
}

repositories {
mavenLocal()
google()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
url "$projectDir/../node_modules/react-native/android"
}
mavenCentral()
google()
}

dependencies {
implementation "com.facebook.react:react-native:+"
implementation 'com.facebook.react:react-native:+'
}
121 changes: 0 additions & 121 deletions android/src/main/java/com/oblador/vectoricons/VectorIconsModule.java

This file was deleted.

0 comments on commit 02e6cbc

Please sign in to comment.