Skip to content

Commit

Permalink
feat: Fabric support (#2686)
Browse files Browse the repository at this point in the history
Hello everyone, the support for new architecture (fabric) is finally landing 🚀 . I've taken a lot of time but I've had to re-understand the whole codebase, the old arch, the new arch, and I did not want to take too many shortcuts.

This release should be mostly non breaking (except for a few well deserved props removals).
HOWEVER, this is a lot of code over a lot of time. Mistakes can happen, if you feel unsafe stick to v11 for a lil' while.

Finally this will unblock many PR (sorry for the conflicts in advance), so let's get releasing again 🔥 

If you appreciate my work please to [sponsor me](https://github.com/sponsors/Titozzz)

BREAKING CHANGE:

- If you are using custom native implementation are still possible on the old arch but many classes were moved / renamed so they will need some changes

- removed the following props: androidHardwareAccelerationDisabled (deprecated), urlPrefixesForDefaultIntent (unused)
  • Loading branch information
noproblem23 committed Apr 1, 2023
1 parent 75908b3 commit 4e349b9
Show file tree
Hide file tree
Showing 59 changed files with 7,324 additions and 5,660 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defaults: &defaults
working_directory: ~/code
docker:
- image: cimg/node:14.17.6-browsers
- image: cimg/node:18.13.0-browsers

version: 2
jobs:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/macos-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
- name: Install npm dependencies
run: yarn --frozen-lockfile
- name: Install macos dependencies
run: yarn add:macos
- name: Install Pods
run: pod install
working-directory: example/macos
Expand Down
21 changes: 7 additions & 14 deletions .github/workflows/windows-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,28 @@ on: [pull_request]
jobs:
run-windows-tests:
name: Build & run tests
runs-on: windows-2019
runs-on: windows-2022

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
name: Checkout Code

- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: '^14'
cache: 'yarn'

- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1.0.2

- name: Check node modules cache
uses: actions/cache@v1
id: yarn-cache
uses: microsoft/setup-msbuild@v1.1.3
with:
path: ./node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
vs-version: '[17.0,)'
msbuild-architecture: x64

- name: Install node modules
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn --pure-lockfile

- name: yarn build
if: steps.yarn-cache.outputs.cache-hit == 'true'
run: |
yarn build
yarn tsc
Expand Down
98 changes: 35 additions & 63 deletions README.md

Large diffs are not rendered by default.

178 changes: 66 additions & 112 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,137 +1,91 @@
buildscript {
ext.getExtOrDefault = {name ->
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeWebView_' + name]
}
import java.nio.file.Paths

// 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) {
repositories {
mavenCentral()
google()
}

dependencies {
classpath("com.android.tools.build:gradle:3.6.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}")
buildscript {
ext.safeExtGet = {prop ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : project.properties['ReactNativeWebView_' + prop]
}
} else {
repositories {
mavenCentral()
google()
gradlePluginPortal()
}

dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion')}")
classpath("com.android.tools.build:gradle:7.0.4")
}
}
}

def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['ReactNativeWebView_' + name]).toInteger()
def getExtOrIntegerDefault(prop) {
return rootProject.ext.has(prop) ? rootProject.ext.get(prop) : (project.properties['ReactNativeWebView_' + prop]).toInteger()
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
defaultConfig {
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
static def findNodeModulePath(baseDir, packageName) {
def basePath = baseDir.toPath().normalize()
// Node's module resolution algorithm searches up to the root directory,
// after which the base path will be null
while (basePath) {
def candidatePath = Paths.get(basePath.toString(), "node_modules", packageName)
if (candidatePath.toFile().exists()) {
return candidatePath.toString()
}
basePath = basePath.getParent()
}
}
lintOptions {
disable 'GradleCompatible'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
return null
}

repositories {
mavenCentral()
google()

def found = false
def defaultDir = null
def androidSourcesName = 'React Native sources'

if (rootProject.ext.has('reactNativeAndroidRoot')) {
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
} else {
defaultDir = new File(
projectDir,
'/../../../node_modules/react-native/android'
)
}

if (defaultDir.exists()) {
maven {
url defaultDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
found = true
} else {
def parentDir = rootProject.projectDir
def isNewArchitectureEnabled() {
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

1.upto(5, {
if (found) return true
parentDir = parentDir.parentFile

def androidSourcesDir = new File(
parentDir,
'node_modules/react-native'
)
apply plugin: 'com.android.library'
if (isNewArchitectureEnabled()) {
apply plugin: 'com.facebook.react'
}
apply plugin: 'kotlin-android'

def androidPrebuiltBinaryDir = new File(
parentDir,
'node_modules/react-native/android'
)
android {
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')

if (androidPrebuiltBinaryDir.exists()) {
maven {
url androidPrebuiltBinaryDir.toString()
name androidSourcesName
}
defaultConfig {
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}

logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
found = true
} else if (androidSourcesDir.exists()) {
maven {
url androidSourcesDir.toString()
name androidSourcesName
sourceSets {
main {
if (isNewArchitectureEnabled()) {
java.srcDirs += ['src/newarch']
} else {
java.srcDirs += ['src/oldarch']
}
}
}
}

logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
found = true
}
})
}
def reactNativePath = findNodeModulePath(projectDir, "react-native")
def codegenPath = findNodeModulePath(projectDir, "react-native-codegen")

if (!found) {
throw new GradleException(
"${project.name}: unable to locate React Native android sources. " +
"Ensure you have you installed React Native as a dependency in your project and try again."
)
}
repositories {
maven {
url "${reactNativePath}/android"
}
mavenCentral()
google()
}

def kotlin_version = getExtOrDefault('kotlinVersion')
def webkit_version = getExtOrDefault('webkitVersion')

dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.webkit:webkit:$webkit_version"
implementation 'com.facebook.react:react-native:+'
implementation "org.jetbrains.kotlin:kotlin-stdlib:${safeExtGet('kotlinVersion')}"
implementation "androidx.webkit:webkit:${safeExtGet('webkitVersion')}"
}

if (isNewArchitectureEnabled()) {
react {
jsRootDir = file("../src/")
libraryName = "rncwebview"
codegenJavaPackageName = "com.reactnativecommunity.webview"
codegenDir = new File(codegenPath)
reactNativeDir = new File(reactNativePath)
}
}
5 changes: 2 additions & 3 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
ReactNativeWebView_kotlinVersion=1.6.0
ReactNativeWebView_webkitVersion=1.4.0
ReactNativeWebView_compileSdkVersion=29
ReactNativeWebView_buildToolsVersion=29.0.3
ReactNativeWebView_targetSdkVersion=28
ReactNativeWebView_compileSdkVersion=31
ReactNativeWebView_targetSdkVersion=31
ReactNativeWebView_minSdkVersion=21
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.reactnativecommunity.webview;

class RNCBasicAuthCredential {
String username;
String password;

RNCBasicAuthCredential(String username, String password) {
this.username = username;
this.password = password;
}
}

0 comments on commit 4e349b9

Please sign in to comment.