Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,6 @@ body:

Providing as much information as possible greatly helps us with reproducting the issues.

- type: dropdown
id: architecture
attributes:
label: Architecture
description: What React Native architecture your application is running on?
options:
- Paper (Old Architecture)
- Fabric (New Architecture)

- type: dropdown
id: build-type
attributes:
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/build-android.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ subst W: "%GITHUB_WORKSPACE%\example" || exit /b 1
robocopy W:\node_modules\react-native-test-app W:\r /MIR /NFL /NDL /NJH /NJS /NP
if %ERRORLEVEL% GEQ 8 exit /b %ERRORLEVEL%
cd /D W:\android || exit /b 1
call gradlew.bat assembleDebug -PnewArchEnabled=%1
call gradlew.bat assembleDebug
6 changes: 2 additions & 4 deletions .github/scripts/build-android.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail

new_arch="${1:-false}"

if [[ "${RUNNER_OS:-}" == "Windows" ]]; then
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cmd //c "$(cygpath -w "$script_dir/build-android.cmd")" "$new_arch"
cmd //c "$(cygpath -w "$script_dir/build-android.cmd")"
else
cd example/android
./gradlew assembleDebug -PnewArchEnabled="${new_arch}"
./gradlew assembleDebug
fi
4 changes: 2 additions & 2 deletions .github/workflows/android-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
run: yarn install
working-directory: example

- name: Build android example app with new arch disabled
run: ./gradlew assembleRelease -PnewArchEnabled=true
- name: Build Android example app
run: ./gradlew assembleRelease
working-directory: example/android

- name: Upload APK to Release
Expand Down
74 changes: 35 additions & 39 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,32 @@ on:
branches:
- main
paths:
- '.github/scripts/build-android.*'
- '.github/workflows/android.yml'
- 'android/**'
- 'common/**'
- 'example/android/**'
- 'example/package.json'
- 'example/react-native.config.js'
- 'example/yarn.lock'
- 'package.json'
- 'react-native.config.js'
- 'src/specs/**'
- 'yarn.lock'
pull_request:
paths:
- '.github/scripts/build-android.*'
- '.github/workflows/android.yml'
- 'android/**'
- 'common/**'
- 'example/android/**'
- 'example/package.json'
- 'example/react-native.config.js'
- 'example/yarn.lock'
- 'package.json'
- 'react-native.config.js'
- 'src/specs/**'
- 'yarn.lock'

