Skip to content

Commit

Permalink
fix: remove custom shadow nodes measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Jan 14, 2025
1 parent 8dd3a80 commit bf0e907
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 405 deletions.
2 changes: 1 addition & 1 deletion apps/example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
# Note that this is incompatible with web debugging.
newArchEnabled=false
newArchEnabled=true
#bridgelessEnabled=true

# Uncomment the line below to build React Native from source.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ReactBottomNavigationView(context: ReactContext) : FrameLayout(context) {
var onTabSelectedListener: ((key: String) -> Unit)? = null
var onTabLongPressedListener: ((key: String) -> Unit)? = null
var onNativeLayoutListener: ((width: Double, height: Double) -> Unit)? = null
var disablePageTransitions = false
private var disablePageTransitions = false
var items: MutableList<TabInfo>? = null

private var selectedItem: String? = null
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
package com.rcttabview

import android.content.Context
import android.view.View
import android.view.ViewGroup
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.PixelUtil.toDIPFromPixel
import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.UIManagerHelper
import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.viewmanagers.RNCTabViewManagerDelegate
import com.facebook.react.viewmanagers.RNCTabViewManagerInterface
import com.facebook.yoga.YogaMeasureMode
import com.facebook.yoga.YogaMeasureOutput
import com.rcttabview.events.OnNativeLayoutEvent
import com.rcttabview.events.PageSelectedEvent
import com.rcttabview.events.TabLongPressEvent


@ReactModule(name = RCTTabViewImpl.NAME)
class RCTTabViewManager(context: ReactApplicationContext) :
SimpleViewManager<ReactBottomNavigationView>(),
ViewGroupManager<ReactBottomNavigationView>(),
RNCTabViewManagerInterface<ReactBottomNavigationView> {

private val contextInner: ReactApplicationContext = context
private val delegate: RNCTabViewManagerDelegate<ReactBottomNavigationView, RCTTabViewManager> =
RNCTabViewManagerDelegate(this)
private val tabViewImpl: RCTTabViewImpl = RCTTabViewImpl()
Expand All @@ -37,6 +35,10 @@ class RCTTabViewManager(context: ReactApplicationContext) :
view.onTabLongPressedListener = { key ->
eventDispatcher?.dispatchEvent(TabLongPressEvent(viewTag = view.id, key))
}

view.onNativeLayoutListener = { width, height ->
eventDispatcher?.dispatchEvent(OnNativeLayoutEvent(viewTag = view.id, width, height))
}
return view

}
Expand All @@ -45,6 +47,36 @@ class RCTTabViewManager(context: ReactApplicationContext) :
return tabViewImpl.getName()
}

override fun getChildCount(parent: ReactBottomNavigationView): Int {
return parent.viewPagerAdapter.itemCount ?: 0
}

override fun getChildAt(parent: ReactBottomNavigationView, index: Int): View? {
return parent.viewPagerAdapter.getChildAt(index)
}

override fun removeView(parent: ReactBottomNavigationView, view: View) {
parent.viewPagerAdapter.removeChild(view)
}

override fun removeAllViews(parent: ReactBottomNavigationView) {
parent.viewPagerAdapter.removeAll()
}

override fun removeViewAt(parent: ReactBottomNavigationView, index: Int) {
val child = parent.viewPagerAdapter.getChildAt(index)

if (child.parent != null) {
(child.parent as? ViewGroup)?.removeView(child)
}

parent.viewPagerAdapter.removeChildAt(index)
}

override fun needsCustomLayoutForChildren(): Boolean {
return true
}

override fun setItems(view: ReactBottomNavigationView?, value: ReadableArray?) {
if (view != null && value != null)
tabViewImpl.setItems(view, value)
Expand Down Expand Up @@ -99,30 +131,6 @@ class RCTTabViewManager(context: ReactApplicationContext) :
tabViewImpl.setHapticFeedbackEnabled(view, value)
}

public override fun measure(
context: Context?,
localData: ReadableMap?,
props: ReadableMap?,
state: ReadableMap?,
width: Float,
widthMode: YogaMeasureMode?,
height: Float,
heightMode: YogaMeasureMode?,
attachmentsPositions: FloatArray?
): Long {
val view = ReactBottomNavigationView(context ?: contextInner)
val measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
view.measure(measureSpec, measureSpec)

val bottomInset = RCTTabViewImpl.getNavigationBarInset(contextInner)

return YogaMeasureOutput.make(
// TabBar should always stretch to the width of the screen.
toDIPFromPixel(width),
toDIPFromPixel(view.measuredHeight.toFloat() + bottomInset)
)
}

override fun setFontFamily(view: ReactBottomNavigationView?, value: String?) {
view?.setFontFamily(value)
}
Expand All @@ -136,7 +144,6 @@ class RCTTabViewManager(context: ReactApplicationContext) :
}

// iOS Methods

override fun setTranslucent(view: ReactBottomNavigationView?, value: Boolean) {
}

Expand All @@ -151,6 +158,4 @@ class RCTTabViewManager(context: ReactApplicationContext) :

override fun setScrollEdgeAppearance(view: ReactBottomNavigationView?, value: String?) {
}


}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit bf0e907

Please sign in to comment.