Skip to content

Commit 0fe34e6

Browse files
committed
Fix color resolving for RN 0.77 & 0.78 (might not compile on older versions)
1 parent 8982286 commit 0fe34e6

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import androidx.annotation.RequiresApi
2424
import androidx.appcompat.widget.Toolbar
2525
import androidx.coordinatorlayout.widget.CoordinatorLayout
2626
import androidx.core.view.WindowInsetsCompat
27+
import com.facebook.react.uimanager.BackgroundStyleApplicator
2728
import com.facebook.react.uimanager.PixelUtil
2829
import com.facebook.react.uimanager.PointerEvents
2930
import com.facebook.react.uimanager.ReactPointerEventsView
@@ -461,6 +462,24 @@ class ScreenStackFragment :
461462
internal fun createAndConfigureBottomSheetBehaviour(): BottomSheetBehavior<Screen> =
462463
configureBottomSheetBehaviour(BottomSheetBehavior<Screen>())
463464

465+
private fun resolveBackgroundColor(screen: Screen): Int? {
466+
val screenColor =
467+
(screen.background as? ColorDrawable?)?.color
468+
?: (screen.background as? MaterialShapeDrawable?)?.tintList?.defaultColor
469+
470+
if (screenColor != null) {
471+
return screenColor
472+
}
473+
474+
val contentWrapper = screen.contentWrapper.get()
475+
if (contentWrapper == null) {
476+
return null
477+
}
478+
479+
val contentWrapperColor = BackgroundStyleApplicator.getBackgroundColor(contentWrapper)
480+
return contentWrapperColor
481+
}
482+
464483
private fun attachShapeToScreen(screen: Screen) {
465484
val cornerSize = PixelUtil.toPixelFromDIP(screen.sheetCornerRadius)
466485
val shapeAppearanceModel =
@@ -471,10 +490,8 @@ class ScreenStackFragment :
471490
setTopRightCorner(CornerFamily.ROUNDED, cornerSize)
472491
}.build()
473492
val shape = MaterialShapeDrawable(shapeAppearanceModel)
474-
val currentColor =
475-
(screen.background as? ColorDrawable?)?.color
476-
?: (screen.background as? MaterialShapeDrawable?)?.tintList?.defaultColor
477-
shape.setTint(currentColor ?: Color.TRANSPARENT)
493+
val backgroundColor = resolveBackgroundColor(screen)
494+
shape.setTint(backgroundColor ?: Color.TRANSPARENT)
478495
screen.background = shape
479496
}
480497

react-navigation

Submodule react-navigation updated 138 files

0 commit comments

Comments
 (0)