Skip to content

Commit eb50da1

Browse files
committed
feat: make shadow node work, share the code between ios
1 parent 1d6d289 commit eb50da1

22 files changed

+400
-465
lines changed
Lines changed: 11 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
11
package com.rcttabview
22

33
import android.content.res.ColorStateList
4-
import android.util.Log
5-
import android.view.View.MeasureSpec
64
import com.facebook.react.bridge.ReadableArray
75
import com.facebook.react.common.MapBuilder
8-
import com.facebook.react.uimanager.LayoutShadowNode
9-
import com.facebook.react.uimanager.ThemedReactContext
10-
import com.facebook.react.uimanager.UIManagerHelper
11-
import com.facebook.react.uimanager.UIManagerModule
12-
import com.facebook.react.uimanager.annotations.ReactProp
13-
import com.facebook.react.uimanager.events.EventDispatcher
14-
import com.facebook.yoga.YogaMeasureFunction
15-
import com.facebook.yoga.YogaMeasureMode
16-
import com.facebook.yoga.YogaMeasureOutput
17-
import com.facebook.yoga.YogaNode
18-
196

207
data class TabInfo(
218
val key: String,
@@ -25,13 +12,14 @@ data class TabInfo(
2512
)
2613

2714
class RCTTabViewImpl {
28-
29-
private lateinit var eventDispatcher: EventDispatcherWrapper
30-
private var tabView: ReactBottomNavigationView? = null
3115
fun getName(): String {
3216
return NAME
3317
}
3418

19+
companion object {
20+
const val NAME = "RNCTabView"
21+
}
22+
3523
fun setItems(view: ReactBottomNavigationView, items: ReadableArray) {
3624
val itemsArray = mutableListOf<TabInfo>()
3725
for (i in 0 until items.size()) {
@@ -49,92 +37,45 @@ class RCTTabViewImpl {
4937
view.updateItems(itemsArray)
5038
}
5139

52-
5340
fun setSelectedPage(view: ReactBottomNavigationView, key: String) {
5441
view.items?.indexOfFirst { it.key == key }?.let {
5542
view.selectedItemId = it
5643
}
5744
}
5845

59-
6046
fun setLabeled(view: ReactBottomNavigationView, flag: Boolean?) {
6147
view.setLabeled(flag)
6248
}
6349

64-
6550
fun setIcons(view: ReactBottomNavigationView, icons: ReadableArray?) {
6651
view.setIcons(icons)
6752
}
6853

69-
@ReactProp(name = "barTintColor", customType = "Color")
7054
fun setBarTintColor(view: ReactBottomNavigationView, color: Int?) {
7155
view.setBarTintColor(color)
7256
}
7357

74-
@ReactProp(name = "rippleColor", customType = "Color")
7558
fun setRippleColor(view: ReactBottomNavigationView, rippleColor: Int?) {
7659
if (rippleColor != null) {
7760
val color = ColorStateList.valueOf(rippleColor)
7861
view.setRippleColor(color)
7962
}
8063
}
8164

82-
@ReactProp(name = "activeTintColor", customType = "Color")
8365
fun setActiveTintColor(view: ReactBottomNavigationView, color: Int?) {
8466
view.setActiveTintColor(color)
8567
}
8668

87-
@ReactProp(name = "inactiveTintColor", customType = "Color")
8869
fun setInactiveTintColor(view: ReactBottomNavigationView, color: Int?) {
8970
view.setInactiveTintColor(color)
9071
}
9172

92-
fun createViewInstance(context: ThemedReactContext): ReactBottomNavigationView {
93-
val view = ReactBottomNavigationView(context)
94-
tabView = view
95-
eventDispatcher = EventDispatcherWrapper(context)
96-
view?.onTabSelectedListener = { data ->
97-
data.getString("key")?.let {
98-
eventDispatcher.dispatchEvent(PageSelectedEvent(viewTag = view.id, key = it))
99-
}
100-
}
101-
102-
view.onTabLongPressedListener = { data ->
103-
data.getString("key")?.let {
104-
// eventDispatcher.dispatchEvent(TabLongPressEvent(viewTag = view.id, key = it))
105-
}
106-
}
107-
108-
return view
109-
}
110-
111-
fun getViewInstance(): ReactBottomNavigationView? {
112-
return if(tabView!=null)
113-
tabView
114-
else
115-
null
116-
}
117-
118-
companion object {
119-
const val NAME = "RNCTabView"
120-
}
121-
// iOS Props
122-
123-
fun setSidebarAdaptable(view: ReactBottomNavigationView, flag: Boolean) {
124-
}
125-
126-
fun setScrollEdgeAppearance(view: ReactBottomNavigationView, value: String) {
127-
128-
}
129-
130-
fun setIgnoresTopSafeArea(view: ReactBottomNavigationView, flag: Boolean) {
131-
}
132-
133-
134-
fun setDisablePageAnimations(view: ReactBottomNavigationView, flag: Boolean) {
135-
}
136-
137-
@ReactProp(name = "translucent")
138-
fun setTranslucentview(view: ReactBottomNavigationView, translucent: Boolean?) {
73+
fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any>? {
74+
return MapBuilder.of(
75+
PageSelectedEvent.EVENT_NAME,
76+
MapBuilder.of("registrationName", "onPageSelected"),
77+
TabLongPressEvent.EVENT_NAME,
78+
MapBuilder.of("registrationName", "onTabLongPress")
79+
)
13980
}
14081
}

android/src/main/java/com/rcttabview/TabViewShadowNode.kt

Lines changed: 0 additions & 43 deletions
This file was deleted.

android/src/main/jni/RCTTabView.h

Lines changed: 0 additions & 19 deletions
This file was deleted.

android/src/main/jni/RNCTabView.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#include <ReactCommon/JavaTurboModule.h>
4+
#include <ReactCommon/TurboModule.h>
5+
#include <jsi/jsi.h>
6+
#include <react/renderer/components/RNCTabView/RNCTabViewComponentDescriptor.h>
7+
8+
namespace facebook::react {
9+
JSI_EXPORT
10+
std::shared_ptr<TurboModule> RNCTabView_ModuleProvider(
11+
const std::string &moduleName,
12+
const JavaTurboModule::InitParams &params);
13+
}

android/src/newarch/EventDispatcherWrapper.kt

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)