Skip to content

Commit

Permalink
Fix color resolving for RN 0.77 & 0.78 (might not compile on older ve…
Browse files Browse the repository at this point in the history
…rsions)
  • Loading branch information
kkafar committed Jan 29, 2025
1 parent 8982286 commit 0fe34e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.annotation.RequiresApi
import androidx.appcompat.widget.Toolbar
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.WindowInsetsCompat
import com.facebook.react.uimanager.BackgroundStyleApplicator
import com.facebook.react.uimanager.PixelUtil
import com.facebook.react.uimanager.PointerEvents
import com.facebook.react.uimanager.ReactPointerEventsView
Expand Down Expand Up @@ -461,6 +462,24 @@ class ScreenStackFragment :
internal fun createAndConfigureBottomSheetBehaviour(): BottomSheetBehavior<Screen> =
configureBottomSheetBehaviour(BottomSheetBehavior<Screen>())

private fun resolveBackgroundColor(screen: Screen): Int? {
val screenColor =
(screen.background as? ColorDrawable?)?.color
?: (screen.background as? MaterialShapeDrawable?)?.tintList?.defaultColor

if (screenColor != null) {
return screenColor
}

val contentWrapper = screen.contentWrapper.get()
if (contentWrapper == null) {
return null
}

val contentWrapperColor = BackgroundStyleApplicator.getBackgroundColor(contentWrapper)
return contentWrapperColor
}

private fun attachShapeToScreen(screen: Screen) {
val cornerSize = PixelUtil.toPixelFromDIP(screen.sheetCornerRadius)
val shapeAppearanceModel =
Expand All @@ -471,10 +490,8 @@ class ScreenStackFragment :
setTopRightCorner(CornerFamily.ROUNDED, cornerSize)
}.build()
val shape = MaterialShapeDrawable(shapeAppearanceModel)
val currentColor =
(screen.background as? ColorDrawable?)?.color
?: (screen.background as? MaterialShapeDrawable?)?.tintList?.defaultColor
shape.setTint(currentColor ?: Color.TRANSPARENT)
val backgroundColor = resolveBackgroundColor(screen)
shape.setTint(backgroundColor ?: Color.TRANSPARENT)
screen.background = shape
}

Expand Down
2 changes: 1 addition & 1 deletion react-navigation
Submodule react-navigation updated 138 files

0 comments on commit 0fe34e6

Please sign in to comment.