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
38 changes: 24 additions & 14 deletions android/build.gradle
Comment thread
hurali97 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ buildscript {

dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
classpath("com.android.tools.build:gradle:7.3.1")
classpath("com.diffplug.spotless:spotless-plugin-gradle:6.11.0")
classpath("com.android.tools.build:gradle:9.2.1")
classpath("com.diffplug.spotless:spotless-plugin-gradle:8.1.0")
}
}

Expand All @@ -32,7 +32,23 @@ def isNewArchitectureEnabled() {
}

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


def shouldEnableAgpFallback() {
def agpMajorVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0].toInteger()
if (agpMajorVersion <= 8) {
return true
}

def propertyVal = providers.gradleProperty("android.builtInKotlin").orNull
def isBuiltInKotlinEnabled = propertyVal != null ? propertyVal.toBoolean() : true

return !isBuiltInKotlinEnabled
}

if (shouldEnableAgpFallback()) {
apply plugin: 'kotlin-android'
}

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
Expand Down Expand Up @@ -82,17 +98,11 @@ android {
exclude "**/libreact_render*.so"
}
sourceSets.main {
java {
if (isNewArchitectureEnabled()) {
srcDirs += [
"src/fabric/java",
"${project.buildDir}/generated/source/codegen/java"
]
} else {
srcDirs += [
"src/paper/java"
]
}
if (isNewArchitectureEnabled()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update docs/docs/getting-started.mdx with minimum RN version supported of 0.75 since directories was added in agp 8.5.0 which is what RN 0.75 uses.

java.directories.add("${project.buildDir}/generated/source/codegen/java") // contains only java files
kotlin.directories.add("src/fabric/java") // contains only kotlin files
} else {
kotlin.directories.add("src/paper/java") // contains both java and kotlin files
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Comment thread
hurali97 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class InsetsChangeEvent(
surfaceId: Int,
viewTag: Int,
private val mInsets: EdgeInsets,
private val mFrame: Rect
private val mFrame: Rect,
) : Event<InsetsChangeEvent>(surfaceId, viewTag) {
override fun getEventName() = EVENT_NAME

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class SafeAreaContextPackage : BaseReactPackage() {
true,
reactModule.needsEagerInit,
reactModule.isCxxModule,
BuildConfig.IS_NEW_ARCHITECTURE_ENABLED)
BuildConfig.IS_NEW_ARCHITECTURE_ENABLED,
)
}
return ReactModuleInfoProvider { reactModuleInfoMap }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class SafeAreaProviderManager :

override fun getExportedCustomDirectEventTypeConstants() =
mutableMapOf(
InsetsChangeEvent.EVENT_NAME to mutableMapOf("registrationName" to "onInsetsChange"))
InsetsChangeEvent.EVENT_NAME to mutableMapOf("registrationName" to "onInsetsChange")
)

override fun addEventEmitters(reactContext: ThemedReactContext, view: SafeAreaProvider) {
super.addEventEmitters(reactContext, view)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ private fun getRootWindowInsetsCompatR(rootView: View): EdgeInsets? {
WindowInsets.Type.statusBars() or
WindowInsets.Type.displayCutout() or
WindowInsets.Type.navigationBars() or
WindowInsets.Type.captionBar())
?: return null
WindowInsets.Type.captionBar()
) ?: return null
return EdgeInsets(
top = insets.top.toFloat(),
right = insets.right.toFloat(),
bottom = insets.bottom.toFloat(),
left = insets.left.toFloat())
left = insets.left.toFloat(),
)
}

@RequiresApi(Build.VERSION_CODES.M)
Expand All @@ -38,7 +39,8 @@ private fun getRootWindowInsetsCompatM(rootView: View): EdgeInsets? {
// never get the keyboard offset while still working with devices that
// hide the navigation bar.
bottom = min(insets.systemWindowInsetBottom, insets.stableInsetBottom).toFloat(),
left = insets.systemWindowInsetLeft.toFloat())
left = insets.systemWindowInsetLeft.toFloat(),
)
}

private fun getRootWindowInsetsCompatBase(rootView: View): EdgeInsets? {
Expand All @@ -48,7 +50,8 @@ private fun getRootWindowInsetsCompatBase(rootView: View): EdgeInsets? {
top = visibleRect.top.toFloat(),
right = (rootView.width - visibleRect.right).toFloat(),
bottom = (rootView.height - visibleRect.bottom).toFloat(),
left = visibleRect.left.toFloat())
left = visibleRect.left.toFloat(),
)
}

