@react-native-menu/menu 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +40 -0
- package/android/src/main/java/com/reactnativemenu/MenuView.kt +37 -3
- package/android/src/main/java/com/reactnativemenu/{MenuViewManager.kt → MenuViewManagerBase.kt} +3 -8
- package/android/src/reactNativeVersionPatch/MenuViewManager/75/com/reactnativemenu/MenuViewManager.kt +17 -0
- package/android/src/reactNativeVersionPatch/MenuViewManager/latest/com/reactnativemenu/MenuViewManager.kt +14 -0
- package/package.json +1 -1
package/android/build.gradle
CHANGED
|
@@ -33,6 +33,10 @@ def getExtOrIntegerDefault(name) {
|
|
|
33
33
|
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Menu_" + name]).toInteger()
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
def getExtOrFallback(name, fallback) {
|
|
37
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : fallback
|
|
38
|
+
}
|
|
39
|
+
|
|
36
40
|
def supportsNamespace() {
|
|
37
41
|
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
38
42
|
def major = parsed[0].toInteger()
|
|
@@ -42,6 +46,35 @@ def supportsNamespace() {
|
|
|
42
46
|
return (major == 7 && minor >= 3) || major >= 8
|
|
43
47
|
}
|
|
44
48
|
|
|
49
|
+
def resolveReactNativeDirectory() {
|
|
50
|
+
def reactNativeLocation = getExtOrFallback("REACT_NATIVE_NODE_MODULES_DIR", null)
|
|
51
|
+
if (reactNativeLocation != null) {
|
|
52
|
+
return file(reactNativeLocation)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// monorepo workaround.
|
|
56
|
+
def reactNativePackage = file(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim())
|
|
57
|
+
if(reactNativePackage.exists()) {
|
|
58
|
+
return reactNativePackage.parentFile
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
throw new GradleException(
|
|
62
|
+
"[@react-native-menu/menu] Unable to resolve react-native location in node_modules. You should project extension property (in `app/build.gradle`) `REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
def getReactNativeMinorVersion() {
|
|
67
|
+
def REACT_NATIVE_DIR = resolveReactNativeDirectory()
|
|
68
|
+
|
|
69
|
+
def reactProperties = new Properties()
|
|
70
|
+
file("$REACT_NATIVE_DIR/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
|
|
71
|
+
|
|
72
|
+
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
|
|
73
|
+
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
|
|
74
|
+
|
|
75
|
+
return REACT_NATIVE_MINOR_VERSION
|
|
76
|
+
}
|
|
77
|
+
|
|
45
78
|
android {
|
|
46
79
|
if (supportsNamespace()) {
|
|
47
80
|
namespace "com.reactnativemenu"
|
|
@@ -93,6 +126,13 @@ android {
|
|
|
93
126
|
} else {
|
|
94
127
|
java.srcDirs += ["src/oldarch"]
|
|
95
128
|
}
|
|
129
|
+
|
|
130
|
+
// MenuViewManager
|
|
131
|
+
if (getReactNativeMinorVersion() <= 75) {
|
|
132
|
+
java.srcDirs += "src/reactNativeVersionPatch/MenuViewManager/75"
|
|
133
|
+
} else {
|
|
134
|
+
java.srcDirs += "src/reactNativeVersionPatch/MenuViewManager/latest"
|
|
135
|
+
}
|
|
96
136
|
}
|
|
97
137
|
}
|
|
98
138
|
}
|
|
@@ -3,6 +3,7 @@ package com.reactnativemenu
|
|
|
3
3
|
import android.content.res.ColorStateList
|
|
4
4
|
import android.content.res.Resources
|
|
5
5
|
import android.graphics.Color
|
|
6
|
+
import android.graphics.Rect
|
|
6
7
|
import android.os.Build
|
|
7
8
|
import android.text.Spannable
|
|
8
9
|
import android.text.SpannableStringBuilder
|
|
@@ -11,19 +12,18 @@ import android.view.*
|
|
|
11
12
|
import android.widget.PopupMenu
|
|
12
13
|
import com.facebook.react.bridge.*
|
|
13
14
|
import com.facebook.react.uimanager.UIManagerHelper
|
|
14
|
-
import com.facebook.react.uimanager.events.Event
|
|
15
|
-
import com.facebook.react.uimanager.events.RCTEventEmitter
|
|
16
15
|
import com.facebook.react.views.view.ReactViewGroup
|
|
17
16
|
import java.lang.reflect.Field
|
|
18
17
|
|
|
19
18
|
|
|
20
|
-
class MenuView(private val mContext: ReactContext): ReactViewGroup(mContext) {
|
|
19
|
+
class MenuView(private val mContext: ReactContext) : ReactViewGroup(mContext) {
|
|
21
20
|
private lateinit var mActions: ReadableArray
|
|
22
21
|
private var mIsAnchoredToRight = false
|
|
23
22
|
private val mPopupMenu: PopupMenu = PopupMenu(context, this)
|
|
24
23
|
private var mIsMenuDisplayed = false
|
|
25
24
|
private var mIsOnLongPress = false
|
|
26
25
|
private var mGestureDetector: GestureDetector
|
|
26
|
+
private var mHitSlopRect: Rect? = null
|
|
27
27
|
|
|
28
28
|
init {
|
|
29
29
|
mGestureDetector = GestureDetector(mContext, object : GestureDetector.SimpleOnGestureListener() {
|
|
@@ -43,6 +43,12 @@ class MenuView(private val mContext: ReactContext): ReactViewGroup(mContext) {
|
|
|
43
43
|
})
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
override fun setHitSlopRect(rect: Rect?) {
|
|
47
|
+
super.setHitSlopRect(rect)
|
|
48
|
+
mHitSlopRect = rect
|
|
49
|
+
updateTouchDelegate()
|
|
50
|
+
}
|
|
51
|
+
|
|
46
52
|
override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
|
|
47
53
|
return true
|
|
48
54
|
}
|
|
@@ -52,6 +58,16 @@ class MenuView(private val mContext: ReactContext): ReactViewGroup(mContext) {
|
|
|
52
58
|
return true
|
|
53
59
|
}
|
|
54
60
|
|
|
61
|
+
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
|
62
|
+
super.onSizeChanged(w, h, oldw, oldh)
|
|
63
|
+
updateTouchDelegate()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
override fun onAttachedToWindow() {
|
|
67
|
+
super.onAttachedToWindow()
|
|
68
|
+
updateTouchDelegate()
|
|
69
|
+
}
|
|
70
|
+
|
|
55
71
|
override fun onDetachedFromWindow() {
|
|
56
72
|
super.onDetachedFromWindow()
|
|
57
73
|
if (mIsMenuDisplayed) {
|
|
@@ -247,6 +263,24 @@ class MenuView(private val mContext: ReactContext): ReactViewGroup(mContext) {
|
|
|
247
263
|
}
|
|
248
264
|
}
|
|
249
265
|
|
|
266
|
+
private fun updateTouchDelegate() {
|
|
267
|
+
post {
|
|
268
|
+
val hitRect = Rect()
|
|
269
|
+
getHitRect(hitRect)
|
|
270
|
+
|
|
271
|
+
mHitSlopRect?.let {
|
|
272
|
+
hitRect.left -= it.left
|
|
273
|
+
hitRect.top -= it.top
|
|
274
|
+
hitRect.right += it.right
|
|
275
|
+
hitRect.bottom += it.bottom
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
(parent as? ViewGroup)?.let {
|
|
279
|
+
it.touchDelegate = TouchDelegate(hitRect, this)
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
250
284
|
private fun getDrawableIdWithName(name: String): Int {
|
|
251
285
|
val appResources: Resources = context.resources
|
|
252
286
|
var resourceId = appResources.getIdentifier(name, "drawable", context.packageName)
|
package/android/src/main/java/com/reactnativemenu/{MenuViewManager.kt → MenuViewManagerBase.kt}
RENAMED
|
@@ -17,13 +17,9 @@ import com.facebook.react.views.view.ReactDrawableHelper
|
|
|
17
17
|
import com.facebook.react.views.view.ReactViewGroup
|
|
18
18
|
import com.facebook.yoga.YogaConstants
|
|
19
19
|
|
|
20
|
-
class
|
|
20
|
+
abstract class MenuViewManagerBase: ReactClippingViewManager<MenuView>() {
|
|
21
21
|
override fun getName() = "MenuView"
|
|
22
22
|
|
|
23
|
-
override fun createViewInstance(reactContext: ThemedReactContext): MenuView {
|
|
24
|
-
return MenuView(reactContext)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
23
|
@ReactProp(name = "actions")
|
|
28
24
|
fun setActions(view: MenuView, actions: ReadableArray) {
|
|
29
25
|
view.setActions(actions)
|
|
@@ -110,6 +106,7 @@ class MenuViewManager: ReactClippingViewManager<MenuView>() {
|
|
|
110
106
|
@ReactProp(name = "hitSlop")
|
|
111
107
|
fun setHitSlop(view: ReactViewGroup, @Nullable hitSlop: ReadableMap?) {
|
|
112
108
|
if (hitSlop == null) {
|
|
109
|
+
// We should keep using setters as `Val cannot be reassigned`
|
|
113
110
|
view.setHitSlopRect(null)
|
|
114
111
|
} else {
|
|
115
112
|
view.setHitSlopRect(Rect(
|
|
@@ -151,9 +148,7 @@ class MenuViewManager: ReactClippingViewManager<MenuView>() {
|
|
|
151
148
|
}
|
|
152
149
|
|
|
153
150
|
@ReactPropGroup(names = [ViewProps.BORDER_COLOR, ViewProps.BORDER_LEFT_COLOR, ViewProps.BORDER_RIGHT_COLOR, ViewProps.BORDER_TOP_COLOR, ViewProps.BORDER_BOTTOM_COLOR, ViewProps.BORDER_START_COLOR, ViewProps.BORDER_END_COLOR], customType = "Color")
|
|
154
|
-
fun setBorderColor(view: ReactViewGroup, index: Int, color: Int?)
|
|
155
|
-
view.setBorderColor(index, color)
|
|
156
|
-
}
|
|
151
|
+
abstract fun setBorderColor(view: ReactViewGroup, index: Int, color: Int?)
|
|
157
152
|
|
|
158
153
|
@ReactProp(name = ViewProps.OVERFLOW)
|
|
159
154
|
fun setOverflow(view: ReactViewGroup, overflow: String?) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.reactnativemenu
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.views.view.ReactViewGroup
|
|
4
|
+
import com.facebook.yoga.YogaConstants
|
|
5
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
6
|
+
|
|
7
|
+
class MenuViewManager : MenuViewManagerBase() {
|
|
8
|
+
override fun createViewInstance(reactContext: ThemedReactContext): MenuView {
|
|
9
|
+
return MenuView(reactContext)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
override fun setBorderColor(view: ReactViewGroup, index: Int, color: Int?) {
|
|
13
|
+
val rgbComponent = color?.let { (it and 0x00FFFFFF).toFloat() } ?: YogaConstants.UNDEFINED
|
|
14
|
+
val alphaComponent = color?.let { (it ushr 24).toFloat() } ?: YogaConstants.UNDEFINED
|
|
15
|
+
view.setBorderColor(SPACING_TYPES[index], rgbComponent, alphaComponent)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
package com.reactnativemenu
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.views.view.ReactViewGroup
|
|
4
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
+
|
|
6
|
+
class MenuViewManager : MenuViewManagerBase() {
|
|
7
|
+
override fun createViewInstance(reactContext: ThemedReactContext): MenuView {
|
|
8
|
+
return MenuView(reactContext)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
override fun setBorderColor(view: ReactViewGroup, index: Int, color: Int?) {
|
|
12
|
+
view.setBorderColor(index, color)
|
|
13
|
+
}
|
|
14
|
+
}
|