jobs:
android-build:
Expand All @@ -23,6 +39,12 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
react-native: [0.87.0]
react: [19.2.8]
include:
- os: ubuntu-latest
react-native: 0.82.0
react: 19.1.1
defaults:
run:
shell: bash
Expand All @@ -43,45 +65,19 @@ jobs:
path: |
node_modules
*/*/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-rn-${{ matrix.react-native }}-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
run: yarn install
- name: Install example app dependencies
run: yarn install
working-directory: example
- name: Build android example app with new arch disabled
run: ./.github/scripts/build-android.sh false
android-build-fabric:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- name: Use Node.js 22.13.0
uses: actions/setup-node@v1
with:
node-version: 22.13.0
- uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17'
- name: Restore yarn workspaces
id: yarn-cache
uses: actions/cache@v3
with:
path: |
node_modules
*/*/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
run: yarn install
- name: Install example app dependencies
run: yarn install
- name: Install React Native ${{ matrix.react-native }} example dependencies
run: yarn add --exact "react@${{ matrix.react }}" "react-native@${{ matrix.react-native }}"
working-directory: example
- name: Build android example app with new arch enabled
run: ./.github/scripts/build-android.sh true
- name: Use RN 0.82-compatible Gradle
if: matrix.react-native == '0.82.0'
run: sed -i 's/gradle-9.4.1-bin.zip/gradle-9.0.0-bin.zip/' example/android/gradle/wrapper/gradle-wrapper.properties
- name: Build Android example app
if: matrix.react-native != '0.82.0'
run: ./.github/scripts/build-android.sh
- name: Compile library against the RN floor
if: matrix.react-native == '0.82.0'
run: ./gradlew :react-native-safe-area-context:compileDebugKotlin
working-directory: example/android
49 changes: 22 additions & 27 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,31 @@ on:
- main
paths:
- '.github/workflows/ios.yml'
- 'ios/**'
- 'common/**'
- 'example/ios/**'
- 'example/package.json'
- 'example/react-native.config.js'
- 'example/yarn.lock'
- 'ios/**'
- 'package.json'
- 'react-native-safe-area-context.podspec'
- 'react-native.config.js'
- 'src/specs/**'
- 'yarn.lock'
pull_request:
paths:
- '.github/workflows/ios.yml'
- 'ios/**'
- 'common/**'
- 'example/ios/**'
- 'example/package.json'
- 'example/react-native.config.js'
- 'example/yarn.lock'
- 'ios/**'
- 'package.json'
- 'react-native-safe-area-context.podspec'
- 'react-native.config.js'
- 'src/specs/**'
- 'yarn.lock'
jobs:
ios-build:
runs-on: macos-latest
Expand All @@ -34,32 +50,11 @@ jobs:
- name: Install example app dependencies
run: yarn install
working-directory: example
- name: Install pods
run: RCT_NEW_ARCH_ENABLED=0 npx pod-install
working-directory: example/ios
- name: Build ios example app
run: xcodebuild -scheme ReactTestApp -workspace RNSACExample.xcworkspace ONLY_ACTIVE_ARCH=NO -sdk iphonesimulator -configuration Debug
working-directory: example/ios
ios-build-fabric:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 22.13.0
uses: actions/setup-node@v1
with:
node-version: 22.13.0
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
working-directory: example
bundler-cache: true
- name: Install dependencies
run: yarn install
- name: Install example app dependencies
run: yarn install
- name: Validate podspec
run: bundle exec pod lib lint ../react-native-safe-area-context.podspec --quick --allow-warnings --no-ansi
working-directory: example
- name: Install pods for new arch
run: RCT_NEW_ARCH_ENABLED=1 npx pod-install
- name: Install pods
run: npx pod-install
working-directory: example/ios
- name: Build ios example app
run: xcodebuild -scheme ReactTestApp -workspace RNSACExample.xcworkspace ONLY_ACTIVE_ARCH=NO -sdk iphonesimulator -configuration Debug
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,11 @@ jobs:
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
run: yarn install
- name: Install example app dependencies
run: yarn install
working-directory: example
- name: Run tests
run: yarn test
- name: Typecheck example app
run: yarn typecheck
working-directory: example
27 changes: 1 addition & 26 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,8 @@ def getExtOrDefault(name, defaultValue) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : defaultValue
}

