Skip to content

Commit 7b163de

Browse files
committed
Fix color resolving for RN 0.77 & 0.78 (might not compile on older versions)
1 parent 013585d commit 7b163de

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

android/src/main/java/com/swmansion/rnscreens/ScreenStackFragment.kt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import androidx.annotation.RequiresApi
2727
import androidx.appcompat.widget.Toolbar
2828
import androidx.coordinatorlayout.widget.CoordinatorLayout
2929
import androidx.core.animation.addListener
30-
import androidx.core.view.OnApplyWindowInsetsListener
3130
import androidx.core.view.WindowInsetsCompat
31+
import com.facebook.react.uimanager.BackgroundStyleApplicator
3232
import com.facebook.react.uimanager.PixelUtil
3333
import com.facebook.react.uimanager.PointerEvents
3434
import com.facebook.react.uimanager.ReactPointerEventsView
@@ -586,6 +586,24 @@ class ScreenStackFragment :
586586
private fun createAndConfigureBottomSheetBehaviour(): BottomSheetBehavior<Screen> =
587587
configureBottomSheetBehaviour(createBottomSheetBehaviour())
588588

589+
private fun resolveBackgroundColor(screen: Screen): Int? {
590+
val screenColor =
591+
(screen.background as? ColorDrawable?)?.color
592+
?: (screen.background as? MaterialShapeDrawable?)?.tintList?.defaultColor
593+
594+
if (screenColor != null) {
595+
return screenColor
596+
}
597+
598+
val contentWrapper = screen.contentWrapper.get()
599+
if (contentWrapper == null) {
600+
return null
601+
}
602+
603+
val contentWrapperColor = BackgroundStyleApplicator.getBackgroundColor(contentWrapper)
604+
return contentWrapperColor
605+
}
606+
589607
private fun attachShapeToScreen(screen: Screen) {
590608
val cornerSize = PixelUtil.toPixelFromDIP(screen.sheetCornerRadius)
591609
val shapeAppearanceModel =
@@ -596,10 +614,8 @@ class ScreenStackFragment :
596614
setTopRightCorner(CornerFamily.ROUNDED, cornerSize)
597615
}.build()
598616
val shape = MaterialShapeDrawable(shapeAppearanceModel)
599-
val currentColor =
600-
(screen.background as? ColorDrawable?)?.color
601-
?: (screen.background as? MaterialShapeDrawable?)?.tintList?.defaultColor
602-
shape.setTint(currentColor ?: Color.TRANSPARENT)
617+
val backgroundColor = resolveBackgroundColor(screen)
618+
shape.setTint(backgroundColor ?: Color.TRANSPARENT)
603619
screen.background = shape
604620
}
605621

0 commit comments

Comments
 (0)