Skip to content

Commit

Permalink
removed redundant logic
Browse files Browse the repository at this point in the history
  • Loading branch information
alduzy committed Nov 13, 2024
1 parent 2054ee4 commit 2e73c1f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
15 changes: 6 additions & 9 deletions android/src/main/java/com/swmansion/rnscreens/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import com.swmansion.rnscreens.events.HeaderHeightChangeEvent
import com.swmansion.rnscreens.events.SheetDetentChangedEvent
import com.swmansion.rnscreens.ext.removeClippedSubviews
import java.lang.ref.WeakReference

@SuppressLint("ViewConstructor") // Only we construct this view, it is never inflated.
Expand Down Expand Up @@ -380,10 +379,7 @@ class Screen(
}
}

private fun startTransitionRecursive(
parent: ViewGroup?,
isPossiblyRemovedClippedSubview: Boolean = true,
) {
private fun startTransitionRecursive(parent: ViewGroup?) {
parent?.let {
for (i in 0 until it.childCount) {
val child = it.getChildAt(i)
Expand All @@ -401,19 +397,20 @@ class Screen(
if (child is ScreenStackHeaderConfig) {
// we want to start transition on children of the toolbar too,
// which is not a child of ScreenStackHeaderConfig
startTransitionRecursive(child, isPossiblyRemovedClippedSubview || it.removeClippedSubviews)
startTransitionRecursive(child)
}
if (child is ViewGroup) {
// The children are miscounted when there's removeClippedSubviews prop
// set to true (which is the default for FlatLists).
// We add a simple view for each possibly clipped item to make it work as expected.
// Unless the child is a ScrollView it's safe to assume that it's true
// and add a simple view for each possibly clipped item to make it work as expected.
// See https://github.com/software-mansion/react-native-screens/pull/2495
if (isPossiblyRemovedClippedSubview && child !is ReactScrollView && child !is ReactHorizontalScrollView) {
if (child !is ReactScrollView && child !is ReactHorizontalScrollView) {
for (j in 0 until child.childCount) {
child.addView(View(context))
}
}
startTransitionRecursive(child, isPossiblyRemovedClippedSubview || it.removeClippedSubviews)
startTransitionRecursive(child)
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions android/src/main/java/com/swmansion/rnscreens/ext/ViewExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.swmansion.rnscreens.ext
import android.graphics.drawable.ColorDrawable
import android.view.View
import android.view.ViewGroup
import com.facebook.react.views.view.ReactViewGroup

internal fun View.parentAsView() = this.parent as? View

Expand Down Expand Up @@ -31,6 +30,3 @@ internal fun View.maybeBgColor(): Int? {
}
return null
}

internal val View.removeClippedSubviews: Boolean
get() = (this as? ReactViewGroup)?.removeClippedSubviews ?: false

0 comments on commit 2e73c1f

Please sign in to comment.