Skip to content

Commit

Permalink
fix(android): properly set android background color (#258)
Browse files Browse the repository at this point in the history
* fix(android): properly set android background color

* docs: add missing changesets
  • Loading branch information
okwasniewski authored Jan 26, 2025
1 parent 20ae835 commit 70e1955
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-bobcats-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-native-bottom-tabs': patch
---

fix: properly set background color on Android
5 changes: 5 additions & 0 deletions .changeset/two-socks-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-native-bottom-tabs': patch
---

fix: iOS crash on old architecture when setting font style
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.rcttabview

import android.annotation.SuppressLint
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.os.Build
Expand All @@ -20,14 +20,10 @@ import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.view.children
import androidx.core.view.forEachIndexed
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.viewpager2.widget.ViewPager2
import coil3.ImageLoader
import coil3.asDrawable
import coil3.request.ImageRequest
import coil3.svg.SvgDecoder
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.common.assets.ReactFontManager
import com.facebook.react.modules.core.ReactChoreographer
Expand All @@ -38,8 +34,7 @@ import com.google.android.material.navigation.NavigationBarView.LABEL_VISIBILITY
import com.google.android.material.navigation.NavigationBarView.LABEL_VISIBILITY_UNLABELED
import com.google.android.material.transition.platform.MaterialFadeThrough

class ReactBottomNavigationView(context: ReactContext) : LinearLayout(context) {
private val reactContext: ReactContext = context
class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
private val bottomNavigation = BottomNavigationView(context)
val layoutHolder = FrameLayout(context)

Expand Down Expand Up @@ -335,11 +330,7 @@ class ReactBottomNavigationView(context: ReactContext) : LinearLayout(context) {
val colorDrawable = ColorDrawable(backgroundColor)

bottomNavigation.itemBackground = colorDrawable
backgroundTintList = ColorStateList.valueOf(backgroundColor)
// Set navigationBarColor for edge-to-edge.
if (Utils.isEdgeToEdge()) {
reactContext.currentActivity?.window?.navigationBarColor = backgroundColor
}
bottomNavigation.backgroundTintList = ColorStateList.valueOf(backgroundColor)
}

fun setActiveTintColor(color: Int?) {
Expand Down Expand Up @@ -430,9 +421,6 @@ class ReactBottomNavigationView(context: ReactContext) : LinearLayout(context) {

override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
if (Utils.isEdgeToEdge()) {
reactContext.currentActivity?.window?.navigationBarColor = Color.TRANSPARENT
}
imageLoader.shutdown()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,5 @@ class Utils {
)
return baseColor.defaultColor
}

// Detect `react-native-edge-to-edge` (https://github.com/zoontek/react-native-edge-to-edge)
fun isEdgeToEdge() = try {
Class.forName("com.zoontek.rnedgetoedge.EdgeToEdgePackage")
true
} catch (exception: ClassNotFoundException) {
false
}
}
}

0 comments on commit 70e1955

Please sign in to comment.