private fun getRootWindowInsetsCompat(rootView: View): EdgeInsets? {
Expand Down Expand Up @@ -76,7 +79,8 @@ fun getSafeAreaInsets(view: View): EdgeInsets? {
top = max(windowInsets.top - visibleRect.top, 0f),
right = max(min(visibleRect.left + view.width - windowWidth, 0f) + windowInsets.right, 0f),
bottom = max(min(visibleRect.top + view.height - windowHeight, 0f) + windowInsets.bottom, 0f),
left = max(windowInsets.left - visibleRect.left, 0f))
left = max(windowInsets.left - visibleRect.left, 0f),
)
}

fun getFrame(rootView: ViewGroup, view: View): Rect? {
Expand All @@ -98,5 +102,6 @@ fun getFrame(rootView: ViewGroup, view: View): Rect? {
x = offset.left.toFloat(),
y = offset.top.toFloat(),
width = view.width.toFloat(),
height = view.height.toFloat())
height = view.height.toFloat(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class SafeAreaView(context: Context?) :
SafeAreaViewEdgeModes.ADDITIVE,
SafeAreaViewEdgeModes.ADDITIVE,
SafeAreaViewEdgeModes.ADDITIVE,
SafeAreaViewEdgeModes.ADDITIVE)
SafeAreaViewEdgeModes.ADDITIVE,
)
val stateWrapper = getStateWrapper()
if (stateWrapper != null) {
val map = Arguments.createMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package com.th3rdwave.safeareacontext
enum class SafeAreaViewEdgeModes {
OFF,
ADDITIVE,
MAXIMUM
MAXIMUM,
}

data class SafeAreaViewEdges(
val top: SafeAreaViewEdgeModes,
val right: SafeAreaViewEdgeModes,
val bottom: SafeAreaViewEdgeModes,
val left: SafeAreaViewEdgeModes
val left: SafeAreaViewEdgeModes,
)

class Safe
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,28 @@ class SafeAreaViewManager : ReactViewManager() {
if (propList != null) {
view.setEdges(
SafeAreaViewEdges(
top = propList.getString("top")?.let { SafeAreaViewEdgeModes.valueOf(it.uppercase()) }
top =
propList.getString("top")?.let { SafeAreaViewEdgeModes.valueOf(it.uppercase()) }
?: SafeAreaViewEdgeModes.OFF,
right =
propList.getString("right")?.let { SafeAreaViewEdgeModes.valueOf(it.uppercase()) }
?: SafeAreaViewEdgeModes.OFF,
bottom =
propList.getString("bottom")?.let {
SafeAreaViewEdgeModes.valueOf(it.uppercase())
}
?: SafeAreaViewEdgeModes.OFF,
} ?: SafeAreaViewEdgeModes.OFF,
left =
propList.getString("left")?.let { SafeAreaViewEdgeModes.valueOf(it.uppercase()) }
?: SafeAreaViewEdgeModes.OFF))
?: SafeAreaViewEdgeModes.OFF,
)
)
}
}

override fun updateState(
view: ReactViewGroup,
props: ReactStylesDiffMap?,
stateWrapper: StateWrapper?
stateWrapper: StateWrapper?,
): Any? {
(view as SafeAreaView).setStateWrapper(stateWrapper)
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package com.th3rdwave.safeareacontext

enum class SafeAreaViewMode {
PADDING,
MARGIN
MARGIN,
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class SafeAreaViewShadowNode : LayoutShadowNode() {
private fun getEdgeValue(
edgeMode: SafeAreaViewEdgeModes,
insetValue: Float,
edgeValue: Float
edgeValue: Float,
): Float {
if (edgeMode == SafeAreaViewEdgeModes.OFF) {
return edgeValue
Expand Down Expand Up @@ -139,7 +139,9 @@ class SafeAreaViewShadowNode : LayoutShadowNode() {
ViewProps.PADDING_TOP,
ViewProps.PADDING_BOTTOM,
ViewProps.PADDING_LEFT,
ViewProps.PADDING_RIGHT])
ViewProps.PADDING_RIGHT,
]
)
override fun setPaddings(index: Int, padding: Dynamic) {
val spacingType = ViewProps.PADDING_MARGIN_SPACING_TYPES[index]
mPaddings[spacingType] =
Expand All @@ -159,7 +161,9 @@ class SafeAreaViewShadowNode : LayoutShadowNode() {
ViewProps.MARGIN_TOP,
ViewProps.MARGIN_BOTTOM,
ViewProps.MARGIN_LEFT,
ViewProps.MARGIN_RIGHT])
ViewProps.MARGIN_RIGHT,
]
)
override fun setMargins(index: Int, margin: Dynamic) {
val spacingType = ViewProps.PADDING_MARGIN_SPACING_TYPES[index]
mMargins[spacingType] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ fun edgeInsetsToJavaMap(insets: EdgeInsets): Map<String, Float> {
"top" to PixelUtil.toDIPFromPixel(insets.top),
"right" to PixelUtil.toDIPFromPixel(insets.right),
"bottom" to PixelUtil.toDIPFromPixel(insets.bottom),
"left" to PixelUtil.toDIPFromPixel(insets.left))
"left" to PixelUtil.toDIPFromPixel(insets.left),
)
}

