Skip to content

Commit

Permalink
Merge branch 'main' into @tboba/introduce-material3-finally-prettier-…
Browse files Browse the repository at this point in the history
…android-ui
  • Loading branch information
tboba committed Sep 18, 2023
2 parents 2bb3e5f + bc899b8 commit 76cedb4
Show file tree
Hide file tree
Showing 30 changed files with 2,555 additions and 2,997 deletions.
7 changes: 4 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module.exports = {
'plugin:import/warnings',
'plugin:react/recommended',
'prettier',
'prettier/react',
'prettier/standard',
],

plugins: ['react-native', 'react-hooks'],
Expand Down Expand Up @@ -51,17 +49,20 @@ module.exports = {
{
files: ['*.{ts,tsx}'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['./tsconfig.json'],
},
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:import/typescript',
'prettier/@typescript-eslint',
],
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
},
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/array-type': 'error',
'@typescript-eslint/consistent-type-assertions': [
'error',
Expand Down
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: software-mansion
1 change: 1 addition & 0 deletions .github/workflows/android-build-test-fabric.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 60
env:
WORKING_DIRECTORY: FabricTestExample
concurrency:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/android-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 60
env:
WORKING_DIRECTORY: TestsExample
concurrency:
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/android-e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: 'zulu'
cache: 'gradle'
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ios-build-test-fabric.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
jobs:
build:
runs-on: macos-12
timeout-minutes: 60
env:
WORKING_DIRECTORY: FabricTestExample
concurrency:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ios-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
jobs:
build:
runs-on: macos-12
timeout-minutes: 60
env:
WORKING_DIRECTORY: TestsExample
concurrency:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tv-os-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
jobs:
build:
runs-on: macos-12
timeout-minutes: 60
env:
WORKING_DIRECTORY: TVOSExample
concurrency:
Expand Down
5 changes: 4 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
arrowParens: 'avoid',
bracketSameLine: true,
bracketSpacing: true,
singleQuote: true,
jsxBracketSameLine: true,
trailingComma: 'es5',
};
4 changes: 2 additions & 2 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand All @@ -20,4 +20,4 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryErro
android.useAndroidX=true
android.enableJetifier=true

kotlin.code.style=official
kotlin.code.style=official
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.swmansion.rnscreens

import androidx.fragment.app.Fragment

interface FragmentHolder {
val fragment: Fragment
}
24 changes: 14 additions & 10 deletions android/src/main/java/com/swmansion/rnscreens/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ import android.util.SparseArray
import android.view.ViewGroup
import android.view.WindowManager
import android.webkit.WebView
import androidx.core.view.children
import androidx.fragment.app.Fragment
import com.facebook.react.bridge.GuardedRunnable
import com.facebook.react.bridge.ReactContext
import com.facebook.react.uimanager.UIManagerModule

