Compare commits

...

3 Commits

Author SHA1 Message Date
Jesse Katsumata
4635b38978 0.3.3
Some checks failed
Build / lint (12) (push) Has been cancelled
Build / tsc (12) (push) Has been cancelled
Build / android (12) (push) Has been cancelled
Build / ios (12) (push) Has been cancelled
2021-04-04 17:44:18 +09:00
Mateusz Mędrek
bf37c96ce8
feat(#64): isAnchoredToRight android value (#69) 2021-04-04 17:43:08 +09:00
Jesse Katsumata
5189091b27
0.3.2 (#74) 2021-03-30 13:53:38 +09:00
5 changed files with 38 additions and 4 deletions

View File

@ -108,6 +108,14 @@ The title of the menu.
| ------ | -------- |
| string | No |
### `isAnchoredToRight` (Android only)
Boolean determining if menu should anchored to right or left corner of parent view.
| Type | Required |
| ------- | -------- |
| boolean | No |
### `actions`
Actions to be displayed in the menu.

View File

@ -7,6 +7,7 @@ import android.os.Build
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.ForegroundColorSpan
import android.view.Gravity
import android.view.Menu
import android.view.MotionEvent
import android.widget.PopupMenu
@ -19,9 +20,9 @@ import com.facebook.react.views.view.ReactViewGroup
import java.lang.reflect.Field
class MenuView(context: ReactContext): ReactViewGroup(context) {
class MenuView(private val mContext: ReactContext): ReactViewGroup(mContext) {
private lateinit var mActions: ReadableArray
private var mContext: ReactContext = context as ReactContext
private var mIsAnchoredToRight = false
private val mPopupMenu: PopupMenu = PopupMenu(context, this)
private var mIsMenuDisplayed = false
@ -42,7 +43,14 @@ class MenuView(context: ReactContext): ReactViewGroup(context) {
}
fun setActions(actions: ReadableArray) {
this.mActions = actions
mActions = actions
}
fun setIsAnchoredToRight(isAnchoredToRight: Boolean) {
if (mIsAnchoredToRight == isAnchoredToRight) {
return
}
mIsAnchoredToRight = isAnchoredToRight
}
private val getActionsCount: Int
@ -51,6 +59,12 @@ class MenuView(context: ReactContext): ReactViewGroup(context) {
private fun prepareMenu() {
if (getActionsCount > 0) {
mPopupMenu.menu.clear()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mPopupMenu.gravity = when (mIsAnchoredToRight) {
true -> Gravity.RIGHT
false -> Gravity.LEFT
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
mPopupMenu.setForceShowIcon(true)
}

View File

@ -29,6 +29,11 @@ class MenuViewManager: ReactClippingViewManager<MenuView>() {
view.setActions(actions)
}
@ReactProp(name = "isAnchoredToRight", defaultBoolean = false)
fun setIsAnchoredToRight(view: MenuView, isAnchoredToRight: Boolean) {
view.setIsAnchoredToRight(isAnchoredToRight)
}
override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
return MapBuilder.of(
"onPressAction",

View File

@ -1,6 +1,6 @@
{
"name": "@react-native-menu/menu",
"version": "0.3.1",
"version": "0.3.3",
"description": "UIMenu component for react-native",
"main": "lib/commonjs/index",
"module": "lib/module/index",

View File

@ -100,6 +100,13 @@ export type MenuComponentProps = {
* The title of the menu.
*/
title?: string;
/**
* (Android API 23+)
* Boolean value determines whether popup menu should be anchored
* to right corner of parent view - default value is `false`
* @platform Android
*/
isAnchoredToRight?: boolean;
};
export type ProcessedMenuAction = Omit<