Skip to content

Commit

Permalink
[ios][android] Update react-native-screens to 3.18.0 (#19383)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsapeta committed Oct 5, 2022
1 parent 7a9e510 commit dee909a
Show file tree
Hide file tree
Showing 87 changed files with 644 additions and 443 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,7 @@ Package-specific changes not released in any SDK will be added here just before
- Updated `react-native-webview` from `11.23.0` to `11.23.1`. ([#19375](https://github.com/expo/expo/pull/19375) by [@aleqsio](https://github.com/aleqsio))
- Updated `react-native-gesture-handler` from `2.5.0` to `2.7.0`. ([#19362](https://github.com/expo/expo/pull/19362) by [@tsapeta](https://github.com/tsapeta))
- Updated `@react-native-picker/picker` from `2.4.2` to `2.4.6`. ([#19390](https://github.com/expo/expo/pull/19390) by [@aleqsio](https://github.com/aleqsio))
- Updated `react-native-screens` from `3.15.0` to `3.18.0`. ([#19383](https://github.com/expo/expo/pull/19383) by [@tsapeta](https://github.com/tsapeta))

### 🛠 Breaking changes

Expand Down
5 changes: 0 additions & 5 deletions android/expoview/build.gradle
Expand Up @@ -392,11 +392,6 @@ dependencies {
}
}

// react-native-screens
api 'androidx.fragment:fragment:1.2.2'
api 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
api 'com.google.android.material:material:1.1.0'

api 'com.google.firebase:firebase-core:17.2.3'
api 'com.google.firebase:firebase-messaging:22.0.0'
api 'com.google.maps.android:android-maps-utils:0.5'
Expand Down
Expand Up @@ -9,6 +9,7 @@ import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ViewManager
import com.shopify.reactnative.flash_list.ReactNativeFlashListPackage
import com.shopify.reactnative.skia.RNSkiaPackage
import com.swmansion.rnscreens.RNScreensPackage
import com.swmansion.gesturehandler.RNGestureHandlerPackage
import com.swmansion.gesturehandler.react.RNGestureHandlerModule
import expo.modules.adapters.react.ReactModuleRegistryProvider
Expand Down Expand Up @@ -43,7 +44,6 @@ import versioned.host.exp.exponent.modules.api.components.webview.RNCWebViewPack
import versioned.host.exp.exponent.modules.api.netinfo.NetInfoModule
import versioned.host.exp.exponent.modules.api.notifications.NotificationsModule
import versioned.host.exp.exponent.modules.api.safeareacontext.SafeAreaContextPackage
import versioned.host.exp.exponent.modules.api.screens.RNScreensPackage
import versioned.host.exp.exponent.modules.api.viewshot.RNViewShotModule
import versioned.host.exp.exponent.modules.internal.DevMenuModule
import versioned.host.exp.exponent.modules.test.ExponentTestNativeModule
Expand Down

This file was deleted.

117 changes: 117 additions & 0 deletions android/vendored/unversioned/react-native-screens/android/build.gradle
@@ -0,0 +1,117 @@
buildscript {
ext.safeExtGet = {prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath('com.android.tools.build:gradle:4.2.2')
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', '1.6.21')}"
classpath "com.diffplug.spotless:spotless-plugin-gradle:5.15.0"
}
}

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"
}

// spotless is only accessible within react-native-screens repo
if (project == rootProject) {
apply from: 'spotless.gradle'
}

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

def reactNativeArchitectures() {
def value = project.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

android {
compileSdkVersion safeExtGet('compileSdkVersion', 28)

// Used to override the NDK path/version on internal CI or by allowing
// users to customize the NDK path/version from their root project (e.g. for M1 support)
if (rootProject.hasProperty("ndkPath")) {
ndkPath rootProject.ext.ndkPath
}
if (rootProject.hasProperty("ndkVersion")) {
ndkVersion rootProject.ext.ndkVersion
}

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 21)
targetSdkVersion safeExtGet('targetSdkVersion', 22)
versionCode 1
versionName "1.0"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
ndk {
abiFilters (*reactNativeArchitectures())
}
}
lintOptions {
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
// For some reason gradle only complains about the duplicated version of libreact_render libraries
// while there are more libraries copied in intermediates folder of the lib build directory, we exlude
// only the ones that make the build fail (ideally we should only include librnscreens_modules but we
// are only allowed to specify exlude patterns)
exclude "**/libreact_render*.so"
}
sourceSets.main {
java {
if (isNewArchitectureEnabled()) {
srcDirs += [
"src/fabric/java",
]
} else {
srcDirs += [
"src/paper/java",
"build/generated/source/codegen/java"
]
}

}
}
}

repositories {
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
// Matches the RN Hello World template
// https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/local-cli/templates/HelloWorld/android/build.gradle#L21
url "$projectDir/../node_modules/react-native/android"
}
mavenCentral()
mavenLocal()
google()
}

dependencies {
if (isNewArchitectureEnabled()) {
implementation project(":ReactAndroid")
} else {
implementation 'com.facebook.react:react-native:+'
}
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.fragment:fragment:1.2.1'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation "androidx.core:core-ktx:1.5.0"
}
@@ -0,0 +1,49 @@
package com.swmansion.rnscreens

import android.view.ViewGroup
import androidx.annotation.UiThread
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.WritableMap
import com.facebook.react.bridge.WritableNativeMap
import com.facebook.react.uimanager.FabricViewStateManager
import com.facebook.react.uimanager.PixelUtil
import kotlin.math.abs

abstract class FabricEnabledViewGroup constructor(context: ReactContext?) : ViewGroup(context), FabricViewStateManager.HasFabricViewStateManager {
private val mFabricViewStateManager: FabricViewStateManager = FabricViewStateManager()

override fun getFabricViewStateManager(): FabricViewStateManager {
return mFabricViewStateManager
}

protected fun updateScreenSizeFabric(width: Int, height: Int) {
updateState(width, height)
}

@UiThread
fun updateState(width: Int, height: Int) {
val realWidth: Float = PixelUtil.toDIPFromPixel(width.toFloat())
val realHeight: Float = PixelUtil.toDIPFromPixel(height.toFloat())

// Check incoming state values. If they're already the correct value, return early to prevent
// infinite UpdateState/SetState loop.
val currentState: ReadableMap? = mFabricViewStateManager.getStateData()
if (currentState != null) {
val delta = 0.9f
val stateFrameHeight: Float = if (currentState.hasKey("frameHeight")) currentState.getDouble("frameHeight").toFloat() else 0f
val stateFrameWidth: Float = if (currentState.hasKey("frameWidth")) currentState.getDouble("frameWidth").toFloat() else 0f
if (abs(stateFrameWidth - realWidth) < delta &&
abs(stateFrameHeight - realHeight) < delta
) {
return
}
}
mFabricViewStateManager.setState {
val map: WritableMap = WritableNativeMap()
map.putDouble("frameWidth", realWidth.toDouble())
map.putDouble("frameHeight", realHeight.toDouble())
map
}
}
}
@@ -0,0 +1,5 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.swmansion.rnscreens">

</manifest>
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.screens
package com.swmansion.rnscreens

import android.content.Context
import androidx.activity.OnBackPressedCallback
Expand All @@ -22,7 +22,9 @@ class CustomSearchView(context: Context, fragment: Fragment) : SearchView(contex
isIconified = true
}
}

private val backPressOverrider = FragmentBackPressOverrider(fragment, mOnBackPressedCallback)

var overrideBackAction: Boolean
set(value) {
backPressOverrider.overrideBackAction = value
Expand Down
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.screens
package com.swmansion.rnscreens

import android.content.Context
import androidx.appcompat.widget.Toolbar
Expand Down
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.screens
package com.swmansion.rnscreens

import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.Fragment
Expand Down
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.screens
package com.swmansion.rnscreens

import android.view.View
import androidx.fragment.app.Fragment
Expand Down Expand Up @@ -43,8 +43,7 @@ class LifecycleHelper {
}

fun <T> unregister(view: T) where T : View, T : LifecycleObserver? {
val lifecycle = mViewToLifecycleMap[view]
lifecycle?.removeObserver(view)
mViewToLifecycleMap[view]?.removeObserver(view)
}

companion object {
Expand Down
@@ -0,0 +1,21 @@
package com.swmansion.rnscreens

import com.facebook.react.ReactPackage
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ViewManager

class RNScreensPackage : ReactPackage {
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> =
emptyList()

override fun createViewManagers(reactContext: ReactApplicationContext) =
listOf<ViewManager<*, *>>(
ScreenContainerViewManager(),
ScreenViewManager(),
ScreenStackViewManager(),
ScreenStackHeaderConfigViewManager(),
ScreenStackHeaderSubviewManager(),
SearchBarManager()
)
}
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.screens
package com.swmansion.rnscreens

import android.annotation.SuppressLint
import android.content.pm.ActivityInfo
Expand All @@ -12,8 +12,6 @@ import com.facebook.react.bridge.GuardedRunnable
import com.facebook.react.bridge.ReactContext
import com.facebook.react.uimanager.UIManagerModule

import host.exp.expoview.BuildConfig

@SuppressLint("ViewConstructor")
class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(context) {

Expand Down Expand Up @@ -86,12 +84,7 @@ class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(contex
}

val headerConfig: ScreenStackHeaderConfig?
get() {
val child = getChildAt(0)
return if (child is ScreenStackHeaderConfig) {
child
} else null
}
get() = getChildAt(0) as? ScreenStackHeaderConfig

/**
* While transitioning this property allows to optimize rendering behavior on Android and provide
Expand Down

0 comments on commit dee909a

Please sign in to comment.