@SuppressLint("ViewConstructor")
class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(context) {
val fragment: Fragment?
get() = fragmentWrapper?.fragment

var fragment: ScreenFragment? = null
var container: ScreenContainer<*>? = null
var fragmentWrapper: ScreenFragmentWrapper? = null
var container: ScreenContainer? = null
var activityState: ActivityState? = null
private set
private var mTransitioning = false
Expand Down Expand Up @@ -85,7 +89,7 @@ class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(contex
}

val headerConfig: ScreenStackHeaderConfig?
get() = getChildAt(0) as? ScreenStackHeaderConfig
get() = children.find { it is ScreenStackHeaderConfig } as? ScreenStackHeaderConfig

/**
* While transitioning this property allows to optimize rendering behavior on Android and provide
Expand Down Expand Up @@ -150,7 +154,7 @@ class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(contex
else -> ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
}

fragment?.let { ScreenWindowTraits.setOrientation(this, it.tryGetActivity()) }
fragmentWrapper?.let { ScreenWindowTraits.setOrientation(this, it.tryGetActivity()) }
}

// Accepts one of 4 accessibility flags
Expand All @@ -167,7 +171,7 @@ class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(contex
ScreenWindowTraits.applyDidSetStatusBarAppearance()
}
mStatusBarStyle = statusBarStyle
fragment?.let { ScreenWindowTraits.setStyle(this, it.tryGetActivity(), it.tryGetContext()) }
fragmentWrapper?.let { ScreenWindowTraits.setStyle(this, it.tryGetActivity(), it.tryGetContext()) }
}

var isStatusBarHidden: Boolean?
Expand All @@ -177,7 +181,7 @@ class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(contex
ScreenWindowTraits.applyDidSetStatusBarAppearance()
}
mStatusBarHidden = statusBarHidden
fragment?.let { ScreenWindowTraits.setHidden(this, it.tryGetActivity()) }
fragmentWrapper?.let { ScreenWindowTraits.setHidden(this, it.tryGetActivity()) }
}

var isStatusBarTranslucent: Boolean?
Expand All @@ -187,7 +191,7 @@ class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(contex
ScreenWindowTraits.applyDidSetStatusBarAppearance()
}
mStatusBarTranslucent = statusBarTranslucent
fragment?.let {
fragmentWrapper?.let {
ScreenWindowTraits.setTranslucent(
this,
it.tryGetActivity(),
Expand All @@ -203,7 +207,7 @@ class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(contex
ScreenWindowTraits.applyDidSetStatusBarAppearance()
}
mStatusBarColor = statusBarColor
fragment?.let { ScreenWindowTraits.setColor(this, it.tryGetActivity(), it.tryGetContext()) }
fragmentWrapper?.let { ScreenWindowTraits.setColor(this, it.tryGetActivity(), it.tryGetContext()) }
}

var navigationBarColor: Int?
Expand All @@ -213,7 +217,7 @@ class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(contex
ScreenWindowTraits.applyDidSetNavigationBarAppearance()
}
mNavigationBarColor = navigationBarColor
fragment?.let { ScreenWindowTraits.setNavigationBarColor(this, it.tryGetActivity()) }
fragmentWrapper?.let { ScreenWindowTraits.setNavigationBarColor(this, it.tryGetActivity()) }
}

var isNavigationBarHidden: Boolean?
Expand All @@ -223,7 +227,7 @@ class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(contex
ScreenWindowTraits.applyDidSetNavigationBarAppearance()
}
mNavigationBarHidden = navigationBarHidden
fragment?.let {
fragmentWrapper?.let {
ScreenWindowTraits.setNavigationBarHidden(
this,
it.tryGetActivity(),
Expand Down
71 changes: 35 additions & 36 deletions android/src/main/java/com/swmansion/rnscreens/ScreenContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import com.facebook.react.modules.core.ChoreographerCompat
import com.facebook.react.modules.core.ReactChoreographer
import com.swmansion.rnscreens.Screen.ActivityState

open class ScreenContainer<T : ScreenFragment>(context: Context?) : ViewGroup(context) {
open class ScreenContainer(context: Context?) : ViewGroup(context) {
@JvmField
protected val mScreenFragments = ArrayList<T>()
protected val mScreenFragments = ArrayList<ScreenFragmentWrapper>()
@JvmField
protected var mFragmentManager: FragmentManager? = null
private var mIsAttached = false
Expand All @@ -34,7 +34,7 @@ open class ScreenContainer<T : ScreenFragment>(context: Context?) : ViewGroup(co
layout(left, top, right, bottom)
}
}
private var mParentScreenFragment: ScreenFragment? = null
private var mParentScreenFragment: ScreenFragmentWrapper? = null

override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
var i = 0
Expand Down Expand Up @@ -87,14 +87,11 @@ open class ScreenContainer<T : ScreenFragment>(context: Context?) : ViewGroup(co
performUpdatesNow()
}

protected open fun adapt(screen: Screen): T {
@Suppress("UNCHECKED_CAST")
return ScreenFragment(screen) as T
}
protected open fun adapt(screen: Screen): ScreenFragmentWrapper = ScreenFragment(screen)

fun addScreen(screen: Screen, index: Int) {
val fragment = adapt(screen)
screen.fragment = fragment
screen.fragmentWrapper = fragment
mScreenFragments.add(index, fragment)
screen.container = this
onScreenChanged()
Expand All @@ -119,6 +116,8 @@ open class ScreenContainer<T : ScreenFragment>(context: Context?) : ViewGroup(co

fun getScreenAt(index: Int): Screen = mScreenFragments[index].screen

fun getScreenFragmentWrapperAt(index: Int): ScreenFragmentWrapper = mScreenFragments[index]

open val topScreen: Screen?
get() = mScreenFragments.firstOrNull { getActivityState(it) === ActivityState.ON_TOP }?.screen

Expand Down Expand Up @@ -174,10 +173,10 @@ open class ScreenContainer<T : ScreenFragment>(context: Context?) : ViewGroup(co
// Otherwise we expect to connect directly with root view and get root fragment manager
if (parent is Screen) {
checkNotNull(
parent.fragment?.let { screenFragment ->
mParentScreenFragment = screenFragment
screenFragment.registerChildScreenContainer(this)
setFragmentManager(screenFragment.childFragmentManager)
parent.fragmentWrapper?.let { fragmentWrapper ->
mParentScreenFragment = fragmentWrapper
fragmentWrapper.addChildScreenContainer(this)
setFragmentManager(fragmentWrapper.fragment.childFragmentManager)
}
) { "Parent Screen does not have its Fragment attached" }
} else {
Expand All @@ -197,19 +196,19 @@ open class ScreenContainer<T : ScreenFragment>(context: Context?) : ViewGroup(co
.setReorderingAllowed(true)
}

private fun attachScreen(transaction: FragmentTransaction, screenFragment: ScreenFragment) {
transaction.add(id, screenFragment)
private fun attachScreen(transaction: FragmentTransaction, fragment: Fragment) {
transaction.add(id, fragment)
}

private fun detachScreen(transaction: FragmentTransaction, screenFragment: ScreenFragment) {
transaction.remove(screenFragment)
private fun detachScreen(transaction: FragmentTransaction, fragment: Fragment) {
transaction.remove(fragment)
}

private fun getActivityState(screenFragment: ScreenFragment): ActivityState? =
screenFragment.screen.activityState
private fun getActivityState(screenFragmentWrapper: ScreenFragmentWrapper): ActivityState? =
screenFragmentWrapper.screen.activityState

open fun hasScreen(screenFragment: ScreenFragment?): Boolean =
mScreenFragments.contains(screenFragment)
open fun hasScreen(screenFragmentWrapper: ScreenFragmentWrapper?): Boolean =
mScreenFragments.contains(screenFragmentWrapper)

override fun onAttachedToWindow() {
super.onAttachedToWindow()
Expand Down Expand Up @@ -246,7 +245,7 @@ open class ScreenContainer<T : ScreenFragment>(context: Context?) : ViewGroup(co
}
}

mParentScreenFragment?.unregisterChildScreenContainer(this)
mParentScreenFragment?.removeChildScreenContainer(this)
mParentScreenFragment = null

super.onDetachedFromWindow()
Expand Down Expand Up @@ -320,13 +319,13 @@ open class ScreenContainer<T : ScreenFragment>(context: Context?) : ViewGroup(co
"mFragmentManager is null when performing update in ScreenContainer"
}.fragments
)
for (screenFragment in mScreenFragments) {
if (getActivityState(screenFragment) === ActivityState.INACTIVE &&
screenFragment.isAdded
for (fragmentWrapper in mScreenFragments) {
if (getActivityState(fragmentWrapper) === ActivityState.INACTIVE &&
fragmentWrapper.fragment.isAdded
) {
detachScreen(it, screenFragment)
detachScreen(it, fragmentWrapper.fragment)
}
orphaned.remove(screenFragment)
orphaned.remove(fragmentWrapper.fragment)
}
if (orphaned.isNotEmpty()) {
val orphanedAry = orphaned.toTypedArray()
Expand All @@ -344,30 +343,30 @@ open class ScreenContainer<T : ScreenFragment>(context: Context?) : ViewGroup(co

// attach newly activated screens
var addedBefore = false
val pendingFront: ArrayList<T> = ArrayList()
val pendingFront: ArrayList<ScreenFragmentWrapper> = ArrayList()

for (screenFragment in mScreenFragments) {
val activityState = getActivityState(screenFragment)
if (activityState !== ActivityState.INACTIVE && !screenFragment.isAdded) {
for (fragmentWrapper in mScreenFragments) {
val activityState = getActivityState(fragmentWrapper)
if (activityState !== ActivityState.INACTIVE && !fragmentWrapper.fragment.isAdded) {
addedBefore = true
attachScreen(it, screenFragment)
attachScreen(it, fragmentWrapper.fragment)
} else if (activityState !== ActivityState.INACTIVE && addedBefore) {
// we detach the screen and then reattach it later to make it appear on front
detachScreen(it, screenFragment)
pendingFront.add(screenFragment)
detachScreen(it, fragmentWrapper.fragment)
pendingFront.add(fragmentWrapper)
}
screenFragment.screen.setTransitioning(transitioning)
fragmentWrapper.screen.setTransitioning(transitioning)
}

for (screenFragment in pendingFront) {
attachScreen(it, screenFragment)
attachScreen(it, screenFragment.fragment)
}

it.commitNowAllowingStateLoss()
}
}

protected open fun notifyContainerUpdate() {
topScreen?.fragment?.onContainerUpdate()
topScreen?.fragmentWrapper?.onContainerUpdate()
}
}
Loading

0 comments on commit 76cedb4

Please sign in to comment.