Skip to content

Commit

Permalink
feat: handle edge-to-edge on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Oct 30, 2024
1 parent 6e0d745 commit 89b5805
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
3 changes: 3 additions & 0 deletions android/src/main/java/com/rcttabview/RCTTabView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import android.view.Choreographer
import android.view.MenuItem
import android.view.View
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.facebook.common.references.CloseableReference
import com.facebook.datasource.DataSources
import com.facebook.drawee.backends.pipeline.Fresco
Expand Down Expand Up @@ -50,6 +52,7 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
updateTintColors(item)
true
}
this.setItemTextAppearanceActiveBoldEnabled(false)
}

private fun onTabLongPressed(item: MenuItem) {
Expand Down
17 changes: 17 additions & 0 deletions android/src/main/java/com/rcttabview/RCTTabViewImpl.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.rcttabview

import android.content.res.ColorStateList
import android.graphics.Color
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.common.MapBuilder

Expand All @@ -18,6 +22,17 @@ class RCTTabViewImpl {

companion object {
const val NAME = "RNCTabView"
fun getNavigationBarInset(context: ReactContext): Int {
val window = context.currentActivity?.window
val isSystemBarTransparent = window?.navigationBarColor == Color.TRANSPARENT

if (!isSystemBarTransparent) {
return 0
}

val windowInsets = ViewCompat.getRootWindowInsets(window?.decorView ?: return 0)
return windowInsets?.getInsets(WindowInsetsCompat.Type.navigationBars())?.bottom ?: 0
}
}

fun setItems(view: ReactBottomNavigationView, items: ReadableArray) {
Expand Down Expand Up @@ -77,6 +92,8 @@ class RCTTabViewImpl {
view.setInactiveTintColor(color)
}



fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any>? {
return MapBuilder.of(
PageSelectedEvent.EVENT_NAME,
Expand Down
7 changes: 6 additions & 1 deletion android/src/newarch/RCTTabViewManager.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.rcttabview

import android.content.Context
import android.graphics.Color
import android.view.View
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
Expand Down Expand Up @@ -113,9 +116,11 @@ class RCTTabViewManager(context: ReactApplicationContext) :
val measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
view.measure(measureSpec, measureSpec)

val bottomInset = RCTTabViewImpl.getNavigationBarInset(contextInner)

return YogaMeasureOutput.make(
toDIPFromPixel(view.measuredWidth.toFloat()),
toDIPFromPixel(view.measuredHeight.toFloat())
toDIPFromPixel(view.measuredHeight.toFloat() + bottomInset)
)
}

Expand Down
9 changes: 7 additions & 2 deletions android/src/oldarch/RCTTabViewManager.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.rcttabview

import android.graphics.Color
import android.view.View.MeasureSpec
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.LayoutShadowNode
Expand Down Expand Up @@ -133,12 +136,14 @@ class RCTTabViewManager(context: ReactApplicationContext) : SimpleViewManager<Re
if (mMeasured) {
return YogaMeasureOutput.make(mWidth, mHeight)
}

val tabView = ReactBottomNavigationView(themedContext)
val spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)

val navigationBarInset = RCTTabViewImpl.getNavigationBarInset(themedContext)
tabView.measure(spec, spec)
this.mWidth = tabView.measuredWidth
this.mHeight = tabView.measuredHeight
this.mHeight = tabView.measuredHeight + navigationBarInset

this.mMeasured = true

return YogaMeasureOutput.make(mWidth, mHeight)
Expand Down

0 comments on commit 89b5805

Please sign in to comment.