fun rectToJsMap(rect: Rect): WritableMap {
Expand All @@ -35,5 +36,6 @@ fun rectToJavaMap(rect: Rect): Map<String, Float> {
"x" to PixelUtil.toDIPFromPixel(rect.x),
"y" to PixelUtil.toDIPFromPixel(rect.y),
"width" to PixelUtil.toDIPFromPixel(rect.width),
"height" to PixelUtil.toDIPFromPixel(rect.height))
"height" to PixelUtil.toDIPFromPixel(rect.height),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ internal class InsetsChangeEvent(
@Suppress("UNUSED_PARAMETER") surfaceId: Int,
viewTag: Int,
private val mInsets: EdgeInsets,
private val mFrame: Rect
// New ctor is only available in RN 0.65.
private val mFrame: Rect,
// New ctor is only available in RN 0.65.
) : Event<InsetsChangeEvent>(viewTag) {
override fun getEventName() = EVENT_NAME

Expand Down
6 changes: 6 additions & 0 deletions example/android/gradle.properties
Comment thread
hurali97 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ bridgelessEnabled=true

# Version of Kotlin to build against.
#KOTLIN_VERSION=1.8.22
KOTLIN_VERSION=2.2.0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the example app on older AGP for now, I am more concerned about testing that than agp v9.


# Opt out of built-in kotlin and new DSL behavior that ships with AGP 9.
# Starting from AGP 10.x these opt outs will be removed.
android.builtInKotlin=false
android.newDsl=false
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Comment thread
hurali97 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
3 changes: 3 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.1",
"private": true,
"scripts": {
"postinstall": "patch-package",
"android": "react-native run-android",
"build:android": "npm run mkdist && react-native bundle --entry-file index.js --platform android --dev true --bundle-output dist/main.android.jsbundle --assets-dest dist/res",
"build:ios": "npm run mkdist && react-native bundle --entry-file index.js --platform ios --dev true --bundle-output dist/main.ios.jsbundle --assets-dest dist",
Expand All @@ -18,6 +19,8 @@
"@react-navigation/native": "^7.3.3",
"@react-navigation/native-stack": "^7.17.5",
"@react-navigation/stack": "^7.10.5",
"patch-package": "^8.0.1",
"postinstall-postinstall": "^2.1.0",
"react": "19.2.3",
"react-native": "^0.85.0",
"react-native-gesture-handler": "^3.0.2",
Expand Down
13 changes: 13 additions & 0 deletions example/patches/@react-native+gradle-plugin+0.85.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/@react-native/gradle-plugin/gradle/libs.versions.toml b/node_modules/@react-native/gradle-plugin/gradle/libs.versions.toml
index c7502fc..7f788db 100644
--- a/node_modules/@react-native/gradle-plugin/gradle/libs.versions.toml
+++ b/node_modules/@react-native/gradle-plugin/gradle/libs.versions.toml
@@ -4,7 +4,7 @@ gson = "2.8.9"
guava = "31.0.1-jre"
javapoet = "1.13.0"
junit = "4.13.2"
-kotlin = "2.1.20"
+kotlin = "2.2.0"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is required as we bumped Gradle version in example app. React Native core defaults to this kotlin version from RN 0.87.x. RN Core also defaults to Gradle version 9.4.1 from RN 0.87.x

assertj = "3.25.1"
ktfmt = "0.22.0"

Loading
Loading