def isNewArchitectureEnabled() {
// To opt-in for the New Architecture, you can either:
// - Set `newArchEnabled` to true inside the `gradle.properties` file
// - Invoke gradle with `-newArchEnabled=true`
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

apply plugin: 'com.android.library'
apply plugin: 'com.facebook.react'


def shouldEnableAgpFallback() {
Expand All @@ -50,17 +43,10 @@ if (shouldEnableAgpFallback()) {
apply plugin: 'kotlin-android'
}

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
}

android {
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
namespace "com.th3rdwave.safeareacontext"
buildFeatures {
buildConfig true
}
}

compileSdkVersion getExtOrDefault('compileSdkVersion', 30)
Expand All @@ -79,8 +65,6 @@ android {
targetSdkVersion getExtOrDefault('targetSdkVersion', 28)
versionCode 1
versionName "1.0"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

ndk {
abiFilters (*reactNativeArchitectures())
}
Expand All @@ -97,15 +81,6 @@ android {
// are only allowed to specify exclude patterns)
exclude "**/libreact_render*.so"
}
sourceSets.main {
if (isNewArchitectureEnabled()) {
java.directories.add("${project.buildDir}/generated/source/codegen/java") // contains only java files
kotlin.directories.add("src/fabric/java") // contains only kotlin files
} else {
java.directories.add("src/paper/java") // contains both java and kotlin files
kotlin.directories.add("src/paper/java")
}
}
}

def reactNativeArchitectures() {
Expand Down
4 changes: 1 addition & 3 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.th3rdwave.safeareacontext">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import com.facebook.react.module.model.ReactModuleInfo
import com.facebook.react.module.model.ReactModuleInfoProvider
import com.facebook.react.uimanager.ViewManager

// Fool autolinking for older versions that do not support BaseReactPackage.
// public class SafeAreaContextPackage implements ReactPackage {
class SafeAreaContextPackage : BaseReactPackage() {
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
return when (name) {
Expand All @@ -30,7 +28,7 @@ class SafeAreaContextPackage : BaseReactPackage() {
true,
reactModule.needsEagerInit,
reactModule.isCxxModule,
BuildConfig.IS_NEW_ARCHITECTURE_ENABLED,
true,
)
}
return ReactModuleInfoProvider { reactModuleInfoMap }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.UIManagerHelper
import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.common.UIManagerType
import com.facebook.react.viewmanagers.RNCSafeAreaProviderManagerDelegate
import com.facebook.react.viewmanagers.RNCSafeAreaProviderManagerInterface

Expand Down Expand Up @@ -37,6 +38,6 @@ class SafeAreaProviderManager :
private fun handleOnInsetsChange(view: SafeAreaProvider, insets: EdgeInsets, frame: Rect) {
val reactContext = view.context as ReactContext
val reactTag = view.id
UIManagerHelper.getEventDispatcherForReactTag(reactContext, reactTag)
UIManagerHelper.getEventDispatcher(reactContext, UIManagerType.FABRIC)
?.dispatchEvent(InsetsChangeEvent(getSurfaceId(reactContext), reactTag, insets, frame))
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import android.view.View
import android.view.ViewTreeObserver
import com.facebook.react.bridge.Arguments
import com.facebook.react.uimanager.StateWrapper
import com.facebook.react.uimanager.UIManagerModule
import com.facebook.react.views.view.ReactViewGroup

class SafeAreaView(context: Context?) :
ReactViewGroup(context), ViewTreeObserver.OnPreDrawListener {
private var mMode = SafeAreaViewMode.PADDING
private var mInsets: EdgeInsets? = null
private var mEdges: SafeAreaViewEdges? = null
private var mProviderView: View? = null
private var mStateWrapper: StateWrapper? = null

Expand All @@ -27,40 +24,15 @@ class SafeAreaView(context: Context?) :
private fun updateInsets() {
val insets = mInsets
if (insets != null) {
val edges =
mEdges
?: SafeAreaViewEdges(
SafeAreaViewEdgeModes.ADDITIVE,
SafeAreaViewEdgeModes.ADDITIVE,
SafeAreaViewEdgeModes.ADDITIVE,
SafeAreaViewEdgeModes.ADDITIVE,
)
val stateWrapper = getStateWrapper()
if (stateWrapper != null) {
val map = Arguments.createMap()
map.putMap("insets", edgeInsetsToJsMap(insets))
stateWrapper.updateState(map)
} else {
val localData = SafeAreaViewLocalData(insets = insets, mode = mMode, edges = edges)
val reactContext = getReactContext(this)
val uiManager = reactContext.getNativeModule(UIManagerModule::class.java)
if (uiManager != null) {
uiManager.setViewLocalData(id, localData)
}
}
}
}

fun setMode(mode: SafeAreaViewMode) {
mMode = mode
updateInsets()
}

fun setEdges(edges: SafeAreaViewEdges) {
mEdges = edges
updateInsets()
}

private fun maybeUpdateInsets(): Boolean {
val providerView = mProviderView ?: return false
val edgeInsets = getSafeAreaInsets(providerView) ?: return false
Expand Down
Loading
Loading